cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 1 | // 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. |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 4 | |
lhchavez | 88cd832 | 2016-10-25 02:44:56 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_ |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 7 | |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 8 | #include <stdint.h> |
yusukes | c10020e | 2017-05-22 16:18:51 | [diff] [blame^] | 9 | |
| 10 | #include <ostream> |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 11 | #include <string> |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 12 | #include <vector> |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 13 | |
| 14 | #include "base/process/process_handle.h" |
| 15 | #include "components/arc/common/process.mojom.h" |
| 16 | |
| 17 | namespace arc { |
| 18 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 19 | class ArcProcess { |
| 20 | public: |
| 21 | ArcProcess(base::ProcessId nspid, |
| 22 | base::ProcessId pid, |
| 23 | const std::string& process_name, |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 24 | mojom::ProcessState process_state, |
| 25 | bool is_focused, |
| 26 | int64_t last_activity_time); |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 27 | ~ArcProcess(); |
| 28 | |
| 29 | ArcProcess(ArcProcess&& other); |
| 30 | ArcProcess& operator=(ArcProcess&& other); |
| 31 | |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 32 | // Sort by descending importance. |
| 33 | bool operator<(const ArcProcess& rhs) const; |
| 34 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 35 | base::ProcessId nspid() const { return nspid_; } |
| 36 | base::ProcessId pid() const { return pid_; } |
| 37 | const std::string& process_name() const { return process_name_; } |
| 38 | mojom::ProcessState process_state() const { return process_state_; } |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 39 | bool is_focused() const { return is_focused_; } |
| 40 | int64_t last_activity_time() const { return last_activity_time_; } |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 41 | std::vector<std::string>& packages() { return packages_; } |
| 42 | const std::vector<std::string>& packages() const { return packages_; } |
| 43 | |
yusukes | ee315ba | 2017-05-11 22:46:38 | [diff] [blame] | 44 | // Returns true if the process is important and should be protected more |
| 45 | // from OOM kills than other processes. |
| 46 | // TODO(cylee|yusukes): Check what stock Android does for handling OOM and |
| 47 | // modify this function as needed (crbug.com/719537). |
| 48 | bool IsImportant() const; |
| 49 | |
| 50 | // Returns true if it is okay for the kernel OOM killer to kill the process. |
| 51 | // TODO(cylee|yusukes): Consider removing this function. Having only |
| 52 | // IsImportant() might be good enough. |
| 53 | bool IsKernelKillable() const; |
| 54 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 55 | private: |
| 56 | base::ProcessId nspid_; |
| 57 | base::ProcessId pid_; |
| 58 | std::string process_name_; |
| 59 | mojom::ProcessState process_state_; |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 60 | // If the Android app is the focused window. |
| 61 | bool is_focused_; |
| 62 | // A monotonic timer recording the last time this process was active. |
| 63 | // Milliseconds since Android boot. This info is passed from Android |
| 64 | // ActivityManagerService via IPC. |
| 65 | int64_t last_activity_time_; |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 66 | std::vector<std::string> packages_; |
| 67 | |
cylee | 576b449 | 2017-05-18 23:36:32 | [diff] [blame] | 68 | friend std::ostream& operator<<(std::ostream& out, |
| 69 | const ArcProcess& arc_process); |
| 70 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(ArcProcess); |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } // namespace arc |
| 75 | |
lhchavez | 88cd832 | 2016-10-25 02:44:56 | [diff] [blame] | 76 | #endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_ |