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..4901cd77ccdc41c88f46d6bb59b3c71c81cc49fd 100644 |
| --- a/chrome/browser/memory/tab_manager.cc |
| +++ b/chrome/browser/memory/tab_manager.cc |
| @@ -670,6 +670,36 @@ void TabManager::UpdateTimerCallback() { |
| PurgeAndSuspendBackgroundedTabs(); |
| } |
| +bool TabManager::CanPurgeAndSuspendBackgroundedTab( |
| + int64_t target_web_contents_id) const { |
| + TabStripModel* model; |
| + int idx = FindTabStripModelById(target_web_contents_id, &model); |
| + if (idx == -1) |
| + return false; |
| + |
| + WebContents* web_contents = model->GetWebContentsAt(idx); |
| + |
| + // Do not suspend tabs that are playing either playing audio or accessing the |
| + // microphone or camera as it's too distruptive to the user experience. |
| + if (IsMediaTab(web_contents)) |
|
chrisha
2016/10/04 21:52:41
This is the only reason I think we shouldn't suspe
tasak
2016/10/05 05:28:46
I see.
Done.
|
| + return false; |
| + |
| + // Do not discard a recently used tab. |
|
Georges Khalil
2016/10/04 13:28:55
nit: s/discard/suspend.
chrisha
2016/10/04 21:52:41
I don't think this is necessary. We should feel fr
tasak
2016/10/05 05:28:46
Done.
|
| + if (minimum_protection_time_.InSeconds() > 0) { |
| + auto delta = |
| + NowTicks() - GetWebContentsData(web_contents)->LastInactiveTime(); |
| + if (delta < minimum_protection_time_) |
| + return false; |
|
Georges Khalil
2016/10/04 13:28:55
nit: Let's move this logic to a function, instead
|
| + } |
| + |
| + // Do not purge and suspend a tab that was explicitly disallowed to. |
| + // Note: reused tab discarding logic. |
| + if (!IsTabAutoDiscardable(web_contents)) |
|
chrisha
2016/10/04 21:52:41
Discarding logic shouldn't affect suspending, IMO.
tasak
2016/10/05 05:28:46
I see.
If needed, I will update src/chrome/common/
|
| + return false; |
| + |
| + return true; |
| +} |
| + |
| void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| const base::CommandLine& command_line = |
| *base::CommandLine::ForCurrentProcess(); |
| @@ -695,6 +725,8 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| // timers if we want necessary and sufficient signals. |
| if (tab.last_active > purge_and_suspend_time_threshold) |
| continue; |
| + if (!CanPurgeAndSuspendBackgroundedTab(tab.tab_contents_id)) |
| + continue; |
| tab.render_process_host->PurgeAndSuspend(); |
| } |
| } |