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" | |
11 #include "base/process.h" | 10 #include "base/process.h" |
12 #include "base/process_util.h" | 11 #include "base/process_util.h" |
13 #include "base/string16.h" | 12 #include "base/string16.h" |
14 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
17 #include "base/timer.h" | 16 #include "base/timer.h" |
18 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
20 #include "chrome/browser/tabs/tab_strip_model.h" | 19 #include "chrome/browser/tabs/tab_strip_model.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
176 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); | 175 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); |
177 ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 176 ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
178 focused_tab_pid_, chrome::kLowestRendererOomScore); | 177 focused_tab_pid_, chrome::kLowestRendererOomScore); |
179 pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore; | 178 pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore; |
180 } | 179 } |
181 | 180 |
182 void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() { | 181 void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() { |
183 BrowserThread::PostTask( | 182 BrowserThread::PostTask( |
184 BrowserThread::FILE, FROM_HERE, | 183 BrowserThread::FILE, FROM_HERE, |
185 base::Bind( | 184 NewRunnableMethod( |
186 &OomPriorityManager::AdjustFocusedTabScoreOnFileThread, this)); | 185 this, &OomPriorityManager::AdjustFocusedTabScoreOnFileThread)); |
187 } | 186 } |
188 | 187 |
189 void OomPriorityManager::Observe(int type, | 188 void OomPriorityManager::Observe(int type, |
190 const content::NotificationSource& source, | 189 const content::NotificationSource& source, |
191 const content::NotificationDetails& details) { | 190 const content::NotificationDetails& details) { |
192 base::ProcessHandle handle = 0; | 191 base::ProcessHandle handle = 0; |
193 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); | 192 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); |
194 switch (type) { | 193 switch (type) { |
195 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 194 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
196 handle = | 195 handle = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // TabStripModel isn't thread safe): | 244 // TabStripModel isn't thread safe): |
246 // 1) whether or not a tab is pinned | 245 // 1) whether or not a tab is pinned |
247 // 2) last time a tab was selected | 246 // 2) last time a tab was selected |
248 // 3) is the tab currently selected | 247 // 3) is the tab currently selected |
249 void OomPriorityManager::AdjustOomPriorities() { | 248 void OomPriorityManager::AdjustOomPriorities() { |
250 if (BrowserList::size() == 0) | 249 if (BrowserList::size() == 0) |
251 return; | 250 return; |
252 TabStatsList stats_list = GetTabStatsOnUIThread(); | 251 TabStatsList stats_list = GetTabStatsOnUIThread(); |
253 BrowserThread::PostTask( | 252 BrowserThread::PostTask( |
254 BrowserThread::FILE, FROM_HERE, | 253 BrowserThread::FILE, FROM_HERE, |
255 base::Bind(&OomPriorityManager::AdjustOomPrioritiesOnFileThread, | 254 NewRunnableMethod(this, |
256 this, stats_list)); | 255 &OomPriorityManager::AdjustOomPrioritiesOnFileThread, |
| 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 Loading... |
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 |
OLD | NEW |