blob: ac18e353c7b7b23605a6a33bd38d62d3bf3ff60e [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
lhchavez88cd8322016-10-25 02:44:565#ifndef CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_
6#define CHROME_BROWSER_CHROMEOS_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
14#include "base/process/process_handle.h"
15#include "components/arc/common/process.mojom.h"
16
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);
yusukescd2c29812016-06-02 06:24:0327 ~ArcProcess();
28
29 ArcProcess(ArcProcess&& other);
30 ArcProcess& operator=(ArcProcess&& other);
31
cyleec2e58df2016-07-25 10:28:2632 // Sort by descending importance.
33 bool operator<(const ArcProcess& rhs) const;
34
yusukescd2c29812016-06-02 06:24:0335 base::ProcessId nspid() const { return nspid_; }
36 base::ProcessId pid() const { return pid_; }
37 const std::string& process_name() const { return process_name_; }
Chris Morinc585d41a2018-06-12 04:26:0038 mojom::ProcessState process_state() const { return process_state_; }
cyleec2e58df2016-07-25 10:28:2639 bool is_focused() const { return is_focused_; }
40 int64_t last_activity_time() const { return last_activity_time_; }
yusukescd2c29812016-06-02 06:24:0341 std::vector<std::string>& packages() { return packages_; }
42 const std::vector<std::string>& packages() const { return packages_; }
43
Chris Morinc585d41a2018-06-12 04:26:0044 void set_process_state(mojom::ProcessState process_state) {
Chris Morin9702b3052018-05-22 21:01:3745 process_state_ = process_state;
46 }
47
yusukesee315ba2017-05-11 22:46:3848 // 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
yusukescd2c29812016-06-02 06:24:0359 private:
[email protected]dedfa292018-04-05 21:52:5560 // Returns true if this is ARC protected process which we don't allow to kill.
61 bool IsArcProtected() const;
62
yusukescd2c29812016-06-02 06:24:0363 base::ProcessId nspid_;
64 base::ProcessId pid_;
65 std::string process_name_;
Chris Morinc585d41a2018-06-12 04:26:0066 mojom::ProcessState process_state_;
cyleec2e58df2016-07-25 10:28:2667 // 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_;
yusukescd2c29812016-06-02 06:24:0373 std::vector<std::string> packages_;
74
cylee576b4492017-05-18 23:36:3275 friend std::ostream& operator<<(std::ostream& out,
76 const ArcProcess& arc_process);
77
yusukescd2c29812016-06-02 06:24:0378 DISALLOW_COPY_AND_ASSIGN(ArcProcess);
cylee1fee6492016-03-09 20:04:4179};
80
81} // namespace arc
82
lhchavez88cd8322016-10-25 02:44:5683#endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_