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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 std::string purge_and_suspend_time = variations::GetVariationParamValue( | |
|
chrisha
2016/11/24 17:13:09
Should we have a default time that this is initial
tasak
2016/11/25 01:15:24
As far as I understand, base::TimeDelta() initiali
chrisha
2016/11/29 14:13:57
Okay, that makes sense. I was thinking that there'
tasak
2016/12/02 02:49:24
Yes... currently the zero means that the purge+sus
| |
| 225 "PurgeAndSuspend", "purge-and-suspend-time"); | |
| 226 if (!purge_and_suspend_time.empty()) { | |
| 227 int time_to_first_suspension_sec = 0; | |
| 228 if (base::StringToInt(purge_and_suspend_time, | |
| 229 &time_to_first_suspension_sec)) { | |
| 230 if (time_to_first_suspension_sec > 0) | |
| 231 time_to_first_suspension_ = | |
| 232 base::TimeDelta::FromSeconds(time_to_first_suspension_sec); | |
| 233 } | |
| 234 } | |
| 224 } | 235 } |
| 225 | 236 |
| 226 void TabManager::Stop() { | 237 void TabManager::Stop() { |
| 227 update_timer_.Stop(); | 238 update_timer_.Stop(); |
| 228 recent_tab_discard_timer_.Stop(); | 239 recent_tab_discard_timer_.Stop(); |
| 229 memory_pressure_listener_.reset(); | 240 memory_pressure_listener_.reset(); |
| 230 } | 241 } |
| 231 | 242 |
| 232 TabStatsList TabManager::GetTabStats() { | 243 TabStatsList TabManager::GetTabStats() { |
| 233 TabStatsList stats_list(GetUnsortedTabStats()); | 244 TabStatsList stats_list(GetUnsortedTabStats()); |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 break; | 735 break; |
| 725 case SUSPENDED: | 736 case SUSPENDED: |
| 726 if (time_passed > kDurationOfRendererSuspension) | 737 if (time_passed > kDurationOfRendererSuspension) |
| 727 return RESUMED; | 738 return RESUMED; |
| 728 break; | 739 break; |
| 729 } | 740 } |
| 730 return state; | 741 return state; |
| 731 } | 742 } |
| 732 | 743 |
| 733 void TabManager::PurgeAndSuspendBackgroundedTabs() { | 744 void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| 734 const base::CommandLine& command_line = | 745 if (time_to_first_suspension_.InSeconds() <= 0) |
|
chrisha
2016/11/24 17:13:09
Do we need this check? This function simply should
tasak
2016/11/25 01:15:24
I would like to confirm. You mean, we should check
tasak
2016/11/25 01:19:44
So my first patch is trying to always record B.
I
chrisha
2016/11/29 14:13:57
I'm not sure I follow this entire chain of logic?
tasak
2016/12/02 02:49:24
I see.... I'm trying to keep the existing behavior
| |
| 735 *base::CommandLine::ForCurrentProcess(); | |
| 736 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) | |
| 737 return; | 746 return; |
| 738 int purge_and_suspend_time = 0; | 747 |
| 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(); | 748 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(); | 749 auto tab_stats = GetUnsortedTabStats(); |
| 750 for (auto& tab : tab_stats) { | 750 for (auto& tab : tab_stats) { |
| 751 if (!tab.render_process_host->IsProcessBackgrounded()) | 751 if (!tab.render_process_host->IsProcessBackgrounded()) |
| 752 continue; | 752 continue; |
| 753 if (!CanSuspendBackgroundedRenderer(tab.child_process_host_id)) | 753 if (!CanSuspendBackgroundedRenderer(tab.child_process_host_id)) |
| 754 continue; | 754 continue; |
| 755 | 755 |
| 756 WebContents* content = GetWebContentsById(tab.tab_contents_id); | 756 WebContents* content = GetWebContentsById(tab.tab_contents_id); |
| 757 if (!content) | 757 if (!content) |
| 758 continue; | 758 continue; |
| 759 | 759 |
| 760 PurgeAndSuspendState current_state = | 760 PurgeAndSuspendState current_state = |
| 761 GetWebContentsData(content)->GetPurgeAndSuspendState(); | 761 GetWebContentsData(content)->GetPurgeAndSuspendState(); |
| 762 // If the tab's purge-and-suspend state is not RUNNING, the tab should be | 762 // 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 | 763 // backgrounded. Since tab.last_hidden is updated everytime the tab is |
| 764 // hidden, we should see tab.last_hidden < last_modified_time. | 764 // hidden, we should see tab.last_hidden < last_modified_time. |
| 765 DCHECK(current_state == RUNNING || | 765 DCHECK(current_state == RUNNING || |
| 766 tab.last_hidden < | 766 tab.last_hidden < |
| 767 GetWebContentsData(content)->LastPurgeAndSuspendModifiedTime()); | 767 GetWebContentsData(content)->LastPurgeAndSuspendModifiedTime()); |
| 768 PurgeAndSuspendState next_state = GetNextPurgeAndSuspendState( | 768 PurgeAndSuspendState next_state = GetNextPurgeAndSuspendState( |
| 769 content, current_time, time_to_first_suspension); | 769 content, current_time, time_to_first_suspension_); |
| 770 if (current_state == next_state) | 770 if (current_state == next_state) |
| 771 continue; | 771 continue; |
| 772 | 772 |
| 773 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 773 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| 774 // timers for simplicity, so PurgeAndSuspend is called even after the | 774 // timers for simplicity, so PurgeAndSuspend is called even after the |
| 775 // renderer is purged and suspended once. This should be replaced with | 775 // renderer is purged and suspended once. This should be replaced with |
| 776 // timers if we want necessary and sufficient signals. | 776 // timers if we want necessary and sufficient signals. |
| 777 GetWebContentsData(content)->SetPurgeAndSuspendState(next_state); | 777 GetWebContentsData(content)->SetPurgeAndSuspendState(next_state); |
| 778 switch (next_state) { | 778 switch (next_state) { |
| 779 case SUSPENDED: | 779 case SUSPENDED: |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 // platform. | 1030 // platform. |
| 1031 std::string allow_multiple_discards = variations::GetVariationParamValue( | 1031 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 1032 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 1032 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 1033 return (allow_multiple_discards != "true"); | 1033 return (allow_multiple_discards != "true"); |
| 1034 #else | 1034 #else |
| 1035 return false; | 1035 return false; |
| 1036 #endif | 1036 #endif |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 } // namespace memory | 1039 } // namespace memory |
| OLD | NEW |