Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/memory/tab_manager_delegate_chromeos.h

Issue 2133503002: arc: Revamp the ArcBridgeService interface (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: more rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ 5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_
6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ 6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/process/process.h" 16 #include "base/process/process.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "chrome/browser/chromeos/arc/arc_process.h" 18 #include "chrome/browser/chromeos/arc/arc_process.h"
19 #include "chrome/browser/memory/tab_manager.h" 19 #include "chrome/browser/memory/tab_manager.h"
20 #include "chrome/browser/memory/tab_stats.h" 20 #include "chrome/browser/memory/tab_stats.h"
21 #include "chrome/browser/ui/browser_list_observer.h" 21 #include "chrome/browser/ui/browser_list_observer.h"
22 #include "components/arc/arc_bridge_service.h" 22 #include "components/arc/arc_bridge_service.h"
23 #include "components/arc/instance_holder.h"
23 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
25 #include "ui/wm/public/activation_change_observer.h" 26 #include "ui/wm/public/activation_change_observer.h"
26 27
27 namespace memory { 28 namespace memory {
28 29
29 // The importance of tabs/apps. The lower the value, the more likely a process 30 // The importance of tabs/apps. The lower the value, the more likely a process
30 // is to be selected on memory pressure. The values is additive, for example, 31 // is to be selected on memory pressure. The values is additive, for example,
31 // one tab could be of value (CHROME_NORMAL | CHROME_PINNED). 32 // one tab could be of value (CHROME_NORMAL | CHROME_PINNED).
32 // TODO(cylee): Refactor this CL so the prioritize logic is unified in 33 // TODO(cylee): Refactor this CL so the prioritize logic is unified in
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ANDROID_PERSISTENT = 1 << 30, 69 ANDROID_PERSISTENT = 1 << 30,
69 ANDROID_NON_EXISTS = 0x7FFFFFFF 70 ANDROID_NON_EXISTS = 0x7FFFFFFF
70 }; 71 };
71 72
72 // The Chrome OS TabManagerDelegate is responsible for keeping the 73 // The Chrome OS TabManagerDelegate is responsible for keeping the
73 // renderers' scores up to date in /proc/<pid>/oom_score_adj. 74 // renderers' scores up to date in /proc/<pid>/oom_score_adj.
74 // 75 //
75 // Note that AdjustOomPriorities will be called on the UI thread by 76 // Note that AdjustOomPriorities will be called on the UI thread by
76 // TabManager, but the actual work will take place on the file thread 77 // TabManager, but the actual work will take place on the file thread
77 // (see implementation of AdjustOomPriorities). 78 // (see implementation of AdjustOomPriorities).
78 class TabManagerDelegate : public arc::ArcBridgeService::Observer, 79 class TabManagerDelegate
79 public aura::client::ActivationChangeObserver, 80 : public arc::InstanceHolder<arc::mojom::ProcessInstance>::Observer,
80 public content::NotificationObserver, 81 public aura::client::ActivationChangeObserver,
81 public chrome::BrowserListObserver { 82 public content::NotificationObserver,
83 public chrome::BrowserListObserver {
82 public: 84 public:
83 class MemoryStat; 85 class MemoryStat;
84 86
85 explicit TabManagerDelegate(const base::WeakPtr<TabManager>& tab_manager); 87 explicit TabManagerDelegate(const base::WeakPtr<TabManager>& tab_manager);
86 88
87 TabManagerDelegate(const base::WeakPtr<TabManager>& tab_manager, 89 TabManagerDelegate(const base::WeakPtr<TabManager>& tab_manager,
88 TabManagerDelegate::MemoryStat* mem_stat); 90 TabManagerDelegate::MemoryStat* mem_stat);
89 91
90 ~TabManagerDelegate() override; 92 ~TabManagerDelegate() override;
91 93
92 void OnBrowserSetLastActive(Browser* browser) override; 94 void OnBrowserSetLastActive(Browser* browser) override;
93 95
94 // ArcBridgeService::Observer overrides. 96 // InstanceHolder<arc::mojom::ProcessInstance>::Observer overrides.
95 void OnProcessInstanceReady() override; 97 void OnInstanceReady(arc::mojom::ProcessInstance* process_instance,
96 void OnProcessInstanceClosed() override; 98 uint32_t version) override;
99 void OnInstanceClosed(arc::mojom::ProcessInstance*) override;
97 100
98 // aura::ActivationChangeObserver overrides. 101 // aura::ActivationChangeObserver overrides.
99 void OnWindowActivated( 102 void OnWindowActivated(
100 aura::client::ActivationChangeObserver::ActivationReason reason, 103 aura::client::ActivationChangeObserver::ActivationReason reason,
101 aura::Window* gained_active, 104 aura::Window* gained_active,
102 aura::Window* lost_active) override; 105 aura::Window* lost_active) override;
103 106
104 // Kills a process on memory pressure. 107 // Kills a process on memory pressure.
105 void LowMemoryKill(const TabStatsList& tab_stats); 108 void LowMemoryKill(const TabStatsList& tab_stats);
106 109
(...skipping 22 matching lines...) Expand all
129 132
130 private: 133 private:
131 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted); 134 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted);
132 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses); 135 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses);
133 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj); 136 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj);
134 137
135 struct Candidate; 138 struct Candidate;
136 class FocusedProcess; 139 class FocusedProcess;
137 class UmaReporter; 140 class UmaReporter;
138 141
139 friend std::ostream& operator<<( 142 friend std::ostream& operator<<(std::ostream& out,
140 std::ostream& out, const Candidate& candidate); 143 const Candidate& candidate);
141 144
142 // content::NotificationObserver: 145 // content::NotificationObserver:
143 void Observe(int type, 146 void Observe(int type,
144 const content::NotificationSource& source, 147 const content::NotificationSource& source,
145 const content::NotificationDetails& details) override; 148 const content::NotificationDetails& details) override;
146 149
147 // Pair to hold child process host id and ProcessHandle. 150 // Pair to hold child process host id and ProcessHandle.
148 typedef std::pair<int, base::ProcessHandle> ProcessInfo; 151 typedef std::pair<int, base::ProcessHandle> ProcessInfo;
149 152
150 // Cache OOM scores in memory. 153 // Cache OOM scores in memory.
151 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; 154 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; // NOLINT
152 155
153 // Get the list of candidates to kill, sorted by reversed importance. 156 // Get the list of candidates to kill, sorted by reversed importance.
154 static std::vector<Candidate> GetSortedCandidates( 157 static std::vector<Candidate> GetSortedCandidates(
155 const TabStatsList& tab_list, 158 const TabStatsList& tab_list,
156 const std::vector<arc::ArcProcess>& arc_processes); 159 const std::vector<arc::ArcProcess>& arc_processes);
157 160
158 // Posts AdjustFocusedTabScore task to the file thread. 161 // Posts AdjustFocusedTabScore task to the file thread.
159 void OnFocusTabScoreAdjustmentTimeout(); 162 void OnFocusTabScoreAdjustmentTimeout();
160 163
161 // Kills a process after getting all info of tabs and apps. 164 // Kills a process after getting all info of tabs and apps.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // On ARC enabled machines, either a tab or an app could be a possible 239 // On ARC enabled machines, either a tab or an app could be a possible
237 // victim of low memory kill process. This is a helper struct which holds a 240 // victim of low memory kill process. This is a helper struct which holds a
238 // pointer to an app or a tab (but not both) to facilitate prioritizing the 241 // pointer to an app or a tab (but not both) to facilitate prioritizing the
239 // victims. 242 // victims.
240 struct TabManagerDelegate::Candidate { 243 struct TabManagerDelegate::Candidate {
241 Candidate(const TabStats* _tab, int _priority) 244 Candidate(const TabStats* _tab, int _priority)
242 : tab(_tab), priority(_priority), is_arc_app(false) {} 245 : tab(_tab), priority(_priority), is_arc_app(false) {}
243 Candidate(const arc::ArcProcess* _app, int _priority) 246 Candidate(const arc::ArcProcess* _app, int _priority)
244 : app(_app), priority(_priority), is_arc_app(true) {} 247 : app(_app), priority(_priority), is_arc_app(true) {}
245 248
246 bool operator<(const Candidate& rhs) const { 249 bool operator<(const Candidate& rhs) const { return priority < rhs.priority; }
247 return priority < rhs.priority;
248 }
249 250
250 union { 251 union {
251 const TabStats* tab; 252 const TabStats* tab;
252 const arc::ArcProcess* app; 253 const arc::ArcProcess* app;
253 }; 254 };
254 int priority; 255 int priority;
255 bool is_arc_app; 256 bool is_arc_app;
256 }; 257 };
257 258
258 // A thin wrapper over library process_metric.h to get memory status so unit 259 // A thin wrapper over library process_metric.h to get memory status so unit
(...skipping 15 matching lines...) Expand all
274 // reported if available memory is under the number. 275 // reported if available memory is under the number.
275 static int LowMemoryMarginKB(); 276 static int LowMemoryMarginKB();
276 277
277 // Reads in an integer. 278 // Reads in an integer.
278 static int ReadIntFromFile(const char* file_name, int default_val); 279 static int ReadIntFromFile(const char* file_name, int default_val);
279 }; 280 };
280 281
281 } // namespace memory 282 } // namespace memory
282 283
283 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ 284 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698