Chromium Code Reviews| Index: chrome/browser/memory/tab_manager.cc |
| diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc |
| index de82f58f8eaf193469a31e878cd0bef17af5b9ee..501d6d2d2bf349a918898c14ce3e49d329e52a21 100644 |
| --- a/chrome/browser/memory/tab_manager.cc |
| +++ b/chrome/browser/memory/tab_manager.cc |
| @@ -41,6 +41,7 @@ |
| #include "chrome/browser/ui/tabs/tab_utils.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "chrome/common/chrome_features.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "chrome/common/url_constants.h" |
| #include "components/metrics/system_memory_stats_recorder.h" |
| #include "components/variations/variations_associated_data.h" |
| @@ -484,7 +485,7 @@ void TabManager::AddTabStats(const TabStripModel* model, |
| bool is_app, |
| bool active_model, |
| TabStatsList* stats_list) { |
| -for (int i = 0; i < model->count(); i++) { |
| + for (int i = 0; i < model->count(); i++) { |
| WebContents* contents = model->GetWebContentsAt(i); |
| if (!contents->IsCrashed()) { |
| TabStats stats; |
| @@ -541,6 +542,36 @@ void TabManager::UpdateTimerCallback() { |
| // This starts the CrOS specific OOM adjustments in /proc/<pid>/oom_score_adj. |
| delegate_->AdjustOomPriorities(stats_list); |
| #endif |
| + |
| + PurgeAndSuspendBackgroundedTabs(); |
| +} |
| + |
| +void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| + const base::CommandLine& command_line = |
| + *base::CommandLine::ForCurrentProcess(); |
| + if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
| + return; |
| + int purge_and_suspend_time = 0; |
| + if (!base::StringToInt( |
| + command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
| + &purge_and_suspend_time)) { |
| + return; |
| + } |
| + if (purge_and_suspend_time <= 0) |
| + return; |
| + auto purge_and_suspend_time_delta = base::TimeDelta::FromSeconds( |
| + purge_and_suspend_time); |
| + auto tab_stats = GetUnsortedTabStats(); |
| + for (auto& tab : tab_stats) { |
| + if (!tab.render_process_host->IsProcessBackgrounded()) |
| + continue; |
| + // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| + // timers for simplicity, so PurgeAndSuspend is called even after the |
| + // renderer is purged and suspended once. |
| + if (NowTicks() - tab.last_active < purge_and_suspend_time_delta) |
|
dcheng
2016/05/10 04:49:53
Nit: maybe just get NowTicks() once outside the lo
hajimehoshi
2016/05/10 06:54:11
Done.
|
| + continue; |
| + tab.render_process_host->PurgeAndSuspend(); |
| + } |
| } |
| bool TabManager::CanDiscardTab(int64_t target_web_contents_id) const { |