blob: e2e6faf3b59cadd3fe1e62ce3a9caa0e10edc798 [file] [log] [blame]
cylee1fee6492016-03-09 20:04:411// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
yusukescd2c29812016-06-02 06:24:034
lhchavez88cd8322016-10-25 02:44:565#ifndef CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_
6#define CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_
cylee1fee6492016-03-09 20:04:417
cyleec2e58df2016-07-25 10:28:268#include <stdint.h>
cylee1fee6492016-03-09 20:04:419#include <string>
yusukescd2c29812016-06-02 06:24:0310#include <vector>
cylee1fee6492016-03-09 20:04:4111
12#include "base/process/process_handle.h"
13#include "components/arc/common/process.mojom.h"
14
15namespace arc {
16
yusukescd2c29812016-06-02 06:24:0317class ArcProcess {
18 public:
19 ArcProcess(base::ProcessId nspid,
20 base::ProcessId pid,
21 const std::string& process_name,
cyleec2e58df2016-07-25 10:28:2622 mojom::ProcessState process_state,
23 bool is_focused,
24 int64_t last_activity_time);
yusukescd2c29812016-06-02 06:24:0325 ~ArcProcess();
26
27 ArcProcess(ArcProcess&& other);
28 ArcProcess& operator=(ArcProcess&& other);
29
cyleec2e58df2016-07-25 10:28:2630 // Sort by descending importance.
31 bool operator<(const ArcProcess& rhs) const;
32
yusukescd2c29812016-06-02 06:24:0333 base::ProcessId nspid() const { return nspid_; }
34 base::ProcessId pid() const { return pid_; }
35 const std::string& process_name() const { return process_name_; }
36 mojom::ProcessState process_state() const { return process_state_; }
cyleec2e58df2016-07-25 10:28:2637 bool is_focused() const { return is_focused_; }
38 int64_t last_activity_time() const { return last_activity_time_; }
yusukescd2c29812016-06-02 06:24:0339 std::vector<std::string>& packages() { return packages_; }
40 const std::vector<std::string>& packages() const { return packages_; }
41
yusukesee315ba2017-05-11 22:46:3842 // Returns true if the process is important and should be protected more
43 // from OOM kills than other processes.
44 // TODO(cylee|yusukes): Check what stock Android does for handling OOM and
45 // modify this function as needed (crbug.com/719537).
46 bool IsImportant() const;
47
48 // Returns true if it is okay for the kernel OOM killer to kill the process.
49 // TODO(cylee|yusukes): Consider removing this function. Having only
50 // IsImportant() might be good enough.
51 bool IsKernelKillable() const;
52
yusukescd2c29812016-06-02 06:24:0353 private:
54 base::ProcessId nspid_;
55 base::ProcessId pid_;
56 std::string process_name_;
57 mojom::ProcessState process_state_;
cyleec2e58df2016-07-25 10:28:2658 // If the Android app is the focused window.
59 bool is_focused_;
60 // A monotonic timer recording the last time this process was active.
61 // Milliseconds since Android boot. This info is passed from Android
62 // ActivityManagerService via IPC.
63 int64_t last_activity_time_;
yusukescd2c29812016-06-02 06:24:0364 std::vector<std::string> packages_;
65
66 DISALLOW_COPY_AND_ASSIGN(ArcProcess);
cylee1fee6492016-03-09 20:04:4167};
68
69} // namespace arc
70
lhchavez88cd8322016-10-25 02:44:5671#endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_