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/chromeos/memory/oom_priority_manager.h" | 5 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/process.h" | 16 #include "base/process.h" |
17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
23 #include "base/time.h" | 23 #include "base/time.h" |
24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/chromeos/memory/low_memory_observer.h" | 27 #include "chrome/browser/chromeos/memory/low_memory_observer.h" |
28 #include "chrome/browser/memory_details.h" | 28 #include "chrome/browser/memory_details.h" |
29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_iterator.h" |
30 #include "chrome/browser/ui/browser_list.h" | 31 #include "chrome/browser/ui/browser_list.h" |
31 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
33 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/notification_types.h" | 39 #include "content/public/browser/notification_types.h" |
39 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 for (size_t i = 0; i < arraysize(kReloadableUrlPrefixes); ++i) { | 259 for (size_t i = 0; i < arraysize(kReloadableUrlPrefixes); ++i) { |
259 if (!strncmp(url.spec().c_str(), | 260 if (!strncmp(url.spec().c_str(), |
260 kReloadableUrlPrefixes[i], | 261 kReloadableUrlPrefixes[i], |
261 strlen(kReloadableUrlPrefixes[i]))) | 262 strlen(kReloadableUrlPrefixes[i]))) |
262 return true; | 263 return true; |
263 } | 264 } |
264 return false; | 265 return false; |
265 } | 266 } |
266 | 267 |
267 bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) { | 268 bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) { |
268 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); | 269 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
269 browser_iterator != BrowserList::end(); ++browser_iterator) { | 270 Browser* browser = *it; |
270 Browser* browser = *browser_iterator; | |
271 TabStripModel* model = browser->tab_strip_model(); | 271 TabStripModel* model = browser->tab_strip_model(); |
272 for (int idx = 0; idx < model->count(); idx++) { | 272 for (int idx = 0; idx < model->count(); idx++) { |
273 // Can't discard tabs that are already discarded or active. | 273 // Can't discard tabs that are already discarded or active. |
274 if (model->IsTabDiscarded(idx) || (model->active_index() == idx)) | 274 if (model->IsTabDiscarded(idx) || (model->active_index() == idx)) |
275 continue; | 275 continue; |
276 WebContents* web_contents = model->GetWebContentsAt(idx); | 276 WebContents* web_contents = model->GetWebContentsAt(idx); |
277 int64 web_contents_id = IdFromWebContents(web_contents); | 277 int64 web_contents_id = IdFromWebContents(web_contents); |
278 if (web_contents_id == target_web_contents_id) { | 278 if (web_contents_id == target_web_contents_id) { |
279 LOG(WARNING) << "Discarding tab " << idx | 279 LOG(WARNING) << "Discarding tab " << idx |
280 << " id " << target_web_contents_id; | 280 << " id " << target_web_contents_id; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 WebContents* web_contents = *it; | 355 WebContents* web_contents = *it; |
356 // Screenshots can consume ~5 MB per web contents for platforms that do | 356 // Screenshots can consume ~5 MB per web contents for platforms that do |
357 // touch back/forward. | 357 // touch back/forward. |
358 web_contents->GetController().ClearAllScreenshots(); | 358 web_contents->GetController().ClearAllScreenshots(); |
359 } | 359 } |
360 // TODO(jamescook): Are there other things we could flush? Drive metadata? | 360 // TODO(jamescook): Are there other things we could flush? Drive metadata? |
361 } | 361 } |
362 | 362 |
363 int OomPriorityManager::GetTabCount() const { | 363 int OomPriorityManager::GetTabCount() const { |
364 int tab_count = 0; | 364 int tab_count = 0; |
365 for (BrowserList::const_iterator browser_it = BrowserList::begin(); | 365 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
366 browser_it != BrowserList::end(); ++browser_it) { | 366 tab_count += it->tab_strip_model()->count(); |
367 Browser* browser = *browser_it; | |
368 tab_count += browser->tab_strip_model()->count(); | |
369 } | |
370 return tab_count; | 367 return tab_count; |
371 } | 368 } |
372 | 369 |
373 // Returns true if |first| is considered less desirable to be killed | 370 // Returns true if |first| is considered less desirable to be killed |
374 // than |second|. | 371 // than |second|. |
375 bool OomPriorityManager::CompareTabStats(TabStats first, | 372 bool OomPriorityManager::CompareTabStats(TabStats first, |
376 TabStats second) { | 373 TabStats second) { |
377 // Being currently selected is most important to protect. | 374 // Being currently selected is most important to protect. |
378 if (first.is_selected != second.is_selected) | 375 if (first.is_selected != second.is_selected) |
379 return first.is_selected; | 376 return first.is_selected; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 581 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
585 iterator->renderer_handle, score); | 582 iterator->renderer_handle, score); |
586 pid_to_oom_score_[iterator->renderer_handle] = score; | 583 pid_to_oom_score_[iterator->renderer_handle] = score; |
587 } | 584 } |
588 priority += priority_increment; | 585 priority += priority_increment; |
589 } | 586 } |
590 } | 587 } |
591 } | 588 } |
592 | 589 |
593 } // namespace chromeos | 590 } // namespace chromeos |
OLD | NEW |