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, |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame^] | 24 | mojom::ProcessState process_state, |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 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_; } |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame^] | 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 | |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame^] | 44 | void set_process_state(mojom::ProcessState process_state) { |
Chris Morin | 9702b305 | 2018-05-22 21:01:37 | [diff] [blame] | 45 | process_state_ = process_state; |
| 46 | } |
| 47 | |
yusukes | ee315ba | 2017-05-11 22:46:38 | [diff] [blame] | 48 | // Returns true if the process is important and should be protected more |
| 49 | // from OOM kills than other processes. |
| 50 | // TODO(cylee|yusukes): Check what stock Android does for handling OOM and |
| 51 | // modify this function as needed (crbug.com/719537). |
| 52 | bool IsImportant() const; |
| 53 | |
| 54 | // Returns true if it is okay for the kernel OOM killer to kill the process. |
| 55 | // TODO(cylee|yusukes): Consider removing this function. Having only |
| 56 | // IsImportant() might be good enough. |
| 57 | bool IsKernelKillable() const; |
| 58 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 59 | private: |
[email protected] | dedfa29 | 2018-04-05 21:52:55 | [diff] [blame] | 60 | // Returns true if this is ARC protected process which we don't allow to kill. |
| 61 | bool IsArcProtected() const; |
| 62 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 63 | base::ProcessId nspid_; |
| 64 | base::ProcessId pid_; |
| 65 | std::string process_name_; |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame^] | 66 | mojom::ProcessState process_state_; |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 67 | // If the Android app is the focused window. |
| 68 | bool is_focused_; |
| 69 | // A monotonic timer recording the last time this process was active. |
| 70 | // Milliseconds since Android boot. This info is passed from Android |
| 71 | // ActivityManagerService via IPC. |
| 72 | int64_t last_activity_time_; |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 73 | std::vector<std::string> packages_; |
| 74 | |
cylee | 576b449 | 2017-05-18 23:36:32 | [diff] [blame] | 75 | friend std::ostream& operator<<(std::ostream& out, |
| 76 | const ArcProcess& arc_process); |
| 77 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(ArcProcess); |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace arc |
| 82 | |
lhchavez | 88cd832 | 2016-10-25 02:44:56 | [diff] [blame] | 83 | #endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_ |