OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/process.h" | 12 #include "base/process.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/timer.h" | 18 #include "base/timer.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "chrome/browser/low_memory_observer.h" | 21 #include "chrome/browser/low_memory_observer.h" |
22 #include "chrome/browser/tabs/tab_strip_model.h" | 22 #include "chrome/browser/tabs/tab_strip_model.h" |
23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
25 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
26 #include "content/browser/renderer_host/render_widget_host.h" | 26 #include "content/browser/renderer_host/render_widget_host.h" |
27 #include "content/browser/zygote_host_linux.h" | |
28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
31 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
32 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/browser/zygote_host_linux.h" |
33 | 33 |
34 #if !defined(OS_CHROMEOS) | 34 #if !defined(OS_CHROMEOS) |
35 #error This file only meant to be compiled on ChromeOS | 35 #error This file only meant to be compiled on ChromeOS |
36 #endif | 36 #endif |
37 | 37 |
38 using base::ProcessHandle; | 38 using base::ProcessHandle; |
39 using base::ProcessMetrics; | 39 using base::ProcessMetrics; |
40 using base::TimeDelta; | 40 using base::TimeDelta; |
41 using base::TimeTicks; | 41 using base::TimeTicks; |
42 using content::BrowserThread; | 42 using content::BrowserThread; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if (first.is_pinned != second.is_pinned) | 176 if (first.is_pinned != second.is_pinned) |
177 return first.is_pinned == true; | 177 return first.is_pinned == true; |
178 | 178 |
179 // Being more recently selected is more important. | 179 // Being more recently selected is more important. |
180 return first.last_selected > second.last_selected; | 180 return first.last_selected > second.last_selected; |
181 } | 181 } |
182 | 182 |
183 void OomPriorityManager::AdjustFocusedTabScoreOnFileThread() { | 183 void OomPriorityManager::AdjustFocusedTabScoreOnFileThread() { |
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
185 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); | 185 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); |
186 ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 186 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
187 focused_tab_pid_, chrome::kLowestRendererOomScore); | 187 focused_tab_pid_, chrome::kLowestRendererOomScore); |
188 pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore; | 188 pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore; |
189 } | 189 } |
190 | 190 |
191 void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() { | 191 void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() { |
192 BrowserThread::PostTask( | 192 BrowserThread::PostTask( |
193 BrowserThread::FILE, FROM_HERE, | 193 BrowserThread::FILE, FROM_HERE, |
194 base::Bind(&OomPriorityManager::AdjustFocusedTabScoreOnFileThread, | 194 base::Bind(&OomPriorityManager::AdjustFocusedTabScoreOnFileThread, |
195 base::Unretained(this))); | 195 base::Unretained(this))); |
196 } | 196 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 ProcessScoreMap::iterator it; | 323 ProcessScoreMap::iterator it; |
324 for (TabStatsList::iterator iterator = stats_list.begin(); | 324 for (TabStatsList::iterator iterator = stats_list.begin(); |
325 iterator != stats_list.end(); ++iterator) { | 325 iterator != stats_list.end(); ++iterator) { |
326 if (already_seen.find(iterator->renderer_handle) == already_seen.end()) { | 326 if (already_seen.find(iterator->renderer_handle) == already_seen.end()) { |
327 already_seen.insert(iterator->renderer_handle); | 327 already_seen.insert(iterator->renderer_handle); |
328 // If a process has the same score as the newly calculated value, | 328 // If a process has the same score as the newly calculated value, |
329 // do not set it. | 329 // do not set it. |
330 score = static_cast<int>(priority + 0.5f); | 330 score = static_cast<int>(priority + 0.5f); |
331 it = pid_to_oom_score_.find(iterator->renderer_handle); | 331 it = pid_to_oom_score_.find(iterator->renderer_handle); |
332 if (it == pid_to_oom_score_.end() || it->second != score) { | 332 if (it == pid_to_oom_score_.end() || it->second != score) { |
333 ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 333 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
334 iterator->renderer_handle, score); | 334 iterator->renderer_handle, score); |
335 pid_to_oom_score_[iterator->renderer_handle] = score; | 335 pid_to_oom_score_[iterator->renderer_handle] = score; |
336 } | 336 } |
337 priority += priority_increment; | 337 priority += priority_increment; |
338 } | 338 } |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 } // namespace browser | 342 } // namespace browser |
OLD | NEW |