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

Side by Side Diff: chrome/browser/memory/tab_manager.cc

Issue 2399293002: Add MemoryCoordinatorDelegate (Closed)
Patch Set: Add workaround for tests Created 4 years, 2 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
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/memory/tab_manager.h" 5 #include "chrome/browser/memory/tab_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (monitor) { 204 if (monitor) {
205 memory_pressure_listener_.reset(new base::MemoryPressureListener( 205 memory_pressure_listener_.reset(new base::MemoryPressureListener(
206 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this)))); 206 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this))));
207 base::MemoryPressureListener::MemoryPressureLevel level = 207 base::MemoryPressureListener::MemoryPressureLevel level =
208 monitor->GetCurrentPressureLevel(); 208 monitor->GetCurrentPressureLevel();
209 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 209 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
210 OnMemoryPressure(level); 210 OnMemoryPressure(level);
211 } 211 }
212 } 212 }
213 #endif 213 #endif
214 MemoryCoordinatorDelegate::Set(weak_ptr_factory_.GetWeakPtr());
214 } 215 }
215 216
216 void TabManager::Stop() { 217 void TabManager::Stop() {
217 update_timer_.Stop(); 218 update_timer_.Stop();
218 recent_tab_discard_timer_.Stop(); 219 recent_tab_discard_timer_.Stop();
219 memory_pressure_listener_.reset(); 220 memory_pressure_listener_.reset();
220 } 221 }
221 222
222 TabStatsList TabManager::GetTabStats() { 223 TabStatsList TabManager::GetTabStats() {
223 TabStatsList stats_list(GetUnsortedTabStats()); 224 TabStatsList stats_list(GetUnsortedTabStats());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 412
412 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const { 413 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const {
413 return GetWebContentsData(contents)->IsAutoDiscardable(); 414 return GetWebContentsData(contents)->IsAutoDiscardable();
414 } 415 }
415 416
416 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents, 417 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents,
417 bool state) { 418 bool state) {
418 GetWebContentsData(contents)->SetAutoDiscardableState(state); 419 GetWebContentsData(contents)->SetAutoDiscardableState(state);
419 } 420 }
420 421
422 bool TabManager::CanSuspendBackgroundedRenderer(int render_process_id) {
423 // A renderer can be suspended if it's not playing media.
424 auto tab_stats = GetUnsortedTabStats();
425 for (auto& tab : tab_stats) {
426 if (tab.child_process_host_id != render_process_id)
427 continue;
428 TabStripModel* model;
429 int index = FindTabStripModelById(tab.tab_contents_id, &model);
430 if (index == -1)
431 return false;
432 WebContents* web_contents = model->GetWebContentsAt(index);
433 if (IsMediaTab(web_contents))
434 return false;
435 }
436 return true;
437 }
438
421 // static 439 // static
422 bool TabManager::CompareTabStats(const TabStats& first, 440 bool TabManager::CompareTabStats(const TabStats& first,
423 const TabStats& second) { 441 const TabStats& second) {
424 // Being currently selected is most important to protect. 442 // Being currently selected is most important to protect.
425 if (first.is_selected != second.is_selected) 443 if (first.is_selected != second.is_selected)
426 return first.is_selected; 444 return first.is_selected;
427 445
428 // Non auto-discardable tabs are more important to protect. 446 // Non auto-discardable tabs are more important to protect.
429 if (first.is_auto_discardable != second.is_auto_discardable) 447 if (first.is_auto_discardable != second.is_auto_discardable)
430 return !first.is_auto_discardable; 448 return !first.is_auto_discardable;
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 // platform. 958 // platform.
941 std::string allow_multiple_discards = variations::GetVariationParamValue( 959 std::string allow_multiple_discards = variations::GetVariationParamValue(
942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); 960 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards");
943 return (allow_multiple_discards != "true"); 961 return (allow_multiple_discards != "true");
944 #else 962 #else
945 return false; 963 return false;
946 #endif 964 #endif
947 } 965 }
948 966
949 } // namespace memory 967 } // namespace memory
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698