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

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: Fix typo. Created 5 years, 6 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/sessions/tab_loader.h ('k') | chrome/chrome_tests_unit.gypi » ('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 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/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/sessions/session_restore_stats_collector.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 "components/favicon/content/content_favicon_driver.h" 16 #include "components/favicon/content/content_favicon_driver.h"
16 #include "components/variations/variations_associated_data.h" 17 #include "components/variations/variations_associated_data.h"
17 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/render_widget_host.h" 21 #include "content/public/browser/render_widget_host.h"
21 #include "content/public/browser/render_widget_host_view.h" 22 #include "content/public/browser/render_widget_host_view.h"
(...skipping 20 matching lines...) Expand all
42 } 43 }
43 default: 44 default:
44 NOTREACHED() << "Unknown notification received:" << type; 45 NOTREACHED() << "Unknown notification received:" << type;
45 } 46 }
46 // Delete ourselves when we are done. 47 // Delete ourselves when we are done.
47 if (tabs_loading_.empty() && tabs_to_load_.empty()) 48 if (tabs_loading_.empty() && tabs_to_load_.empty())
48 this_retainer_ = nullptr; 49 this_retainer_ = nullptr;
49 } 50 }
50 51
51 void TabLoader::SetTabLoadingEnabled(bool enable_tab_loading) { 52 void TabLoader::SetTabLoadingEnabled(bool enable_tab_loading) {
53 // TODO(chrisha): Make the SessionRestoreStatsCollector aware that tab loading
54 // was explicitly stopped or restarted. This can make be used to invalidate
55 // various metrics.
52 if (enable_tab_loading == loading_enabled_) 56 if (enable_tab_loading == loading_enabled_)
53 return; 57 return;
54 loading_enabled_ = enable_tab_loading; 58 loading_enabled_ = enable_tab_loading;
55 if (loading_enabled_) 59 if (loading_enabled_) {
56 LoadNextTab(); 60 LoadNextTab();
57 else 61 } else {
58 force_load_timer_.Stop(); 62 force_load_timer_.Stop();
63 }
59 } 64 }
60 65
61 // static 66 // static
62 void TabLoader::RestoreTabs(const std::vector<RestoredTab>& tabs, 67 void TabLoader::RestoreTabs(const std::vector<RestoredTab>& tabs,
63 const base::TimeTicks& restore_started) { 68 const base::TimeTicks& restore_started) {
64 if (!shared_tab_loader_) 69 if (!shared_tab_loader_)
65 shared_tab_loader_ = new TabLoader(restore_started); 70 shared_tab_loader_ = new TabLoader(restore_started);
66 71
72 shared_tab_loader_->stats_collector_->TrackTabs(tabs);
67 shared_tab_loader_->StartLoading(tabs); 73 shared_tab_loader_->StartLoading(tabs);
68 } 74 }
69 75
70 TabLoader::TabLoader(base::TimeTicks restore_started) 76 TabLoader::TabLoader(base::TimeTicks restore_started)
71 : memory_pressure_listener_( 77 : memory_pressure_listener_(
72 base::Bind(&TabLoader::OnMemoryPressure, base::Unretained(this))), 78 base::Bind(&TabLoader::OnMemoryPressure, base::Unretained(this))),
73 force_load_delay_multiplier_(1), 79 force_load_delay_multiplier_(1),
74 loading_enabled_(true), 80 loading_enabled_(true),
75 restore_started_(restore_started) { 81 restore_started_(restore_started) {
82 stats_collector_ = new SessionRestoreStatsCollector(
83 restore_started,
84 make_scoped_ptr(
85 new SessionRestoreStatsCollector::UmaStatsReportingDelegate()));
76 shared_tab_loader_ = this; 86 shared_tab_loader_ = this;
77 this_retainer_ = this; 87 this_retainer_ = this;
78 } 88 }
79 89
80 TabLoader::~TabLoader() { 90 TabLoader::~TabLoader() {
81 DCHECK(tabs_loading_.empty() && tabs_to_load_.empty()); 91 DCHECK(tabs_loading_.empty() && tabs_to_load_.empty());
82 DCHECK(shared_tab_loader_ == this); 92 DCHECK(shared_tab_loader_ == this);
83 shared_tab_loader_ = nullptr; 93 shared_tab_loader_ = nullptr;
84 } 94 }
85 95
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 #endif 224 #endif
215 225
216 // When receiving a resource pressure level warning, we stop pre-loading more 226 // When receiving a resource pressure level warning, we stop pre-loading more
217 // tabs since we are running in danger of loading more tabs by throwing out 227 // tabs since we are running in danger of loading more tabs by throwing out
218 // old ones. 228 // old ones.
219 if (tabs_to_load_.empty()) 229 if (tabs_to_load_.empty())
220 return; 230 return;
221 // Stop the timer and suppress any tab loads while we clean the list. 231 // Stop the timer and suppress any tab loads while we clean the list.
222 SetTabLoadingEnabled(false); 232 SetTabLoadingEnabled(false);
223 while (!tabs_to_load_.empty()) { 233 while (!tabs_to_load_.empty()) {
224 NavigationController* controller = tabs_to_load_.front(); 234 NavigationController* tab = tabs_to_load_.front();
225 tabs_to_load_.pop_front(); 235 tabs_to_load_.pop_front();
226 RemoveTab(controller); 236 RemoveTab(tab);
237
238 // Notify the stats collector that a tab's loading has been deferred due to
239 // memory pressure.
240 stats_collector_->DeferTab(tab);
227 } 241 }
228 // By calling |LoadNextTab| explicitly, we make sure that the 242 // By calling |LoadNextTab| explicitly, we make sure that the
229 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent. 243 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent.
230 LoadNextTab(); 244 LoadNextTab();
231 } 245 }
232 246
233 // static 247 // static
234 TabLoader* TabLoader::shared_tab_loader_ = nullptr; 248 TabLoader* TabLoader::shared_tab_loader_ = nullptr;
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_loader.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698