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/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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 // Set up default callbacks. These may be overridden post-construction as | 152 // Set up default callbacks. These may be overridden post-construction as |
| 153 // testing seams. | 153 // testing seams. |
| 154 get_current_pressure_level_ = base::Bind(&GetCurrentPressureLevel); | 154 get_current_pressure_level_ = base::Bind(&GetCurrentPressureLevel); |
| 155 notify_renderer_process_ = base::Bind(&NotifyRendererProcess); | 155 notify_renderer_process_ = base::Bind(&NotifyRendererProcess); |
| 156 } | 156 } |
| 157 | 157 |
| 158 TabManager::~TabManager() { | 158 TabManager::~TabManager() { |
| 159 Stop(); | 159 Stop(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Check the variation parameter to see if a tab be discarded more than once. | |
| 163 // Default is to only discard once per tab. | |
| 164 bool TabManager::CheckMultipleDiscards() { | |
| 165 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 166 std::string allow_multiple_discards = variations::GetVariationParamValue( | |
| 167 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | |
| 168 return (allow_multiple_discards == "true"); | |
| 169 | |
| 170 #elif defined(OS_CHROMEOS) | |
| 171 // On Chrome OS, tab manager is always started and tabs can be discarded more | |
| 172 // than once. | |
| 173 return false; | |
| 174 #endif | |
|
Georges Khalil
2016/05/16 18:41:22
Let's simplify this. For CHROMEOS, always return f
Anderson Silva
2016/05/16 19:39:06
I've also thought about that. I didn't do it thoug
| |
| 175 } | |
| 176 | |
| 162 void TabManager::Start() { | 177 void TabManager::Start() { |
| 163 #if defined(OS_WIN) || defined(OS_MACOSX) | 178 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 164 // If the feature is not enabled, do nothing. | 179 // If the feature is not enabled, do nothing. |
| 165 if (!base::FeatureList::IsEnabled(features::kAutomaticTabDiscarding)) | 180 if (!base::FeatureList::IsEnabled(features::kAutomaticTabDiscarding)) |
| 166 return; | 181 return; |
| 167 | 182 |
| 168 // Check the variation parameter to see if a tab be discarded more than once. | |
| 169 // Default is to only discard once per tab. | |
| 170 std::string allow_multiple_discards = variations::GetVariationParamValue( | |
| 171 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | |
| 172 if (allow_multiple_discards == "true") | |
| 173 discard_once_ = true; | |
| 174 else | |
| 175 discard_once_ = false; | |
| 176 | |
| 177 // Check the variation parameter to see if a tab is to be protected for an | 183 // Check the variation parameter to see if a tab is to be protected for an |
| 178 // amount of time after being backgrounded. The value is in seconds. | 184 // amount of time after being backgrounded. The value is in seconds. |
| 179 std::string minimum_protection_time_string = | 185 std::string minimum_protection_time_string = |
| 180 variations::GetVariationParamValue(features::kAutomaticTabDiscarding.name, | 186 variations::GetVariationParamValue(features::kAutomaticTabDiscarding.name, |
| 181 "MinimumProtectionTime"); | 187 "MinimumProtectionTime"); |
| 182 if (!minimum_protection_time_string.empty()) { | 188 if (!minimum_protection_time_string.empty()) { |
| 183 unsigned int minimum_protection_time_seconds = 0; | 189 unsigned int minimum_protection_time_seconds = 0; |
| 184 if (base::StringToUint(minimum_protection_time_string, | 190 if (base::StringToUint(minimum_protection_time_string, |
| 185 &minimum_protection_time_seconds)) { | 191 &minimum_protection_time_seconds)) { |
| 186 if (minimum_protection_time_seconds > 0) | 192 if (minimum_protection_time_seconds > 0) |
| 187 minimum_protection_time_ = | 193 minimum_protection_time_ = |
| 188 base::TimeDelta::FromSeconds(minimum_protection_time_seconds); | 194 base::TimeDelta::FromSeconds(minimum_protection_time_seconds); |
| 189 } | 195 } |
| 190 } | 196 } |
| 197 #endif | |
|
Georges Khalil
2016/05/16 18:41:22
Pasted by mistake?
Anderson Silva
2016/05/16 19:39:06
No, that's actually because of the #if defined WIN
| |
| 191 | 198 |
| 192 #elif defined(OS_CHROMEOS) | 199 // Check if multiple discards are allowed. |
| 193 // On Chrome OS, tab manager is always started and tabs can be discarded more | 200 discard_once_ = CheckMultipleDiscards(); |
|
Georges Khalil
2016/05/16 18:41:22
The logic here is inverted, as discard_once_ would
Anderson Silva
2016/05/16 19:39:06
You're right. But then I think we might have an is
| |
| 194 // than once. | |
| 195 discard_once_ = false; | |
| 196 #endif | |
| 197 | 201 |
| 198 if (!update_timer_.IsRunning()) { | 202 if (!update_timer_.IsRunning()) { |
| 199 update_timer_.Start(FROM_HERE, | 203 update_timer_.Start(FROM_HERE, |
| 200 TimeDelta::FromSeconds(kAdjustmentIntervalSeconds), | 204 TimeDelta::FromSeconds(kAdjustmentIntervalSeconds), |
| 201 this, &TabManager::UpdateTimerCallback); | 205 this, &TabManager::UpdateTimerCallback); |
| 202 } | 206 } |
| 203 | 207 |
| 204 // MemoryPressureMonitor is not implemented on Linux so far and tabs are never | 208 // MemoryPressureMonitor is not implemented on Linux so far and tabs are never |
| 205 // discarded. | 209 // discarded. |
| 206 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 210 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) | 558 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
| 555 return; | 559 return; |
| 556 int purge_and_suspend_time = 0; | 560 int purge_and_suspend_time = 0; |
| 557 if (!base::StringToInt( | 561 if (!base::StringToInt( |
| 558 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), | 562 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
| 559 &purge_and_suspend_time)) { | 563 &purge_and_suspend_time)) { |
| 560 return; | 564 return; |
| 561 } | 565 } |
| 562 if (purge_and_suspend_time <= 0) | 566 if (purge_and_suspend_time <= 0) |
| 563 return; | 567 return; |
| 564 auto purge_and_suspend_time_threshold = NowTicks() - | 568 auto purge_and_suspend_time_threshold = |
| 565 base::TimeDelta::FromSeconds(purge_and_suspend_time); | 569 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| 566 auto tab_stats = GetUnsortedTabStats(); | 570 auto tab_stats = GetUnsortedTabStats(); |
| 567 for (auto& tab : tab_stats) { | 571 for (auto& tab : tab_stats) { |
| 568 if (!tab.render_process_host->IsProcessBackgrounded()) | 572 if (!tab.render_process_host->IsProcessBackgrounded()) |
| 569 continue; | 573 continue; |
| 570 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 574 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| 571 // timers for simplicity, so PurgeAndSuspend is called even after the | 575 // timers for simplicity, so PurgeAndSuspend is called even after the |
| 572 // renderer is purged and suspended once. This should be replaced with | 576 // renderer is purged and suspended once. This should be replaced with |
| 573 // timers if we want necessary and sufficient signals. | 577 // timers if we want necessary and sufficient signals. |
| 574 if (tab.last_active > purge_and_suspend_time_threshold) | 578 if (tab.last_active > purge_and_suspend_time_threshold) |
| 575 continue; | 579 continue; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 } | 882 } |
| 879 } else { | 883 } else { |
| 880 // The code here can only be tested under a full browser test. | 884 // The code here can only be tested under a full browser test. |
| 881 AddTabStats(&stats_list); | 885 AddTabStats(&stats_list); |
| 882 } | 886 } |
| 883 | 887 |
| 884 return stats_list; | 888 return stats_list; |
| 885 } | 889 } |
| 886 | 890 |
| 887 } // namespace memory | 891 } // namespace memory |
| OLD | NEW |