OLD | NEW |
---|---|
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/session_restore_stats_collector.h" | 5 #include "chrome/browser/sessions/session_restore_stats_collector.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
13 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 | 15 |
16 using content::NavigationController; | 16 using content::NavigationController; |
17 using content::RenderWidgetHost; | 17 using content::RenderWidgetHost; |
18 using content::WebContents; | 18 using content::WebContents; |
19 | 19 |
20 // static | 20 // static |
21 void SessionRestoreStatsCollector::TrackTabs( | 21 void SessionRestoreStatsCollector::TrackTabs( |
22 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs, | 22 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs, |
23 const base::TimeTicks& restore_started) { | 23 const base::TimeTicks& restore_started, |
24 bool active_only) { | |
24 if (!shared_collector_) | 25 if (!shared_collector_) |
25 shared_collector_ = new SessionRestoreStatsCollector(restore_started); | 26 shared_collector_ = |
27 new SessionRestoreStatsCollector(restore_started, active_only); | |
26 | 28 |
27 shared_collector_->AddTabs(tabs); | 29 shared_collector_->AddTabs(tabs); |
28 } | 30 } |
29 | 31 |
30 SessionRestoreStatsCollector::SessionRestoreStatsCollector( | 32 SessionRestoreStatsCollector::SessionRestoreStatsCollector( |
31 const base::TimeTicks& restore_started) | 33 const base::TimeTicks& restore_started, |
34 bool active_only) | |
32 : got_first_foreground_load_(false), | 35 : got_first_foreground_load_(false), |
33 got_first_paint_(false), | 36 got_first_paint_(false), |
34 restore_started_(restore_started), | 37 restore_started_(restore_started), |
35 tab_count_(0), | 38 tab_count_(0), |
36 max_parallel_tab_loads_(0) { | 39 max_parallel_tab_loads_(0), |
40 active_only_(active_only) { | |
37 this_retainer_ = this; | 41 this_retainer_ = this; |
38 registrar_.Add( | 42 registrar_.Add( |
39 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 43 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
40 content::NotificationService::AllSources()); | 44 content::NotificationService::AllSources()); |
41 } | 45 } |
42 | 46 |
43 SessionRestoreStatsCollector::~SessionRestoreStatsCollector() { | 47 SessionRestoreStatsCollector::~SessionRestoreStatsCollector() { |
44 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && | 48 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && |
45 tabs_tracked_.empty() && render_widget_hosts_loading_.empty()); | 49 tabs_tracked_.empty() && render_widget_hosts_loading_.empty()); |
46 DCHECK(shared_collector_ == this); | 50 DCHECK(shared_collector_ == this); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 | 160 |
157 // Check if we are done and if so, reset |this_retainer_| as the collector no | 161 // Check if we are done and if so, reset |this_retainer_| as the collector no |
158 // longer needs to stay alive. | 162 // longer needs to stay alive. |
159 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && | 163 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && |
160 tabs_tracked_.empty() && render_widget_hosts_loading_.empty()) | 164 tabs_tracked_.empty() && render_widget_hosts_loading_.empty()) |
161 this_retainer_ = nullptr; | 165 this_retainer_ = nullptr; |
162 } | 166 } |
163 | 167 |
164 void SessionRestoreStatsCollector::AddTabs( | 168 void SessionRestoreStatsCollector::AddTabs( |
165 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs) { | 169 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs) { |
170 tab_count_ += tabs.size(); | |
166 for (auto& tab : tabs) { | 171 for (auto& tab : tabs) { |
172 // If we are only restoring active tabs and the tab is not active, nothing | |
173 // to do. | |
174 if (active_only_ && !tab.is_active) | |
sky
2015/04/03 22:04:46
Actually, one nit. Pass active_only to this functi
| |
175 continue; | |
167 RegisterForNotifications(&tab.contents->GetController()); | 176 RegisterForNotifications(&tab.contents->GetController()); |
168 if (tab.is_active) { | 177 if (tab.is_active) { |
169 RenderWidgetHost* render_widget_host = | 178 RenderWidgetHost* render_widget_host = |
170 GetRenderWidgetHost(&tab.contents->GetController()); | 179 GetRenderWidgetHost(&tab.contents->GetController()); |
171 render_widget_hosts_loading_.insert(render_widget_host); | 180 render_widget_hosts_loading_.insert(render_widget_host); |
172 } | 181 } |
173 } | 182 } |
174 } | 183 } |
175 | 184 |
176 void SessionRestoreStatsCollector::RemoveTab(NavigationController* tab) { | 185 void SessionRestoreStatsCollector::RemoveTab(NavigationController* tab) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 } | 220 } |
212 | 221 |
213 void SessionRestoreStatsCollector::RegisterForNotifications( | 222 void SessionRestoreStatsCollector::RegisterForNotifications( |
214 NavigationController* tab) { | 223 NavigationController* tab) { |
215 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 224 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
216 content::Source<WebContents>(tab->GetWebContents())); | 225 content::Source<WebContents>(tab->GetWebContents())); |
217 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 226 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
218 content::Source<NavigationController>(tab)); | 227 content::Source<NavigationController>(tab)); |
219 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 228 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
220 content::Source<NavigationController>(tab)); | 229 content::Source<NavigationController>(tab)); |
221 ++tab_count_; | |
222 tabs_tracked_.insert(tab); | 230 tabs_tracked_.insert(tab); |
223 } | 231 } |
224 | 232 |
225 RenderWidgetHost* SessionRestoreStatsCollector::GetRenderWidgetHost( | 233 RenderWidgetHost* SessionRestoreStatsCollector::GetRenderWidgetHost( |
226 NavigationController* tab) { | 234 NavigationController* tab) { |
227 WebContents* web_contents = tab->GetWebContents(); | 235 WebContents* web_contents = tab->GetWebContents(); |
228 if (web_contents) { | 236 if (web_contents) { |
229 content::RenderWidgetHostView* render_widget_host_view = | 237 content::RenderWidgetHostView* render_widget_host_view = |
230 web_contents->GetRenderWidgetHostView(); | 238 web_contents->GetRenderWidgetHostView(); |
231 if (render_widget_host_view) | 239 if (render_widget_host_view) |
232 return render_widget_host_view->GetRenderWidgetHost(); | 240 return render_widget_host_view->GetRenderWidgetHost(); |
233 } | 241 } |
234 return nullptr; | 242 return nullptr; |
235 } | 243 } |
236 | 244 |
237 // static | 245 // static |
238 SessionRestoreStatsCollector* SessionRestoreStatsCollector::shared_collector_ = | 246 SessionRestoreStatsCollector* SessionRestoreStatsCollector::shared_collector_ = |
239 nullptr; | 247 nullptr; |
OLD | NEW |