blob: 5470eca1e08b3eaa2d41a8549c423e78a9e44b31 [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
Hans Wennborgc777e0412020-04-22 09:22:4114#include "base/macros.h"
cylee1fee6492016-03-09 20:04:4115#include "base/process/process_handle.h"
Gyuyoung Kimb6093332019-12-19 14:01:4316#include "components/arc/mojom/process.mojom-forward.h"
cylee1fee6492016-03-09 20:04:4117
18namespace arc {
19
yusukescd2c29812016-06-02 06:24:0320class ArcProcess {
21 public:
22 ArcProcess(base::ProcessId nspid,
23 base::ProcessId pid,
24 const std::string& process_name,
Chris Morinc585d41a2018-06-12 04:26:0025 mojom::ProcessState process_state,
cyleec2e58df2016-07-25 10:28:2626 bool is_focused,
27 int64_t last_activity_time);
yusukescd2c29812016-06-02 06:24:0328 ~ArcProcess();
29
30 ArcProcess(ArcProcess&& other);
31 ArcProcess& operator=(ArcProcess&& other);
32
cyleec2e58df2016-07-25 10:28:2633 // Sort by descending importance.
34 bool operator<(const ArcProcess& rhs) const;
35
yusukescd2c29812016-06-02 06:24:0336 base::ProcessId nspid() const { return nspid_; }
37 base::ProcessId pid() const { return pid_; }
38 const std::string& process_name() const { return process_name_; }
Chris Morinc585d41a2018-06-12 04:26:0039 mojom::ProcessState process_state() const { return process_state_; }
cyleec2e58df2016-07-25 10:28:2640 bool is_focused() const { return is_focused_; }
41 int64_t last_activity_time() const { return last_activity_time_; }
yusukescd2c29812016-06-02 06:24:0342 std::vector<std::string>& packages() { return packages_; }
43 const std::vector<std::string>& packages() const { return packages_; }
44
Chris Morinc585d41a2018-06-12 04:26:0045 void set_process_state(mojom::ProcessState process_state) {
Chris Morin9702b3052018-05-22 21:01:3746 process_state_ = process_state;
47 }
48
yusukesee315ba2017-05-11 22:46:3849 // 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 Yang49d33542018-08-30 09:51:1555 // Returns true if it is persistent process and should have a lower
56 // oom_score_adj.
yusukesee315ba2017-05-11 22:46:3857 // TODO(cylee|yusukes): Consider removing this function. Having only
58 // IsImportant() might be good enough.
Kuo-Hsin Yang49d33542018-08-30 09:51:1559 bool IsPersistent() const;
yusukesee315ba2017-05-11 22:46:3860
Willie Koomson6d36d662018-12-18 18:55:5561 // 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
yusukescd2c29812016-06-02 06:24:0369 private:
[email protected]dedfa292018-04-05 21:52:5570 // Returns true if this is ARC protected process which we don't allow to kill.
71 bool IsArcProtected() const;
72
yusukescd2c29812016-06-02 06:24:0373 base::ProcessId nspid_;
74 base::ProcessId pid_;
75 std::string process_name_;
Chris Morinc585d41a2018-06-12 04:26:0076 mojom::ProcessState process_state_;
cyleec2e58df2016-07-25 10:28:2677 // 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_;
yusukescd2c29812016-06-02 06:24:0383 std::vector<std::string> packages_;
84
cylee576b4492017-05-18 23:36:3285 friend std::ostream& operator<<(std::ostream& out,
86 const ArcProcess& arc_process);
87
yusukescd2c29812016-06-02 06:24:0388 DISALLOW_COPY_AND_ASSIGN(ArcProcess);
cylee1fee6492016-03-09 20:04:4189};
90
91} // namespace arc
92
Henrique Ferreiro2ef82302021-03-24 12:12:2593#endif // CHROME_BROWSER_ASH_ARC_PROCESS_ARC_PROCESS_H_