OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/memory/tab_manager_delegate_chromeos.h" | 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 namespace memory { | 39 namespace memory { |
40 namespace { | 40 namespace { |
41 | 41 |
42 // When switching to a new tab the tab's renderer's OOM score needs to be | 42 // When switching to a new tab the tab's renderer's OOM score needs to be |
43 // updated to reflect its front-most status and protect it from discard. | 43 // updated to reflect its front-most status and protect it from discard. |
44 // However, doing this immediately might slow down tab switch time, so wait | 44 // However, doing this immediately might slow down tab switch time, so wait |
45 // a little while before doing the adjustment. | 45 // a little while before doing the adjustment. |
46 const int kFocusedTabScoreAdjustIntervalMs = 500; | 46 const int kFocusedTabScoreAdjustIntervalMs = 500; |
47 | 47 |
48 // TODO(cylee): Check whether the app is in foreground or not. | 48 // TODO(cylee): Check whether the app is in foreground or not. |
49 int AppStateToPriority( | 49 int AppStateToPriority(const arc::mojom::ProcessState& process_state) { |
50 const arc::ProcessState& process_state) { | |
51 // Logic copied from Android: | 50 // Logic copied from Android: |
52 // frameworks/base/core/java/android/app/ActivityManager.java | 51 // frameworks/base/core/java/android/app/ActivityManager.java |
53 // Note that ProcessState enumerates from most important (lower value) to | 52 // Note that ProcessState enumerates from most important (lower value) to |
54 // least important (higher value), while ProcessPriority enumerates the | 53 // least important (higher value), while ProcessPriority enumerates the |
55 // opposite. | 54 // opposite. |
56 if (process_state >= arc::ProcessState::HOME) { | 55 if (process_state >= arc::mojom::ProcessState::HOME) { |
57 return ProcessPriority::ANDROID_BACKGROUND; | 56 return ProcessPriority::ANDROID_BACKGROUND; |
58 } else if (process_state >= arc::ProcessState::SERVICE) { | 57 } else if (process_state >= arc::mojom::ProcessState::SERVICE) { |
59 return ProcessPriority::ANDROID_SERVICE; | 58 return ProcessPriority::ANDROID_SERVICE; |
60 } else if (process_state >= arc::ProcessState::HEAVY_WEIGHT) { | 59 } else if (process_state >= arc::mojom::ProcessState::HEAVY_WEIGHT) { |
61 return ProcessPriority::ANDROID_CANT_SAVE_STATE; | 60 return ProcessPriority::ANDROID_CANT_SAVE_STATE; |
62 } else if (process_state >= arc::ProcessState::IMPORTANT_BACKGROUND) { | 61 } else if (process_state >= arc::mojom::ProcessState::IMPORTANT_BACKGROUND) { |
63 return ProcessPriority::ANDROID_PERCEPTIBLE; | 62 return ProcessPriority::ANDROID_PERCEPTIBLE; |
64 } else if (process_state >= arc::ProcessState::IMPORTANT_FOREGROUND) { | 63 } else if (process_state >= arc::mojom::ProcessState::IMPORTANT_FOREGROUND) { |
65 return ProcessPriority::ANDROID_VISIBLE; | 64 return ProcessPriority::ANDROID_VISIBLE; |
66 } else if (process_state >= arc::ProcessState::TOP_SLEEPING) { | 65 } else if (process_state >= arc::mojom::ProcessState::TOP_SLEEPING) { |
67 return ProcessPriority::ANDROID_TOP_SLEEPING; | 66 return ProcessPriority::ANDROID_TOP_SLEEPING; |
68 } else if (process_state >= arc::ProcessState::FOREGROUND_SERVICE) { | 67 } else if (process_state >= arc::mojom::ProcessState::FOREGROUND_SERVICE) { |
69 return ProcessPriority::ANDROID_FOREGROUND_SERVICE; | 68 return ProcessPriority::ANDROID_FOREGROUND_SERVICE; |
70 } else if (process_state >= arc::ProcessState::TOP) { | 69 } else if (process_state >= arc::mojom::ProcessState::TOP) { |
71 return ProcessPriority::ANDROID_TOP; | 70 return ProcessPriority::ANDROID_TOP; |
72 } else if (process_state >= arc::ProcessState::PERSISTENT) { | 71 } else if (process_state >= arc::mojom::ProcessState::PERSISTENT) { |
73 return ProcessPriority::ANDROID_PERSISTENT; | 72 return ProcessPriority::ANDROID_PERSISTENT; |
74 } | 73 } |
75 return ProcessPriority::ANDROID_NON_EXISTS; | 74 return ProcessPriority::ANDROID_NON_EXISTS; |
76 } | 75 } |
77 | 76 |
78 // TODO(cylee): Check whether the tab is in foreground or not. | 77 // TODO(cylee): Check whether the tab is in foreground or not. |
79 int TabStatsToPriority(const TabStats& tab) { | 78 int TabStatsToPriority(const TabStats& tab) { |
80 int priority = 0; | 79 int priority = 0; |
81 if (tab.is_app) { | 80 if (tab.is_app) { |
82 priority = ProcessPriority::CHROME_APP; | 81 priority = ProcessPriority::CHROME_APP; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 DCHECK(arc_bridge_service); | 131 DCHECK(arc_bridge_service); |
133 | 132 |
134 arc_process_instance_ = arc_bridge_service->process_instance(); | 133 arc_process_instance_ = arc_bridge_service->process_instance(); |
135 arc_process_instance_version_ = arc_bridge_service->process_version(); | 134 arc_process_instance_version_ = arc_bridge_service->process_version(); |
136 | 135 |
137 if (!IsArcMemoryManagementEnabled()) | 136 if (!IsArcMemoryManagementEnabled()) |
138 return; | 137 return; |
139 | 138 |
140 DCHECK(arc_process_instance_); | 139 DCHECK(arc_process_instance_); |
141 if (arc_process_instance_version_ < 2) { | 140 if (arc_process_instance_version_ < 2) { |
142 VLOG(1) << "arc::ProcessInstance version < 2 does not " | 141 VLOG(1) << "ProcessInstance version < 2 does not " |
143 "support DisableBuiltinOomAdjustment() yet."; | 142 "support DisableBuiltinOomAdjustment() yet."; |
144 return; | 143 return; |
145 } | 144 } |
146 // If --enable-arc-memory-management is on, stop Android system-wide | 145 // If --enable-arc-memory-management is on, stop Android system-wide |
147 // oom_adj adjustment since this class will take over oom_score_adj settings. | 146 // oom_adj adjustment since this class will take over oom_score_adj settings. |
148 arc_process_instance_->DisableBuiltinOomAdjustment(); | 147 arc_process_instance_->DisableBuiltinOomAdjustment(); |
149 } | 148 } |
150 | 149 |
151 void TabManagerDelegate::OnProcessInstanceClosed() { | 150 void TabManagerDelegate::OnProcessInstanceClosed() { |
152 arc_process_instance_ = nullptr; | 151 arc_process_instance_ = nullptr; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 range_middle, chrome::kHighestRendererOomScore, | 392 range_middle, chrome::kHighestRendererOomScore, |
394 &new_map); | 393 &new_map); |
395 base::AutoLock oom_score_autolock(oom_score_lock_); | 394 base::AutoLock oom_score_autolock(oom_score_lock_); |
396 oom_score_map_.swap(new_map); | 395 oom_score_map_.swap(new_map); |
397 } | 396 } |
398 | 397 |
399 void TabManagerDelegate::SetOomScoreAdjForApp(int nspid, int score) { | 398 void TabManagerDelegate::SetOomScoreAdjForApp(int nspid, int score) { |
400 if (!arc_process_instance_) | 399 if (!arc_process_instance_) |
401 return; | 400 return; |
402 if (arc_process_instance_version_ < 2) { | 401 if (arc_process_instance_version_ < 2) { |
403 VLOG(1) << "arc::ProcessInstance version < 2 does not " | 402 VLOG(1) << "ProcessInstance version < 2 does not " |
404 "support SetOomScoreAdj() yet."; | 403 "support SetOomScoreAdj() yet."; |
405 return; | 404 return; |
406 } | 405 } |
407 arc_process_instance_->SetOomScoreAdj(nspid, score); | 406 arc_process_instance_->SetOomScoreAdj(nspid, score); |
408 } | 407 } |
409 | 408 |
410 void TabManagerDelegate::SetOomScoreAdjForTabs( | 409 void TabManagerDelegate::SetOomScoreAdjForTabs( |
411 const std::vector<std::pair<base::ProcessHandle, int>>& entries) { | 410 const std::vector<std::pair<base::ProcessHandle, int>>& entries) { |
412 BrowserThread::PostTask( | 411 BrowserThread::PostTask( |
413 BrowserThread::FILE, FROM_HERE, | 412 BrowserThread::FILE, FROM_HERE, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } | 475 } |
477 } | 476 } |
478 priority += priority_increment; | 477 priority += priority_increment; |
479 } | 478 } |
480 | 479 |
481 if (oom_score_for_tabs.size()) | 480 if (oom_score_for_tabs.size()) |
482 SetOomScoreAdjForTabs(oom_score_for_tabs); | 481 SetOomScoreAdjForTabs(oom_score_for_tabs); |
483 } | 482 } |
484 | 483 |
485 } // namespace memory | 484 } // namespace memory |
OLD | NEW |