blob: 35369151fcfcf2c56e844215b01c9118b2042248 [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,
cyleec2e58df2016-07-25 10:28:2624 mojom::ProcessState process_state,
25 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_; }
38 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
yusukesee315ba2017-05-11 22:46:3844 // Returns true if the process is important and should be protected more
45 // from OOM kills than other processes.
46 // TODO(cylee|yusukes): Check what stock Android does for handling OOM and
47 // modify this function as needed (crbug.com/719537).
48 bool IsImportant() const;
49
50 // Returns true if it is okay for the kernel OOM killer to kill the process.
51 // TODO(cylee|yusukes): Consider removing this function. Having only
52 // IsImportant() might be good enough.
53 bool IsKernelKillable() const;
54
yusukescd2c29812016-06-02 06:24:0355 private:
56 base::ProcessId nspid_;
57 base::ProcessId pid_;
58 std::string process_name_;
59 mojom::ProcessState process_state_;
cyleec2e58df2016-07-25 10:28:2660 // If the Android app is the focused window.
61 bool is_focused_;
62 // A monotonic timer recording the last time this process was active.
63 // Milliseconds since Android boot. This info is passed from Android
64 // ActivityManagerService via IPC.
65 int64_t last_activity_time_;
yusukescd2c29812016-06-02 06:24:0366 std::vector<std::string> packages_;
67
cylee576b4492017-05-18 23:36:3268 friend std::ostream& operator<<(std::ostream& out,
69 const ArcProcess& arc_process);
70
yusukescd2c29812016-06-02 06:24:0371 DISALLOW_COPY_AND_ASSIGN(ArcProcess);
cylee1fee6492016-03-09 20:04:4172};
73
74} // namespace arc
75
lhchavez88cd8322016-10-25 02:44:5676#endif // CHROME_BROWSER_CHROMEOS_ARC_PROCESS_ARC_PROCESS_H_