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

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

Issue 2399293002: Add MemoryCoordinatorDelegate (Closed)
Patch Set: 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::CanSuspendRenderer(int render_process_id) {
423 auto tab_stats = GetUnsortedTabStats();
424 for (auto& tab : tab_stats) {
bashi 2016/10/07 04:03:41 This isn't efficient but I couldn't figure out how
haraken 2016/10/07 06:38:19 Yeah, the underlying issue is that we have a way t
425 if (tab.child_process_host_id != render_process_id)
426 continue;
427 if (!CanDiscardTab(tab.tab_contents_id))
bashi 2016/10/07 04:03:41 Or we may want to check only IsMediaTab()
haraken 2016/10/07 06:38:19 Yes, but we can fix this later.
428 return false;
429 }
430 return true;
431 }
432
421 // static 433 // static
422 bool TabManager::CompareTabStats(const TabStats& first, 434 bool TabManager::CompareTabStats(const TabStats& first,
423 const TabStats& second) { 435 const TabStats& second) {
424 // Being currently selected is most important to protect. 436 // Being currently selected is most important to protect.
425 if (first.is_selected != second.is_selected) 437 if (first.is_selected != second.is_selected)
426 return first.is_selected; 438 return first.is_selected;
427 439
428 // Non auto-discardable tabs are more important to protect. 440 // Non auto-discardable tabs are more important to protect.
429 if (first.is_auto_discardable != second.is_auto_discardable) 441 if (first.is_auto_discardable != second.is_auto_discardable)
430 return !first.is_auto_discardable; 442 return !first.is_auto_discardable;
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 // platform. 952 // platform.
941 std::string allow_multiple_discards = variations::GetVariationParamValue( 953 std::string allow_multiple_discards = variations::GetVariationParamValue(
942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); 954 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards");
943 return (allow_multiple_discards != "true"); 955 return (allow_multiple_discards != "true");
944 #else 956 #else
945 return false; 957 return false;
946 #endif 958 #endif
947 } 959 }
948 960
949 } // namespace memory 961 } // namespace memory
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698