OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/oom_priority_manager.h" | 5 #include "chrome/browser/oom_priority_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | |
10 #include "base/process.h" | 11 #include "base/process.h" |
11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "base/timer.h" | 17 #include "base/timer.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/tabs/tab_strip_model.h" | 20 #include "chrome/browser/tabs/tab_strip_model.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
175 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); | 176 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); |
176 ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 177 ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
177 focused_tab_pid_, chrome::kLowestRendererOomScore); | 178 focused_tab_pid_, chrome::kLowestRendererOomScore); |
178 pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore; | 179 pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore; |
179 } | 180 } |
180 | 181 |
181 void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() { | 182 void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() { |
182 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
183 BrowserThread::FILE, FROM_HERE, | 184 BrowserThread::FILE, FROM_HERE, |
184 NewRunnableMethod( | 185 base::Bind( |
185 this, &OomPriorityManager::AdjustFocusedTabScoreOnFileThread)); | 186 &OomPriorityManager::AdjustFocusedTabScoreOnFileThread, this)); |
James Hawkins
2011/11/19 03:31:12
Do you still need this wrapped?
groby-ooo-7-16
2011/11/21 22:50:14
What do you mean by wrapped?
On 2011/11/19 03:31:1
groby-ooo-7-16
2011/11/21 22:54:48
If you mean line-wrapped (sorry, only realized tha
| |
186 } | 187 } |
187 | 188 |
188 void OomPriorityManager::Observe(int type, | 189 void OomPriorityManager::Observe(int type, |
189 const content::NotificationSource& source, | 190 const content::NotificationSource& source, |
190 const content::NotificationDetails& details) { | 191 const content::NotificationDetails& details) { |
191 base::ProcessHandle handle = 0; | 192 base::ProcessHandle handle = 0; |
192 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); | 193 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); |
193 switch (type) { | 194 switch (type) { |
194 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 195 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
195 handle = | 196 handle = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 // TabStripModel isn't thread safe): | 244 // TabStripModel isn't thread safe): |
244 // 1) whether or not a tab is pinned | 245 // 1) whether or not a tab is pinned |
245 // 2) last time a tab was selected | 246 // 2) last time a tab was selected |
246 // 3) is the tab currently selected | 247 // 3) is the tab currently selected |
247 void OomPriorityManager::AdjustOomPriorities() { | 248 void OomPriorityManager::AdjustOomPriorities() { |
248 if (BrowserList::size() == 0) | 249 if (BrowserList::size() == 0) |
249 return; | 250 return; |
250 TabStatsList stats_list = GetTabStatsOnUIThread(); | 251 TabStatsList stats_list = GetTabStatsOnUIThread(); |
251 BrowserThread::PostTask( | 252 BrowserThread::PostTask( |
252 BrowserThread::FILE, FROM_HERE, | 253 BrowserThread::FILE, FROM_HERE, |
253 NewRunnableMethod(this, | 254 base::Bind(&OomPriorityManager::AdjustOomPrioritiesOnFileThread, |
254 &OomPriorityManager::AdjustOomPrioritiesOnFileThread, | 255 this, |
255 stats_list)); | 256 stats_list)); |
James Hawkins
2011/11/19 03:31:12
Save a line: put this on the line above.
groby-ooo-7-16
2011/11/21 22:54:48
Done.
| |
256 } | 257 } |
257 | 258 |
258 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() { | 259 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() { |
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
260 TabStatsList stats_list; | 261 TabStatsList stats_list; |
261 stats_list.reserve(32); // 99% of users have < 30 tabs open | 262 stats_list.reserve(32); // 99% of users have < 30 tabs open |
262 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); | 263 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); |
263 browser_iterator != BrowserList::end(); ++browser_iterator) { | 264 browser_iterator != BrowserList::end(); ++browser_iterator) { |
264 Browser* browser = *browser_iterator; | 265 Browser* browser = *browser_iterator; |
265 const TabStripModel* model = browser->tabstrip_model(); | 266 const TabStripModel* model = browser->tabstrip_model(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 324 ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
324 iterator->renderer_handle, score); | 325 iterator->renderer_handle, score); |
325 pid_to_oom_score_[iterator->renderer_handle] = score; | 326 pid_to_oom_score_[iterator->renderer_handle] = score; |
326 } | 327 } |
327 priority += priority_increment; | 328 priority += priority_increment; |
328 } | 329 } |
329 } | 330 } |
330 } | 331 } |
331 | 332 |
332 } // namespace browser | 333 } // namespace browser |
OLD | NEW |