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

Side by Side Diff: chrome/browser/sessions/tab_loader.cc

Issue 1136523004: [Sessions] Add detailed logging of SessionRestore events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/sessions/tab_loader.h" 5 #include "chrome/browser/sessions/tab_loader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
18 #include "content/public/browser/render_widget_host.h" 19 #include "content/public/browser/render_widget_host.h"
19 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/session_restore_uma.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 23
22 using content::NavigationController; 24 using content::NavigationController;
23 using content::RenderWidgetHost; 25 using content::RenderWidgetHost;
24 using content::WebContents; 26 using content::WebContents;
25 27
26 void TabLoader::Observe(int type, 28 void TabLoader::Observe(int type,
27 const content::NotificationSource& source, 29 const content::NotificationSource& source,
28 const content::NotificationDetails& details) { 30 const content::NotificationDetails& details) {
29 switch (type) { 31 switch (type) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 112
111 void TabLoader::LoadNextTab() { 113 void TabLoader::LoadNextTab() {
112 // LoadNextTab should only get called after we have started the tab 114 // LoadNextTab should only get called after we have started the tab
113 // loading. 115 // loading.
114 CHECK(delegate_); 116 CHECK(delegate_);
115 if (!tabs_to_load_.empty()) { 117 if (!tabs_to_load_.empty()) {
116 NavigationController* controller = tabs_to_load_.front(); 118 NavigationController* controller = tabs_to_load_.front();
117 DCHECK(controller); 119 DCHECK(controller);
118 tabs_loading_.insert(controller); 120 tabs_loading_.insert(controller);
119 tabs_to_load_.pop_front(); 121 tabs_to_load_.pop_front();
122
123 // Keep track of tabs that have been automatically loaded by session
124 // restore. This is the complement to SessionRestore.DeferredTabLoadedByUser
125 // recorded in NavigationControllerImpl::SetActive.
126 if (controller->NeedsReload()) {
127 UMA_HISTOGRAM_ENUMERATION(
128 content::kSessionRestoreTabActions,
129 content::kSessionRestoreTabActionsUma_BackgroundTabLoaded,
130 content::kSessionRestoreTabActionsUma_Max);
131 }
132
120 controller->LoadIfNecessary(); 133 controller->LoadIfNecessary();
121 content::WebContents* contents = controller->GetWebContents(); 134 content::WebContents* contents = controller->GetWebContents();
122 if (contents) { 135 if (contents) {
123 Browser* browser = chrome::FindBrowserWithWebContents(contents); 136 Browser* browser = chrome::FindBrowserWithWebContents(contents);
124 if (browser && 137 if (browser &&
125 browser->tab_strip_model()->GetActiveWebContents() != contents) { 138 browser->tab_strip_model()->GetActiveWebContents() != contents) {
126 // By default tabs are marked as visible. As only the active tab is 139 // By default tabs are marked as visible. As only the active tab is
127 // visible we need to explicitly tell non-active tabs they are hidden. 140 // visible we need to explicitly tell non-active tabs they are hidden.
128 // Without this call non-active tabs are not marked as backgrounded. 141 // Without this call non-active tabs are not marked as backgrounded.
129 // 142 //
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 189 }
177 190
178 void TabLoader::HandleTabClosedOrLoaded(NavigationController* controller) { 191 void TabLoader::HandleTabClosedOrLoaded(NavigationController* controller) {
179 RemoveTab(controller); 192 RemoveTab(controller);
180 if (delegate_ && loading_enabled_) 193 if (delegate_ && loading_enabled_)
181 LoadNextTab(); 194 LoadNextTab();
182 } 195 }
183 196
184 void TabLoader::OnMemoryPressure( 197 void TabLoader::OnMemoryPressure(
185 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 198 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
199 // On Windows and Mac this mechanism is only experimentally enabled.
200 #if defined(OS_WIN) or (defined(OS_MACOSX) and !defined(OS_IOS))
201 // If memory pressure isn't explicitly turned on then ignore these calls.
202 std::string react_to_memory_pressure = variations::GetVariationParamValue(
203 kSessionRestoreBackgroundLoading, "ReactToMemoryPressure"));
204 if (react_to_memory_pressure != "1")
205 return;
206 #endif
207
208 // Note that the session restore was interrupted by memory pressure.
209 UMA_HISTOGRAM_ENUMERATION(
210 content::kSessionRestoreActions,
211 content::kSessionRestoreActionsUma_InterruptedByMemoryPressure,
212 content::kSessionRestoreActionsUma_Max);
213
186 // When receiving a resource pressure level warning, we stop pre-loading more 214 // When receiving a resource pressure level warning, we stop pre-loading more
187 // tabs since we are running in danger of loading more tabs by throwing out 215 // tabs since we are running in danger of loading more tabs by throwing out
188 // old ones. 216 // old ones.
189 if (tabs_to_load_.empty()) 217 if (tabs_to_load_.empty())
190 return; 218 return;
191 // Stop the timer and suppress any tab loads while we clean the list. 219 // Stop the timer and suppress any tab loads while we clean the list.
192 SetTabLoadingEnabled(false); 220 SetTabLoadingEnabled(false);
193 while (!tabs_to_load_.empty()) { 221 while (!tabs_to_load_.empty()) {
222 // Count the number of tabs that have had their loading deferred.
223 UMA_HISTOGRAM_ENUMERATION(
224 content::kSessionRestoreTabActions,
225 content::kSessionRestoreTabActionsUma_TabLoadingDeferred,
226 content::kSessionRestoreTabActionsUma_Max);
227
194 NavigationController* controller = tabs_to_load_.front(); 228 NavigationController* controller = tabs_to_load_.front();
195 tabs_to_load_.pop_front(); 229 tabs_to_load_.pop_front();
196 RemoveTab(controller); 230 RemoveTab(controller);
197 } 231 }
198 // By calling |LoadNextTab| explicitly, we make sure that the 232 // By calling |LoadNextTab| explicitly, we make sure that the
199 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent. 233 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent.
200 LoadNextTab(); 234 LoadNextTab();
201 } 235 }
202 236
203 // static 237 // static
204 TabLoader* TabLoader::shared_tab_loader_ = nullptr; 238 TabLoader* TabLoader::shared_tab_loader_ = nullptr;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698