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

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

Issue 2483003004: Make purge-and-suspend-time finch experiment parameter (Closed)
Patch Set: Make purge-and-suspend-time=0 immediately purge+suspend. Instead default value is 30min. Created 4 years 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
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | chrome/common/chrome_switches.h » ('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/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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (monitor) { 214 if (monitor) {
215 memory_pressure_listener_.reset(new base::MemoryPressureListener( 215 memory_pressure_listener_.reset(new base::MemoryPressureListener(
216 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this)))); 216 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this))));
217 base::MemoryPressureListener::MemoryPressureLevel level = 217 base::MemoryPressureListener::MemoryPressureLevel level =
218 monitor->GetCurrentPressureLevel(); 218 monitor->GetCurrentPressureLevel();
219 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 219 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
220 OnMemoryPressure(level); 220 OnMemoryPressure(level);
221 } 221 }
222 } 222 }
223 #endif 223 #endif
224 // purge-and-suspend param is used for Purge+Suspend finch experiment
225 // in the following way:
226 // https://docs.google.com/document/d/1hPHkKtXXBTlsZx9s-9U17XC-ofEIzPo9FYbBEc7 PPbk/edit?usp=sharing
227 std::string purge_and_suspend_time = variations::GetVariationParamValue(
228 "PurgeAndSuspend", "purge-and-suspend-time");
229 unsigned time_to_first_suspension_sec;
230 if (purge_and_suspend_time.empty() ||
231 !base::StringToUint(purge_and_suspend_time,
232 &time_to_first_suspension_sec))
233 time_to_first_suspension_sec = 108000;
Wez 2017/02/15 22:22:52 There doesn't seem to be any explanation here, or
234 time_to_first_suspension_ =
235 base::TimeDelta::FromSeconds(time_to_first_suspension_sec);
224 } 236 }
225 237
226 void TabManager::Stop() { 238 void TabManager::Stop() {
227 update_timer_.Stop(); 239 update_timer_.Stop();
228 recent_tab_discard_timer_.Stop(); 240 recent_tab_discard_timer_.Stop();
229 memory_pressure_listener_.reset(); 241 memory_pressure_listener_.reset();
230 } 242 }
231 243
232 TabStatsList TabManager::GetTabStats() { 244 TabStatsList TabManager::GetTabStats() {
233 TabStatsList stats_list(GetUnsortedTabStats()); 245 TabStatsList stats_list(GetUnsortedTabStats());
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 break; 736 break;
725 case SUSPENDED: 737 case SUSPENDED:
726 if (time_passed > kDurationOfRendererSuspension) 738 if (time_passed > kDurationOfRendererSuspension)
727 return RESUMED; 739 return RESUMED;
728 break; 740 break;
729 } 741 }
730 return state; 742 return state;
731 } 743 }
732 744
733 void TabManager::PurgeAndSuspendBackgroundedTabs() { 745 void TabManager::PurgeAndSuspendBackgroundedTabs() {
734 const base::CommandLine& command_line =
735 *base::CommandLine::ForCurrentProcess();
736 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime))
737 return;
738 int purge_and_suspend_time = 0;
739 if (!base::StringToInt(
740 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime),
741 &purge_and_suspend_time)) {
742 return;
743 }
744 if (purge_and_suspend_time <= 0)
745 return;
746 base::TimeTicks current_time = NowTicks(); 746 base::TimeTicks current_time = NowTicks();
747 base::TimeDelta time_to_first_suspension =
748 base::TimeDelta::FromSeconds(purge_and_suspend_time);
749 auto tab_stats = GetUnsortedTabStats(); 747 auto tab_stats = GetUnsortedTabStats();
750 for (auto& tab : tab_stats) { 748 for (auto& tab : tab_stats) {
751 if (!tab.render_process_host->IsProcessBackgrounded()) 749 if (!tab.render_process_host->IsProcessBackgrounded())
752 continue; 750 continue;
753 if (!CanSuspendBackgroundedRenderer(tab.child_process_host_id)) 751 if (!CanSuspendBackgroundedRenderer(tab.child_process_host_id))
754 continue; 752 continue;
755 753
756 WebContents* content = GetWebContentsById(tab.tab_contents_id); 754 WebContents* content = GetWebContentsById(tab.tab_contents_id);
757 if (!content) 755 if (!content)
758 continue; 756 continue;
759 757
760 PurgeAndSuspendState current_state = 758 PurgeAndSuspendState current_state =
761 GetWebContentsData(content)->GetPurgeAndSuspendState(); 759 GetWebContentsData(content)->GetPurgeAndSuspendState();
762 // If the tab's purge-and-suspend state is not RUNNING, the tab should be 760 // If the tab's purge-and-suspend state is not RUNNING, the tab should be
763 // backgrounded. Since tab.last_hidden is updated everytime the tab is 761 // backgrounded. Since tab.last_hidden is updated everytime the tab is
764 // hidden, we should see tab.last_hidden < last_modified_time. 762 // hidden, we should see tab.last_hidden < last_modified_time.
765 DCHECK(current_state == RUNNING || 763 DCHECK(current_state == RUNNING ||
766 tab.last_hidden < 764 tab.last_hidden <
767 GetWebContentsData(content)->LastPurgeAndSuspendModifiedTime()); 765 GetWebContentsData(content)->LastPurgeAndSuspendModifiedTime());
768 PurgeAndSuspendState next_state = GetNextPurgeAndSuspendState( 766 PurgeAndSuspendState next_state = GetNextPurgeAndSuspendState(
769 content, current_time, time_to_first_suspension); 767 content, current_time, time_to_first_suspension_);
770 if (current_state == next_state) 768 if (current_state == next_state)
771 continue; 769 continue;
772 770
773 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without 771 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without
774 // timers for simplicity, so PurgeAndSuspend is called even after the 772 // timers for simplicity, so PurgeAndSuspend is called even after the
775 // renderer is purged and suspended once. This should be replaced with 773 // renderer is purged and suspended once. This should be replaced with
776 // timers if we want necessary and sufficient signals. 774 // timers if we want necessary and sufficient signals.
777 GetWebContentsData(content)->SetPurgeAndSuspendState(next_state); 775 GetWebContentsData(content)->SetPurgeAndSuspendState(next_state);
778 switch (next_state) { 776 switch (next_state) {
779 case SUSPENDED: 777 case SUSPENDED:
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 // platform. 1028 // platform.
1031 std::string allow_multiple_discards = variations::GetVariationParamValue( 1029 std::string allow_multiple_discards = variations::GetVariationParamValue(
1032 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); 1030 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards");
1033 return (allow_multiple_discards != "true"); 1031 return (allow_multiple_discards != "true");
1034 #else 1032 #else
1035 return false; 1033 return false;
1036 #endif 1034 #endif
1037 } 1035 }
1038 1036
1039 } // namespace memory 1037 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698