Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: chrome/browser/memory/tab_manager.cc

Issue 2387603003: Resume a backgrounded renderer that was purged and suspended (Closed)
Patch Set: Add Resume Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // For each period of this length record a statistic to indicate whether or not 77 // For each period of this length record a statistic to indicate whether or not
78 // the user experienced a low memory event. If this interval is changed, 78 // the user experienced a low memory event. If this interval is changed,
79 // Tabs.Discard.DiscardInLastMinute must be replaced with a new statistic. 79 // Tabs.Discard.DiscardInLastMinute must be replaced with a new statistic.
80 const int kRecentTabDiscardIntervalSeconds = 60; 80 const int kRecentTabDiscardIntervalSeconds = 60;
81 #endif 81 #endif
82 82
83 // If there has been no priority adjustment in this interval, assume the 83 // If there has been no priority adjustment in this interval, assume the
84 // machine was suspended and correct the timing statistics. 84 // machine was suspended and correct the timing statistics.
85 const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4; 85 const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4;
86 86
87 // If a backgrounded renderer is kept backgrounded during this time after
88 // suspended, resume the renderer to avoid breaking web.
89 const int kResumeSuspendedRendererMinutes = 20;
90
91 // After resuming and running a backgrounded rendererr for this period,
92 // the renderer is purged and suspended again.
93 const int kSuspendResumedRendererMinutes = 2;
94
87 // The time during which a tab is protected from discarding after it stops being 95 // The time during which a tab is protected from discarding after it stops being
88 // audible. 96 // audible.
89 const int kAudioProtectionTimeSeconds = 60; 97 const int kAudioProtectionTimeSeconds = 60;
90 98
91 int FindTabStripModelById(int64_t target_web_contents_id, 99 int FindTabStripModelById(int64_t target_web_contents_id,
92 TabStripModel** model) { 100 TabStripModel** model) {
93 DCHECK(model); 101 DCHECK(model);
94 for (auto* browser : *BrowserList::GetInstance()) { 102 for (auto* browser : *BrowserList::GetInstance()) {
95 TabStripModel* local_model = browser->tab_strip_model(); 103 TabStripModel* local_model = browser->tab_strip_model();
96 for (int idx = 0; idx < local_model->count(); idx++) { 104 for (int idx = 0; idx < local_model->count(); idx++) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) 684 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime))
677 return; 685 return;
678 int purge_and_suspend_time = 0; 686 int purge_and_suspend_time = 0;
679 if (!base::StringToInt( 687 if (!base::StringToInt(
680 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), 688 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime),
681 &purge_and_suspend_time)) { 689 &purge_and_suspend_time)) {
682 return; 690 return;
683 } 691 }
684 if (purge_and_suspend_time <= 0) 692 if (purge_and_suspend_time <= 0)
685 return; 693 return;
694 base::TimeTicks current_time = NowTicks();
686 auto purge_and_suspend_time_threshold = 695 auto purge_and_suspend_time_threshold =
687 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); 696 current_time - base::TimeDelta::FromSeconds(purge_and_suspend_time);
688 auto tab_stats = GetUnsortedTabStats(); 697 auto tab_stats = GetUnsortedTabStats();
689 for (auto& tab : tab_stats) { 698 for (auto& tab : tab_stats) {
690 if (!tab.render_process_host->IsProcessBackgrounded()) 699 if (!tab.render_process_host->IsProcessBackgrounded())
691 continue; 700 continue;
692 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without 701 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without
693 // timers for simplicity, so PurgeAndSuspend is called even after the 702 // timers for simplicity, so PurgeAndSuspend is called even after the
694 // renderer is purged and suspended once. This should be replaced with 703 // renderer is purged and suspended once. This should be replaced with
695 // timers if we want necessary and sufficient signals. 704 // timers if we want necessary and sufficient signals.
696 if (tab.last_active > purge_and_suspend_time_threshold) 705 if (tab.last_active > purge_and_suspend_time_threshold)
697 continue; 706 continue;
698 tab.render_process_host->PurgeAndSuspend(); 707
708 auto last_purged_and_suspended_time =
709 tab.render_process_host->GetLastPurgedAndSuspendedTime();
710 auto last_resumed_time = tab.render_process_host->GetLastResumedTime();
711
712 if (last_purged_and_suspended_time < tab.last_active ||
713 (last_resumed_time > last_purged_and_suspended_time &&
714 last_purged_and_suspended_time > tab.last_active &&
715 ((current_time - last_resumed_time) >
716 base::TimeDelta::FromMinutes(kSuspendResumedRendererMinutes)))) {
717 tab.render_process_host->PurgeAndSuspend();
718 if (!task_runner_.get())
719 task_runner_ = base::ThreadTaskRunnerHandle::Get();
720 } else {
721 auto delta = current_time - last_purged_and_suspended_time;
722 if (last_resumed_time < last_purged_and_suspended_time &&
723 delta > base::TimeDelta::FromMinutes(kResumeSuspendedRendererMinutes))
724 tab.render_process_host->Resume();
725 }
699 } 726 }
700 } 727 }
701 728
702 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { 729 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) {
703 // Can't discard active index. 730 // Can't discard active index.
704 if (model->active_index() == index) 731 if (model->active_index() == index)
705 return nullptr; 732 return nullptr;
706 733
707 WebContents* old_contents = model->GetWebContentsAt(index); 734 WebContents* old_contents = model->GetWebContentsAt(index);
708 735
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 // platform. 967 // platform.
941 std::string allow_multiple_discards = variations::GetVariationParamValue( 968 std::string allow_multiple_discards = variations::GetVariationParamValue(
942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); 969 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards");
943 return (allow_multiple_discards != "true"); 970 return (allow_multiple_discards != "true");
944 #else 971 #else
945 return false; 972 return false;
946 #endif 973 #endif
947 } 974 }
948 975
949 } // namespace memory 976 } // namespace memory
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698