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 | |
Henrique Ferreiro | 2ef8230 | 2021-03-24 12:12:25 | [diff] [blame^] | 5 | #ifndef CHROME_BROWSER_ASH_ARC_PROCESS_ARC_PROCESS_H_ |
| 6 | #define CHROME_BROWSER_ASH_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 | |
Hans Wennborg | c777e041 | 2020-04-22 09:22:41 | [diff] [blame] | 14 | #include "base/macros.h" |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 15 | #include "base/process/process_handle.h" |
Gyuyoung Kim | b609333 | 2019-12-19 14:01:43 | [diff] [blame] | 16 | #include "components/arc/mojom/process.mojom-forward.h" |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 17 | |
| 18 | namespace arc { |
| 19 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 20 | class ArcProcess { |
| 21 | public: |
| 22 | ArcProcess(base::ProcessId nspid, |
| 23 | base::ProcessId pid, |
| 24 | const std::string& process_name, |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame] | 25 | mojom::ProcessState process_state, |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 26 | bool is_focused, |
| 27 | int64_t last_activity_time); |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 28 | ~ArcProcess(); |
| 29 | |
| 30 | ArcProcess(ArcProcess&& other); |
| 31 | ArcProcess& operator=(ArcProcess&& other); |
| 32 | |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 33 | // Sort by descending importance. |
| 34 | bool operator<(const ArcProcess& rhs) const; |
| 35 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 36 | base::ProcessId nspid() const { return nspid_; } |
| 37 | base::ProcessId pid() const { return pid_; } |
| 38 | const std::string& process_name() const { return process_name_; } |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame] | 39 | mojom::ProcessState process_state() const { return process_state_; } |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 40 | bool is_focused() const { return is_focused_; } |
| 41 | int64_t last_activity_time() const { return last_activity_time_; } |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 42 | std::vector<std::string>& packages() { return packages_; } |
| 43 | const std::vector<std::string>& packages() const { return packages_; } |
| 44 | |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame] | 45 | void set_process_state(mojom::ProcessState process_state) { |
Chris Morin | 9702b305 | 2018-05-22 21:01:37 | [diff] [blame] | 46 | process_state_ = process_state; |
| 47 | } |
| 48 | |
yusukes | ee315ba | 2017-05-11 22:46:38 | [diff] [blame] | 49 | // Returns true if the process is important and should be protected more |
| 50 | // from OOM kills than other processes. |
| 51 | // TODO(cylee|yusukes): Check what stock Android does for handling OOM and |
| 52 | // modify this function as needed (crbug.com/719537). |
| 53 | bool IsImportant() const; |
| 54 | |
Kuo-Hsin Yang | 49d3354 | 2018-08-30 09:51:15 | [diff] [blame] | 55 | // Returns true if it is persistent process and should have a lower |
| 56 | // oom_score_adj. |
yusukes | ee315ba | 2017-05-11 22:46:38 | [diff] [blame] | 57 | // TODO(cylee|yusukes): Consider removing this function. Having only |
| 58 | // IsImportant() might be good enough. |
Kuo-Hsin Yang | 49d3354 | 2018-08-30 09:51:15 | [diff] [blame] | 59 | bool IsPersistent() const; |
yusukes | ee315ba | 2017-05-11 22:46:38 | [diff] [blame] | 60 | |
Willie Koomson | 6d36d66 | 2018-12-18 18:55:55 | [diff] [blame] | 61 | // Returns true if the process is cached or empty and should have a higher |
| 62 | // oom_score_adj to be killed earlier. |
| 63 | bool IsCached() const; |
| 64 | |
| 65 | // Returns true if process is in the background but should have a lower |
| 66 | // oom_score_adj. |
| 67 | bool IsBackgroundProtected() const; |
| 68 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 69 | private: |
[email protected] | dedfa29 | 2018-04-05 21:52:55 | [diff] [blame] | 70 | // Returns true if this is ARC protected process which we don't allow to kill. |
| 71 | bool IsArcProtected() const; |
| 72 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 73 | base::ProcessId nspid_; |
| 74 | base::ProcessId pid_; |
| 75 | std::string process_name_; |
Chris Morin | c585d41a | 2018-06-12 04:26:00 | [diff] [blame] | 76 | mojom::ProcessState process_state_; |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 77 | // If the Android app is the focused window. |
| 78 | bool is_focused_; |
| 79 | // A monotonic timer recording the last time this process was active. |
| 80 | // Milliseconds since Android boot. This info is passed from Android |
| 81 | // ActivityManagerService via IPC. |
| 82 | int64_t last_activity_time_; |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 83 | std::vector<std::string> packages_; |
| 84 | |
cylee | 576b449 | 2017-05-18 23:36:32 | [diff] [blame] | 85 | friend std::ostream& operator<<(std::ostream& out, |
| 86 | const ArcProcess& arc_process); |
| 87 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(ArcProcess); |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace arc |
| 92 | |
Henrique Ferreiro | 2ef8230 | 2021-03-24 12:12:25 | [diff] [blame^] | 93 | #endif // CHROME_BROWSER_ASH_ARC_PROCESS_ARC_PROCESS_H_ |