blob: 96ac21e4223286ad288daaf8c8f44ab2373a5b9d [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
Henrique Ferreiro2ef82302021-03-24 12:12:255#ifndef CHROME_BROWSER_ASH_ARC_PROCESS_ARC_PROCESS_H_
6#define CHROME_BROWSER_ASH_ARC_PROCESS_ARC_PROCESS_H_
cylee1fee6492016-03-09 20:04:417
cyleec2e58df2016-07-25 10:28:268#include <stdint.h>
yusukesc10020e2017-05-22 16:18:519
10#include <ostream>
cylee1fee6492016-03-09 20:04:4111#include <string>
yusukescd2c29812016-06-02 06:24:0312#include <vector>
cylee1fee6492016-03-09 20:04:4113
Yao Li0a8f82f2021-12-01 02:07:4814#include "ash/components/arc/mojom/process.mojom-forward.h"
cylee1fee6492016-03-09 20:04:4115#include "base/process/process_handle.h"
cylee1fee6492016-03-09 20:04:4116
17namespace arc {
18
yusukescd2c29812016-06-02 06:24:0319class ArcProcess {
20 public:
21 ArcProcess(base::ProcessId nspid,
22 base::ProcessId pid,
23 const std::string& process_name,
Chris Morinc585d41a2018-06-12 04:26:0024 mojom::ProcessState process_state,
cyleec2e58df2016-07-25 10:28:2625 bool is_focused,
26 int64_t last_activity_time);
Peter Boström53c6c5952021-09-17 09:41:2627
28 ArcProcess(const ArcProcess&) = delete;
29 ArcProcess& operator=(const ArcProcess&) = delete;
30
yusukescd2c29812016-06-02 06:24:0331 ~ArcProcess();
32
33 ArcProcess(ArcProcess&& other);
34 ArcProcess& operator=(ArcProcess&& other);
35
cyleec2e58df2016-07-25 10:28:2636 // Sort by descending importance.
37 bool operator<(const ArcProcess& rhs) const;
38
yusukescd2c29812016-06-02 06:24:0339 base::ProcessId nspid() const { return nspid_; }
40 base::ProcessId pid() const { return pid_; }
41 const std::string& process_name() const { return process_name_; }
Chris Morinc585d41a2018-06-12 04:26:0042 mojom::ProcessState process_state() const { return process_state_; }
cyleec2e58df2016-07-25 10:28:2643 bool is_focused() const { return is_focused_; }
44 int64_t last_activity_time() const { return last_activity_time_; }
yusukescd2c29812016-06-02 06:24:0345 std::vector<std::string>& packages() { return packages_; }
46 const std::vector<std::string>& packages() const { return packages_; }
47
Chris Morinc585d41a2018-06-12 04:26:0048 void set_process_state(mojom::ProcessState process_state) {
Chris Morin9702b3052018-05-22 21:01:3749 process_state_ = process_state;
50 }
51
yusukesee315ba2017-05-11 22:46:3852 // Returns true if the process is important and should be protected more
53 // from OOM kills than other processes.
54 // TODO(cylee|yusukes): Check what stock Android does for handling OOM and
55 // modify this function as needed (crbug.com/719537).
56 bool IsImportant() const;
57
Kuo-Hsin Yang49d33542018-08-30 09:51:1558 // Returns true if it is persistent process and should have a lower
59 // oom_score_adj.
yusukesee315ba2017-05-11 22:46:3860 // TODO(cylee|yusukes): Consider removing this function. Having only
61 // IsImportant() might be good enough.
Kuo-Hsin Yang49d33542018-08-30 09:51:1562 bool IsPersistent() const;
yusukesee315ba2017-05-11 22:46:3863
Willie Koomson6d36d662018-12-18 18:55:5564 // Returns true if the process is cached or empty and should have a higher
65 // oom_score_adj to be killed earlier.
66 bool IsCached() const;
67
68 // Returns true if process is in the background but should have a lower
69 // oom_score_adj.
70 bool IsBackgroundProtected() const;
71
yusukescd2c29812016-06-02 06:24:0372 private:
[email protected]dedfa292018-04-05 21:52:5573 // Returns true if this is ARC protected process which we don't allow to kill.
74 bool IsArcProtected() const;
75
yusukescd2c29812016-06-02 06:24:0376 base::ProcessId nspid_;
77 base::ProcessId pid_;
78 std::string process_name_;
Chris Morinc585d41a2018-06-12 04:26:0079 mojom::ProcessState process_state_;
cyleec2e58df2016-07-25 10:28:2680 // If the Android app is the focused window.
81 bool is_focused_;
82 // A monotonic timer recording the last time this process was active.
83 // Milliseconds since Android boot. This info is passed from Android
84 // ActivityManagerService via IPC.
85 int64_t last_activity_time_;
yusukescd2c29812016-06-02 06:24:0386 std::vector<std::string> packages_;
87
cylee576b4492017-05-18 23:36:3288 friend std::ostream& operator<<(std::ostream& out,
89 const ArcProcess& arc_process);
cylee1fee6492016-03-09 20:04:4190};
91
92} // namespace arc
93
Henrique Ferreiro2ef82302021-03-24 12:12:2594#endif // CHROME_BROWSER_ASH_ARC_PROCESS_ARC_PROCESS_H_