OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/arc/process/arc_process.h" | 5 #include "chrome/browser/chromeos/arc/process/arc_process.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 namespace arc { | 9 namespace arc { |
10 | 10 |
11 namespace { | |
12 | |
13 // A special process on Android side which serves as a dummy "focused" app | |
Yusuke Sato
2017/05/09 22:54:35
moved
| |
14 // when the focused window is a Chrome side window (i.e., all Android | |
15 // processes are running in the background). We don't want to kill it anyway. | |
16 static constexpr char kArcHomeProcess[] = "org.chromium.arc.home"; | |
Luis Héctor Chávez
2017/05/09 23:00:10
nit: static is superfluous in the anonymous namesp
Yusuke Sato
2017/05/09 23:20:12
Done.
| |
17 | |
18 } // namespace | |
19 | |
11 ArcProcess::ArcProcess(base::ProcessId nspid, | 20 ArcProcess::ArcProcess(base::ProcessId nspid, |
12 base::ProcessId pid, | 21 base::ProcessId pid, |
13 const std::string& process_name, | 22 const std::string& process_name, |
14 mojom::ProcessState process_state, | 23 mojom::ProcessState process_state, |
15 bool is_focused, | 24 bool is_focused, |
16 int64_t last_activity_time) | 25 int64_t last_activity_time) |
17 : nspid_(nspid), | 26 : nspid_(nspid), |
18 pid_(pid), | 27 pid_(pid), |
19 process_name_(process_name), | 28 process_name_(process_name), |
20 process_state_(process_state), | 29 process_state_(process_state), |
21 is_focused_(is_focused), | 30 is_focused_(is_focused), |
22 last_activity_time_(last_activity_time) {} | 31 last_activity_time_(last_activity_time) {} |
23 | 32 |
24 ArcProcess::~ArcProcess() = default; | 33 ArcProcess::~ArcProcess() = default; |
25 | 34 |
26 // Sort by (process_state, last_activity_time) pair. | 35 // Sort by (process_state, last_activity_time) pair. |
27 // Smaller process_state value means higher priority as defined in Android. | 36 // Smaller process_state value means higher priority as defined in Android. |
28 // Larger last_activity_time means more recently used. | 37 // Larger last_activity_time means more recently used. |
29 bool ArcProcess::operator<(const ArcProcess& rhs) const { | 38 bool ArcProcess::operator<(const ArcProcess& rhs) const { |
30 return std::make_pair(process_state(), -last_activity_time()) < | 39 return std::make_pair(process_state(), -last_activity_time()) < |
31 std::make_pair(rhs.process_state(), -rhs.last_activity_time()); | 40 std::make_pair(rhs.process_state(), -rhs.last_activity_time()); |
32 } | 41 } |
33 | 42 |
34 ArcProcess::ArcProcess(ArcProcess&& other) = default; | 43 ArcProcess::ArcProcess(ArcProcess&& other) = default; |
35 ArcProcess& ArcProcess::operator=(ArcProcess&& other) = default; | 44 ArcProcess& ArcProcess::operator=(ArcProcess&& other) = default; |
36 | 45 |
46 bool ArcProcess::IsUserVisible() const { | |
47 return process_state() <= mojom::ProcessState::IMPORTANT_FOREGROUND || | |
48 process_name() == kArcHomeProcess; | |
49 } | |
50 | |
51 bool ArcProcess::IsKillableForKernel() const { | |
52 // Protect PERSISTENT, PERSISTENT_UI, and our HOME processes since they should | |
53 // never be killed even by the kernel. Returning false for them allows their | |
54 // OOM adjustment scores to remain negative. | |
55 return process_state() > arc::mojom::ProcessState::PERSISTENT_UI && | |
56 process_name() != kArcHomeProcess; | |
57 } | |
58 | |
37 } // namespace arc | 59 } // namespace arc |
OLD | NEW |