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

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 rebasing 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() override;
96 void OnProcessInstanceClosed() override; 98 void OnInstanceClosed() override;
97 99
98 // aura::ActivationChangeObserver overrides. 100 // aura::ActivationChangeObserver overrides.
99 void OnWindowActivated( 101 void OnWindowActivated(
100 aura::client::ActivationChangeObserver::ActivationReason reason, 102 aura::client::ActivationChangeObserver::ActivationReason reason,
101 aura::Window* gained_active, 103 aura::Window* gained_active,
102 aura::Window* lost_active) override; 104 aura::Window* lost_active) override;
103 105
104 // Kills a process on memory pressure. 106 // Kills a process on memory pressure.
105 void LowMemoryKill(const TabStatsList& tab_stats); 107 void LowMemoryKill(const TabStatsList& tab_stats);
106 108
(...skipping 22 matching lines...) Expand all
129 131
130 private: 132 private:
131 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted); 133 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted);
132 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses); 134 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses);
133 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj); 135 FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj);
134 136
135 struct Candidate; 137 struct Candidate;
136 class FocusedProcess; 138 class FocusedProcess;
137 class UmaReporter; 139 class UmaReporter;
138 140
139 friend std::ostream& operator<<( 141 friend std::ostream& operator<<(std::ostream& out,
140 std::ostream& out, const Candidate& candidate); 142 const Candidate& candidate);
141 143
142 // content::NotificationObserver: 144 // content::NotificationObserver:
143 void Observe(int type, 145 void Observe(int type,
144 const content::NotificationSource& source, 146 const content::NotificationSource& source,
145 const content::NotificationDetails& details) override; 147 const content::NotificationDetails& details) override;
146 148
147 // Pair to hold child process host id and ProcessHandle. 149 // Pair to hold child process host id and ProcessHandle.
148 typedef std::pair<int, base::ProcessHandle> ProcessInfo; 150 typedef std::pair<int, base::ProcessHandle> ProcessInfo;
149 151
150 // Cache OOM scores in memory. 152 // Cache OOM scores in memory.
151 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; 153 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; // NOLINT
152 154
153 // Get the list of candidates to kill, sorted by reversed importance. 155 // Get the list of candidates to kill, sorted by reversed importance.
154 static std::vector<Candidate> GetSortedCandidates( 156 static std::vector<Candidate> GetSortedCandidates(
155 const TabStatsList& tab_list, 157 const TabStatsList& tab_list,
156 const std::vector<arc::ArcProcess>& arc_processes); 158 const std::vector<arc::ArcProcess>& arc_processes);
157 159
158 // Posts AdjustFocusedTabScore task to the file thread. 160 // Posts AdjustFocusedTabScore task to the file thread.
159 void OnFocusTabScoreAdjustmentTimeout(); 161 void OnFocusTabScoreAdjustmentTimeout();
160 162
161 // Kills a process after getting all info of tabs and apps. 163 // 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 238 // 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 239 // 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 240 // pointer to an app or a tab (but not both) to facilitate prioritizing the
239 // victims. 241 // victims.
240 struct TabManagerDelegate::Candidate { 242 struct TabManagerDelegate::Candidate {
241 Candidate(const TabStats* _tab, int _priority) 243 Candidate(const TabStats* _tab, int _priority)
242 : tab(_tab), priority(_priority), is_arc_app(false) {} 244 : tab(_tab), priority(_priority), is_arc_app(false) {}
243 Candidate(const arc::ArcProcess* _app, int _priority) 245 Candidate(const arc::ArcProcess* _app, int _priority)
244 : app(_app), priority(_priority), is_arc_app(true) {} 246 : app(_app), priority(_priority), is_arc_app(true) {}
245 247
246 bool operator<(const Candidate& rhs) const { 248 bool operator<(const Candidate& rhs) const { return priority < rhs.priority; }
247 return priority < rhs.priority;
248 }
249 249
250 union { 250 union {
251 const TabStats* tab; 251 const TabStats* tab;
252 const arc::ArcProcess* app; 252 const arc::ArcProcess* app;
253 }; 253 };
254 int priority; 254 int priority;
255 bool is_arc_app; 255 bool is_arc_app;
256 }; 256 };
257 257
258 // A thin wrapper over library process_metric.h to get memory status so unit 258 // 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. 274 // reported if available memory is under the number.
275 static int LowMemoryMarginKB(); 275 static int LowMemoryMarginKB();
276 276
277 // Reads in an integer. 277 // Reads in an integer.
278 static int ReadIntFromFile(const char* file_name, int default_val); 278 static int ReadIntFromFile(const char* file_name, int default_val);
279 }; 279 };
280 280
281 } // namespace memory 281 } // namespace memory
282 282
283 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ 283 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/arc_file_tasks.cc ('k') | chrome/browser/memory/tab_manager_delegate_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698