| Index: chrome/browser/memory/tab_manager.cc
|
| diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc
|
| index 18289a83c29d97f3c242d5407dfd0713c49338d7..e544137770f53a4f75b4fc29102aa403f1569552 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"
|
| @@ -487,7 +488,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;
|
| @@ -544,6 +545,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)
|
| + continue;
|
| + tab.render_process_host->PurgeAndSuspend();
|
| + }
|
| }
|
|
|
| bool TabManager::CanDiscardTab(int64_t target_web_contents_id) const {
|
|
|