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> |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 9 | #include <string> |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 10 | #include <vector> |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 11 | |
| 12 | #include "base/process/process_handle.h" |
| 13 | #include "components/arc/common/process.mojom.h" |
| 14 | |
| 15 | namespace arc { |
| 16 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 17 | class ArcProcess { |
| 18 | public: |
| 19 | ArcProcess(base::ProcessId nspid, |
| 20 | base::ProcessId pid, |
| 21 | const std::string& process_name, |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 22 | mojom::ProcessState process_state, |
| 23 | bool is_focused, |
| 24 | int64_t last_activity_time); |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 25 | ~ArcProcess(); |
| 26 | |
| 27 | ArcProcess(ArcProcess&& other); |
| 28 | ArcProcess& operator=(ArcProcess&& other); |
| 29 | |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 30 | // Sort by descending importance. |
| 31 | bool operator<(const ArcProcess& rhs) const; |
| 32 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 33 | 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_; } |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 37 | bool is_focused() const { return is_focused_; } |
| 38 | int64_t last_activity_time() const { return last_activity_time_; } |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 39 | std::vector<std::string>& packages() { return packages_; } |
| 40 | const std::vector<std::string>& packages() const { return packages_; } |
| 41 | |
yusukes | ee315ba | 2017-05-11 22:46:38 | [diff] [blame^] | 42 | // 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 | |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 53 | private: |
| 54 | base::ProcessId nspid_; |
| 55 | base::ProcessId pid_; |
| 56 | std::string process_name_; |
| 57 | mojom::ProcessState process_state_; |
cylee | c2e58df | 2016-07-25 10:28:26 | [diff] [blame] | 58 | // 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_; |
yusukes | cd2c2981 | 2016-06-02 06:24:03 | [diff] [blame] | 64 | std::vector<std::string> packages_; |
| 65 | |
| 66 | DISALLOW_COPY_AND_ASSIGN(ArcProcess); |
cylee | 1fee649 | 2016-03-09 20:04:41 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace arc |
| 70 | |
lhchavez | 88cd832 | 2016-10-25 02:44:56 | [diff] [blame] | 71 | #endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_ |