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 582b2e667099f6fa0085f6721c4b9c69a37709c8..b27b133342199746130ba04e69fc7e866c4baed6 100644 |
| --- a/chrome/browser/memory/tab_manager.cc |
| +++ b/chrome/browser/memory/tab_manager.cc |
| @@ -84,6 +84,14 @@ const int kRecentTabDiscardIntervalSeconds = 60; |
| // machine was suspended and correct the timing statistics. |
| const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4; |
| +// If a backgrounded renderer is kept backgrounded during this time after |
| +// suspended, resume the renderer to avoid breaking web. |
| +const int kResumeSuspendedRendererMinutes = 20; |
|
haraken
2016/10/06 07:29:05
I'd say 20 seconds would be too short.
tasak
2016/10/06 08:02:06
2min.
Done.
|
| + |
| +// After resuming and running a backgrounded rendererr for this period, |
|
haraken
2016/10/06 07:29:05
renderer
tasak
2016/10/06 08:02:06
Done.
|
| +// the renderer is purged and suspended again. |
| +const int kSuspendResumedRendererMinutes = 2; |
|
haraken
2016/10/06 07:29:05
Would it be hard to run the renderer until it has
tasak
2016/10/06 08:02:06
I think, it is difficult to ask task runners in ta
|
| + |
| // The time during which a tab is protected from discarding after it stops being |
| // audible. |
| const int kAudioProtectionTimeSeconds = 60; |
| @@ -683,8 +691,9 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| } |
| if (purge_and_suspend_time <= 0) |
| return; |
| + base::TimeTicks current_time = NowTicks(); |
| auto purge_and_suspend_time_threshold = |
| - NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| + current_time - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| auto tab_stats = GetUnsortedTabStats(); |
| for (auto& tab : tab_stats) { |
| if (!tab.render_process_host->IsProcessBackgrounded()) |
| @@ -695,7 +704,26 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| // timers if we want necessary and sufficient signals. |
| if (tab.last_active > purge_and_suspend_time_threshold) |
| continue; |
| - tab.render_process_host->PurgeAndSuspend(); |
| + |
| + auto last_purged_and_suspended_time = |
| + tab.render_process_host->GetLastPurgedAndSuspendedTime(); |
| + auto last_resumed_time = |
| + tab.render_process_host->GetLastResumedInBackgroundTime(); |
| + |
| + if (last_purged_and_suspended_time < tab.last_active || |
| + (last_resumed_time > last_purged_and_suspended_time && |
| + last_purged_and_suspended_time > tab.last_active && |
| + ((current_time - last_resumed_time) > |
| + base::TimeDelta::FromMinutes(kSuspendResumedRendererMinutes)))) { |
| + tab.render_process_host->PurgeAndSuspend(); |
| + if (!task_runner_.get()) |
| + task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| + } else { |
| + auto delta = current_time - last_purged_and_suspended_time; |
| + if (last_resumed_time < last_purged_and_suspended_time && |
| + delta > base::TimeDelta::FromMinutes(kResumeSuspendedRendererMinutes)) |
| + tab.render_process_host->Resume(); |
| + } |
| } |
| } |