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

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

Issue 2172893003: MC: WIP: dispatching notifications from browser to renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mc-4-dispatch-callback
Patch Set: Created 4 years, 5 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/BUILD.gn ('k') | components/memory_coordinator/browser/memory_coordinator.h » ('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 27 matching lines...) Expand all
38 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_list.h" 39 #include "chrome/browser/ui/browser_list.h"
40 #include "chrome/browser/ui/browser_window.h" 40 #include "chrome/browser/ui/browser_window.h"
41 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 41 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
42 #include "chrome/browser/ui/tabs/tab_strip_model.h" 42 #include "chrome/browser/ui/tabs/tab_strip_model.h"
43 #include "chrome/browser/ui/tabs/tab_utils.h" 43 #include "chrome/browser/ui/tabs/tab_utils.h"
44 #include "chrome/common/chrome_constants.h" 44 #include "chrome/common/chrome_constants.h"
45 #include "chrome/common/chrome_features.h" 45 #include "chrome/common/chrome_features.h"
46 #include "chrome/common/chrome_switches.h" 46 #include "chrome/common/chrome_switches.h"
47 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
48 #include "components/memory_coordinator/browser/memory_coordinator.h"
48 #include "components/metrics/system_memory_stats_recorder.h" 49 #include "components/metrics/system_memory_stats_recorder.h"
49 #include "components/variations/variations_associated_data.h" 50 #include "components/variations/variations_associated_data.h"
50 #include "content/public/browser/browser_thread.h" 51 #include "content/public/browser/browser_thread.h"
51 #include "content/public/browser/memory_pressure_controller.h" 52 #include "content/public/browser/memory_pressure_controller.h"
52 #include "content/public/browser/navigation_controller.h" 53 #include "content/public/browser/navigation_controller.h"
53 #include "content/public/browser/render_process_host.h" 54 #include "content/public/browser/render_process_host.h"
54 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
55 #include "content/public/common/page_importance_signals.h" 56 #include "content/public/common/page_importance_signals.h"
56 57
57 #if defined(OS_CHROMEOS) 58 #if defined(OS_CHROMEOS)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // A wrapper to content::SendPressureNotification that doesn't have overloaded 126 // A wrapper to content::SendPressureNotification that doesn't have overloaded
126 // type ambiguity. Makes use of Bind easier. 127 // type ambiguity. Makes use of Bind easier.
127 // TODO(chrisha): Move this do the default implementation of a delegate. 128 // TODO(chrisha): Move this do the default implementation of a delegate.
128 void NotifyRendererProcess( 129 void NotifyRendererProcess(
129 const content::RenderProcessHost* render_process_host, 130 const content::RenderProcessHost* render_process_host,
130 base::MemoryPressureListener::MemoryPressureLevel level) { 131 base::MemoryPressureListener::MemoryPressureLevel level) {
131 content::MemoryPressureController::SendPressureNotification( 132 content::MemoryPressureController::SendPressureNotification(
132 render_process_host, level); 133 render_process_host, level);
133 } 134 }
134 135
136 void NotifyRendererUsingMemoryCoordinator(
137 const content::RenderProcessHost* render_process_host,
138 base::MemoryPressureListener::MemoryPressureLevel level) {
139 auto* coordinator = memory_coordinator::MemoryCoordinator::GetInstance();
140 DCHECK(coordinator);
141 coordinator->DispatchToRenderer(render_process_host->GetID(), level);
142 }
143
135 } // namespace 144 } // namespace
136 145
137 //////////////////////////////////////////////////////////////////////////////// 146 ////////////////////////////////////////////////////////////////////////////////
138 // TabManager 147 // TabManager
139 148
140 TabManager::TabManager() 149 TabManager::TabManager()
141 : discard_count_(0), 150 : discard_count_(0),
142 recent_tab_discard_(false), 151 recent_tab_discard_(false),
143 discard_once_(false), 152 discard_once_(false),
144 browser_tab_strip_tracker_(this, nullptr, nullptr), 153 browser_tab_strip_tracker_(this, nullptr, nullptr),
145 test_tick_clock_(nullptr), 154 test_tick_clock_(nullptr),
146 under_memory_pressure_(false), 155 under_memory_pressure_(false),
147 weak_ptr_factory_(this) { 156 weak_ptr_factory_(this) {
148 #if defined(OS_CHROMEOS) 157 #if defined(OS_CHROMEOS)
149 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); 158 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr()));
150 #endif 159 #endif
151 browser_tab_strip_tracker_.Init( 160 browser_tab_strip_tracker_.Init(
152 BrowserTabStripTracker::InitWith::ALL_BROWERS); 161 BrowserTabStripTracker::InitWith::ALL_BROWERS);
153 162
154 // Set up default callbacks. These may be overridden post-construction as 163 // Set up default callbacks. These may be overridden post-construction as
155 // testing seams. 164 // testing seams.
156 get_current_pressure_level_ = base::Bind(&GetCurrentPressureLevel); 165 get_current_pressure_level_ = base::Bind(&GetCurrentPressureLevel);
157 notify_renderer_process_ = base::Bind(&NotifyRendererProcess); 166 notify_renderer_process_ = base::Bind(&NotifyRendererProcess);
167 if (memory_coordinator::IsEnabled()) {
168 auto* coordinator = memory_coordinator::MemoryCoordinator::GetInstance();
169 DCHECK(coordinator);
170 coordinator->SetChildrenDispatchCallback(
171 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this)));
172 notify_renderer_process_ =
173 base::Bind(&NotifyRendererUsingMemoryCoordinator);
174 }
158 } 175 }
159 176
160 TabManager::~TabManager() { 177 TabManager::~TabManager() {
161 Stop(); 178 Stop();
162 } 179 }
163 180
164 void TabManager::Start() { 181 void TabManager::Start() {
165 #if defined(OS_WIN) || defined(OS_MACOSX) 182 #if defined(OS_WIN) || defined(OS_MACOSX)
166 // If the feature is not enabled, do nothing. 183 // If the feature is not enabled, do nothing.
167 if (!base::FeatureList::IsEnabled(features::kAutomaticTabDiscarding)) 184 if (!base::FeatureList::IsEnabled(features::kAutomaticTabDiscarding))
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 observers_.RemoveObserver(observer); 917 observers_.RemoveObserver(observer);
901 } 918 }
902 919
903 void TabManager::OnDiscardedStateChange(content::WebContents* contents, 920 void TabManager::OnDiscardedStateChange(content::WebContents* contents,
904 bool is_discarded) { 921 bool is_discarded) {
905 FOR_EACH_OBSERVER(TabManagerObserver, observers_, 922 FOR_EACH_OBSERVER(TabManagerObserver, observers_,
906 OnDiscardedStateChange(contents, is_discarded)); 923 OnDiscardedStateChange(contents, is_discarded));
907 } 924 }
908 925
909 } // namespace memory 926 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | components/memory_coordinator/browser/memory_coordinator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698