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

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

Issue 2153943002: Implementing TabManager extensions API Discard Function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reset protection time Created 4 years, 4 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
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | chrome/common/extensions/api/tabs.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 int index = FindTabStripModelById(target_web_contents_id, &model); 287 int index = FindTabStripModelById(target_web_contents_id, &model);
288 288
289 if (index == -1) 289 if (index == -1)
290 return nullptr; 290 return nullptr;
291 291
292 VLOG(1) << "Discarding tab " << index << " id " << target_web_contents_id; 292 VLOG(1) << "Discarding tab " << index << " id " << target_web_contents_id;
293 293
294 return DiscardWebContentsAt(index, model); 294 return DiscardWebContentsAt(index, model);
295 } 295 }
296 296
297 WebContents* TabManager::DiscardTabByExtension(content::WebContents* contents) {
298 if (contents)
299 return DiscardTabById(reinterpret_cast<int64_t>(contents));
300
301 return DiscardTabImpl();
302 }
303
297 void TabManager::LogMemoryAndDiscardTab() { 304 void TabManager::LogMemoryAndDiscardTab() {
298 LogMemory("Tab Discards Memory details", 305 LogMemory("Tab Discards Memory details",
299 base::Bind(&TabManager::PurgeMemoryAndDiscardTab)); 306 base::Bind(&TabManager::PurgeMemoryAndDiscardTab));
300 } 307 }
301 308
302 void TabManager::LogMemory(const std::string& title, 309 void TabManager::LogMemory(const std::string& title,
303 const base::Closure& callback) { 310 const base::Closure& callback) {
304 DCHECK_CURRENTLY_ON(BrowserThread::UI); 311 DCHECK_CURRENTLY_ON(BrowserThread::UI);
305 OomMemoryDetails::Log(title, callback); 312 OomMemoryDetails::Log(title, callback);
306 } 313 }
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 task_runner_->PostDelayedTask( 841 task_runner_->PostDelayedTask(
835 FROM_HERE, 842 FROM_HERE,
836 base::Bind(&TabManager::DoChildProcessDispatch, 843 base::Bind(&TabManager::DoChildProcessDispatch,
837 weak_ptr_factory_.GetWeakPtr()), 844 weak_ptr_factory_.GetWeakPtr()),
838 base::TimeDelta::FromSeconds(kRendererNotificationDelayInSeconds)); 845 base::TimeDelta::FromSeconds(kRendererNotificationDelayInSeconds));
839 } 846 }
840 847
841 // TODO(jamescook): This should consider tabs with references to other tabs, 848 // TODO(jamescook): This should consider tabs with references to other tabs,
842 // such as tabs created with JavaScript window.open(). Potentially consider 849 // such as tabs created with JavaScript window.open(). Potentially consider
843 // discarding the entire set together, or use that in the priority computation. 850 // discarding the entire set together, or use that in the priority computation.
844 bool TabManager::DiscardTabImpl() { 851 content::WebContents* TabManager::DiscardTabImpl() {
845 DCHECK_CURRENTLY_ON(BrowserThread::UI); 852 DCHECK_CURRENTLY_ON(BrowserThread::UI);
846 TabStatsList stats = GetTabStats(); 853 TabStatsList stats = GetTabStats();
847 854
848 if (stats.empty()) 855 if (stats.empty())
849 return false; 856 return nullptr;
850 // Loop until a non-discarded tab to kill is found. 857 // Loop until a non-discarded tab to kill is found.
851 for (TabStatsList::const_reverse_iterator stats_rit = stats.rbegin(); 858 for (TabStatsList::const_reverse_iterator stats_rit = stats.rbegin();
852 stats_rit != stats.rend(); ++stats_rit) { 859 stats_rit != stats.rend(); ++stats_rit) {
853 int64_t least_important_tab_id = stats_rit->tab_contents_id; 860 int64_t least_important_tab_id = stats_rit->tab_contents_id;
854 if (CanDiscardTab(least_important_tab_id) && 861 if (CanDiscardTab(least_important_tab_id)) {
855 DiscardTabById(least_important_tab_id)) 862 WebContents* new_contents = DiscardTabById(least_important_tab_id);
856 return true; 863 if (new_contents)
864 return new_contents;
865 }
857 } 866 }
858 return false; 867 return nullptr;
859 } 868 }
860 869
861 // Check the variation parameter to see if a tab can be discarded only once or 870 // Check the variation parameter to see if a tab can be discarded only once or
862 // multiple times. 871 // multiple times.
863 // Default is to only discard once per tab. 872 // Default is to only discard once per tab.
864 bool TabManager::CanOnlyDiscardOnce() { 873 bool TabManager::CanOnlyDiscardOnce() {
865 #if defined(OS_WIN) || defined(OS_MACOSX) 874 #if defined(OS_WIN) || defined(OS_MACOSX)
866 // On Windows and MacOS, default to discarding only once unless otherwise 875 // On Windows and MacOS, default to discarding only once unless otherwise
867 // specified by the variation parameter. 876 // specified by the variation parameter.
868 // TODO(georgesak): Add Linux when automatic discarding is enabled for that 877 // TODO(georgesak): Add Linux when automatic discarding is enabled for that
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 void TabManager::RemoveObserver(TabManagerObserver* observer) { 917 void TabManager::RemoveObserver(TabManagerObserver* observer) {
909 observers_.RemoveObserver(observer); 918 observers_.RemoveObserver(observer);
910 } 919 }
911 920
912 void TabManager::OnDiscardedStateChange(content::WebContents* contents, 921 void TabManager::OnDiscardedStateChange(content::WebContents* contents,
913 bool is_discarded) { 922 bool is_discarded) {
914 FOR_EACH_OBSERVER(TabManagerObserver, observers_, 923 FOR_EACH_OBSERVER(TabManagerObserver, observers_,
915 OnDiscardedStateChange(contents, is_discarded)); 924 OnDiscardedStateChange(contents, is_discarded));
916 } 925 }
917 926
927 void TabManager::set_minimum_protection_time_for_tests(
928 base::TimeDelta minimum_protection_time) {
929 minimum_protection_time_ = minimum_protection_time;
930 }
931
918 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents, 932 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents,
919 bool is_auto_discardable) { 933 bool is_auto_discardable) {
920 FOR_EACH_OBSERVER( 934 FOR_EACH_OBSERVER(
921 TabManagerObserver, observers_, 935 TabManagerObserver, observers_,
922 OnAutoDiscardableStateChange(contents, is_auto_discardable)); 936 OnAutoDiscardableStateChange(contents, is_auto_discardable));
923 } 937 }
924 938
925 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const { 939 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const {
926 return GetWebContentsData(contents)->IsAutoDiscardable(); 940 return GetWebContentsData(contents)->IsAutoDiscardable();
927 } 941 }
928 942
929 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents, 943 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents,
930 bool state) { 944 bool state) {
931 GetWebContentsData(contents)->SetAutoDiscardableState(state); 945 GetWebContentsData(contents)->SetAutoDiscardableState(state);
932 } 946 }
933 947
934 } // namespace memory 948 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | chrome/common/extensions/api/tabs.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698