Chromium Code Reviews| 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/resource_coordinator/tab_manager.h" | 5 #include "chrome/browser/resource_coordinator/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 #include "chrome/common/chrome_constants.h" | 44 #include "chrome/common/chrome_constants.h" |
| 45 #include "chrome/common/chrome_features.h" | 45 #include "chrome/common/chrome_features.h" |
| 46 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
| 48 #include "components/metrics/system_memory_stats_recorder.h" | 48 #include "components/metrics/system_memory_stats_recorder.h" |
| 49 #include "components/variations/variations_associated_data.h" | 49 #include "components/variations/variations_associated_data.h" |
| 50 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 51 #include "content/public/browser/navigation_controller.h" | 51 #include "content/public/browser/navigation_controller.h" |
| 52 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
| 53 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 54 #include "content/public/common/content_features.h" | |
| 54 #include "content/public/common/page_importance_signals.h" | 55 #include "content/public/common/page_importance_signals.h" |
| 55 | 56 |
| 56 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
| 57 #include "ash/multi_profile_uma.h" | 58 #include "ash/multi_profile_uma.h" |
| 58 #include "ash/shell_port.h" | 59 #include "ash/shell_port.h" |
| 59 #include "chrome/browser/resource_coordinator/tab_manager_delegate_chromeos.h" | 60 #include "chrome/browser/resource_coordinator/tab_manager_delegate_chromeos.h" |
| 60 #include "components/user_manager/user_manager.h" | 61 #include "components/user_manager/user_manager.h" |
| 61 #endif | 62 #endif |
| 62 | 63 |
| 63 using base::TimeDelta; | 64 using base::TimeDelta; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 159 |
| 159 // MemoryPressureMonitor is not implemented on Linux so far and tabs are never | 160 // MemoryPressureMonitor is not implemented on Linux so far and tabs are never |
| 160 // discarded. | 161 // discarded. |
| 161 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 162 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 162 if (!recent_tab_discard_timer_.IsRunning()) { | 163 if (!recent_tab_discard_timer_.IsRunning()) { |
| 163 recent_tab_discard_timer_.Start( | 164 recent_tab_discard_timer_.Start( |
| 164 FROM_HERE, TimeDelta::FromSeconds(kRecentTabDiscardIntervalSeconds), | 165 FROM_HERE, TimeDelta::FromSeconds(kRecentTabDiscardIntervalSeconds), |
| 165 this, &TabManager::RecordRecentTabDiscard); | 166 this, &TabManager::RecordRecentTabDiscard); |
| 166 } | 167 } |
| 167 start_time_ = NowTicks(); | 168 start_time_ = NowTicks(); |
| 168 // Create a |MemoryPressureListener| to listen for memory events. | 169 // Create a |MemoryPressureListener| to listen for memory events when |
| 170 // MemoryCoordinator is disabled. When MemoryCoordinator is enabled | |
| 171 // it asks TabManager to tab discarding. | |
|
fmeawad
2017/06/19 19:54:59
nit: to "do" tab discarding?
bashi
2017/06/21 23:46:23
Done. Thanks!
| |
| 169 base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get(); | 172 base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get(); |
| 170 if (monitor) { | 173 if (monitor && !base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 171 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 174 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 172 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this)))); | 175 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this)))); |
| 173 base::MemoryPressureListener::MemoryPressureLevel level = | 176 base::MemoryPressureListener::MemoryPressureLevel level = |
| 174 monitor->GetCurrentPressureLevel(); | 177 monitor->GetCurrentPressureLevel(); |
| 175 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 178 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 176 OnMemoryPressure(level); | 179 OnMemoryPressure(level); |
| 177 } | 180 } |
| 178 } | 181 } |
| 179 #endif | 182 #endif |
| 180 // purge-and-suspend param is used for Purge+Suspend finch experiment | 183 // purge-and-suspend param is used for Purge+Suspend finch experiment |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 // platform. | 878 // platform. |
| 876 std::string allow_multiple_discards = variations::GetVariationParamValue( | 879 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 877 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 880 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 878 return (allow_multiple_discards != "true"); | 881 return (allow_multiple_discards != "true"); |
| 879 #else | 882 #else |
| 880 return false; | 883 return false; |
| 881 #endif | 884 #endif |
| 882 } | 885 } |
| 883 | 886 |
| 884 } // namespace resource_coordinator | 887 } // namespace resource_coordinator |
| OLD | NEW |