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

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

Issue 12211139: Phase out BrowserList::empty() and BrowserList::size(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos Created 7 years, 10 months 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 | « no previous file | chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc » ('j') | 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) 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
(...skipping 10 matching lines...) Expand all
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_iterator.h"
31 #include "chrome/browser/ui/browser_list.h" 31 #include "chrome/browser/ui/browser_list_impl.h"
32 #include "chrome/browser/ui/host_desktop.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 33 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
35 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/notification_types.h" 40 #include "content/public/browser/notification_types.h"
40 #include "content/public/browser/render_process_host.h" 41 #include "content/public/browser/render_process_host.h"
41 #include "content/public/browser/render_widget_host.h" 42 #include "content/public/browser/render_widget_host.h"
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Here we collect most of the information we need to sort the 522 // Here we collect most of the information we need to sort the
522 // existing renderers in priority order, and hand out oom_score_adj 523 // existing renderers in priority order, and hand out oom_score_adj
523 // scores based on that sort order. 524 // scores based on that sort order.
524 // 525 //
525 // Things we need to collect on the browser thread (because 526 // Things we need to collect on the browser thread (because
526 // TabStripModel isn't thread safe): 527 // TabStripModel isn't thread safe):
527 // 1) whether or not a tab is pinned 528 // 1) whether or not a tab is pinned
528 // 2) last time a tab was selected 529 // 2) last time a tab was selected
529 // 3) is the tab currently selected 530 // 3) is the tab currently selected
530 void OomPriorityManager::AdjustOomPriorities() { 531 void OomPriorityManager::AdjustOomPriorities() {
531 if (BrowserList::size() == 0) 532 if (chrome::BrowserListImpl::GetInstance(
533 chrome::HOST_DESKTOP_TYPE_ASH)->empty()) {
532 return; 534 return;
535 }
533 536
534 // Check for a discontinuity in time caused by the machine being suspended. 537 // Check for a discontinuity in time caused by the machine being suspended.
535 if (!last_adjust_time_.is_null()) { 538 if (!last_adjust_time_.is_null()) {
536 TimeDelta suspend_time = TimeTicks::Now() - last_adjust_time_; 539 TimeDelta suspend_time = TimeTicks::Now() - last_adjust_time_;
537 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { 540 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) {
538 // We were probably suspended, move our event timers forward in time so 541 // We were probably suspended, move our event timers forward in time so
539 // when we subtract them out later we are counting "uptime". 542 // when we subtract them out later we are counting "uptime".
540 start_time_ += suspend_time; 543 start_time_ += suspend_time;
541 if (!last_discard_time_.is_null()) 544 if (!last_discard_time_.is_null())
542 last_discard_time_ += suspend_time; 545 last_discard_time_ += suspend_time;
543 } 546 }
544 } 547 }
545 last_adjust_time_ = TimeTicks::Now(); 548 last_adjust_time_ = TimeTicks::Now();
546 549
547 TabStatsList stats_list = GetTabStatsOnUIThread(); 550 TabStatsList stats_list = GetTabStatsOnUIThread();
548 BrowserThread::PostTask( 551 BrowserThread::PostTask(
549 BrowserThread::FILE, FROM_HERE, 552 BrowserThread::FILE, FROM_HERE,
550 base::Bind(&OomPriorityManager::AdjustOomPrioritiesOnFileThread, 553 base::Bind(&OomPriorityManager::AdjustOomPrioritiesOnFileThread,
551 base::Unretained(this), stats_list)); 554 base::Unretained(this), stats_list));
552 } 555 }
553 556
554 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() { 557 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() {
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
556 TabStatsList stats_list; 559 TabStatsList stats_list;
557 stats_list.reserve(32); // 99% of users have < 30 tabs open 560 stats_list.reserve(32); // 99% of users have < 30 tabs open
558 bool browser_active = true; 561 bool browser_active = true;
559 for (BrowserList::const_reverse_iterator browser_iterator = 562 const chrome::BrowserListImpl* ash_browser_list =
560 BrowserList::begin_last_active(); 563 chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
561 browser_iterator != BrowserList::end_last_active(); 564 for (chrome::BrowserListImpl::const_reverse_iterator browser_iterator =
565 ash_browser_list->begin_last_active();
566 browser_iterator != ash_browser_list->end_last_active();
562 ++browser_iterator) { 567 ++browser_iterator) {
563 Browser* browser = *browser_iterator; 568 Browser* browser = *browser_iterator;
564 bool is_browser_for_app = browser->is_app(); 569 bool is_browser_for_app = browser->is_app();
565 const TabStripModel* model = browser->tab_strip_model(); 570 const TabStripModel* model = browser->tab_strip_model();
566 for (int i = 0; i < model->count(); i++) { 571 for (int i = 0; i < model->count(); i++) {
567 WebContents* contents = model->GetWebContentsAt(i); 572 WebContents* contents = model->GetWebContentsAt(i);
568 if (!contents->IsCrashed()) { 573 if (!contents->IsCrashed()) {
569 TabStats stats; 574 TabStats stats;
570 stats.is_app = is_browser_for_app; 575 stats.is_app = is_browser_for_app;
571 stats.is_reloadable_ui = IsReloadableUI(contents->GetURL()); 576 stats.is_reloadable_ui = IsReloadableUI(contents->GetURL());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( 637 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore(
633 iterator->renderer_handle, score); 638 iterator->renderer_handle, score);
634 pid_to_oom_score_[iterator->renderer_handle] = score; 639 pid_to_oom_score_[iterator->renderer_handle] = score;
635 } 640 }
636 priority += priority_increment; 641 priority += priority_increment;
637 } 642 }
638 } 643 }
639 } 644 }
640 645
641 } // namespace chromeos 646 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698