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

Side by Side Diff: chrome/browser/oom_priority_manager.cc

Issue 8566033: base::Bind fixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed review issues Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/omnibox_search_hint.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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));
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // TabStripModel isn't thread safe): 245 // TabStripModel isn't thread safe):
245 // 1) whether or not a tab is pinned 246 // 1) whether or not a tab is pinned
246 // 2) last time a tab was selected 247 // 2) last time a tab was selected
247 // 3) is the tab currently selected 248 // 3) is the tab currently selected
248 void OomPriorityManager::AdjustOomPriorities() { 249 void OomPriorityManager::AdjustOomPriorities() {
249 if (BrowserList::size() == 0) 250 if (BrowserList::size() == 0)
250 return; 251 return;
251 TabStatsList stats_list = GetTabStatsOnUIThread(); 252 TabStatsList stats_list = GetTabStatsOnUIThread();
252 BrowserThread::PostTask( 253 BrowserThread::PostTask(
253 BrowserThread::FILE, FROM_HERE, 254 BrowserThread::FILE, FROM_HERE,
254 NewRunnableMethod(this, 255 base::Bind(&OomPriorityManager::AdjustOomPrioritiesOnFileThread,
255 &OomPriorityManager::AdjustOomPrioritiesOnFileThread, 256 this, stats_list));
256 stats_list));
257 } 257 }
258 258
259 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() { 259 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
261 TabStatsList stats_list; 261 TabStatsList stats_list;
262 stats_list.reserve(32); // 99% of users have < 30 tabs open 262 stats_list.reserve(32); // 99% of users have < 30 tabs open
263 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); 263 for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
264 browser_iterator != BrowserList::end(); ++browser_iterator) { 264 browser_iterator != BrowserList::end(); ++browser_iterator) {
265 Browser* browser = *browser_iterator; 265 Browser* browser = *browser_iterator;
266 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
324 ZygoteHost::GetInstance()->AdjustRendererOOMScore( 324 ZygoteHost::GetInstance()->AdjustRendererOOMScore(
325 iterator->renderer_handle, score); 325 iterator->renderer_handle, score);
326 pid_to_oom_score_[iterator->renderer_handle] = score; 326 pid_to_oom_score_[iterator->renderer_handle] = score;
327 } 327 }
328 priority += priority_increment; 328 priority += priority_increment;
329 } 329 }
330 } 330 }
331 } 331 }
332 332
333 } // namespace browser 333 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/omnibox_search_hint.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698