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_ = new SessionRestoreStatsCollector(restore_started); |
26 | 27 |
27 shared_collector_->AddTabs(tabs); | 28 shared_collector_->AddTabs(tabs, active_only); |
28 } | 29 } |
29 | 30 |
30 SessionRestoreStatsCollector::SessionRestoreStatsCollector( | 31 SessionRestoreStatsCollector::SessionRestoreStatsCollector( |
31 const base::TimeTicks& restore_started) | 32 const base::TimeTicks& restore_started) |
32 : got_first_foreground_load_(false), | 33 : got_first_foreground_load_(false), |
33 got_first_paint_(false), | 34 got_first_paint_(false), |
34 restore_started_(restore_started), | 35 restore_started_(restore_started), |
35 tab_count_(0), | 36 tab_count_(0), |
36 max_parallel_tab_loads_(0) { | 37 max_parallel_tab_loads_(0) { |
37 this_retainer_ = this; | 38 this_retainer_ = this; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 156 } |
156 | 157 |
157 // Check if we are done and if so, reset |this_retainer_| as the collector no | 158 // Check if we are done and if so, reset |this_retainer_| as the collector no |
158 // longer needs to stay alive. | 159 // longer needs to stay alive. |
159 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && | 160 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && |
160 tabs_tracked_.empty() && render_widget_hosts_loading_.empty()) | 161 tabs_tracked_.empty() && render_widget_hosts_loading_.empty()) |
161 this_retainer_ = nullptr; | 162 this_retainer_ = nullptr; |
162 } | 163 } |
163 | 164 |
164 void SessionRestoreStatsCollector::AddTabs( | 165 void SessionRestoreStatsCollector::AddTabs( |
165 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs) { | 166 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs, |
| 167 bool active_only) { |
| 168 tab_count_ += tabs.size(); |
166 for (auto& tab : tabs) { | 169 for (auto& tab : tabs) { |
| 170 // If we are only restoring active tabs and the tab is not active, nothing |
| 171 // to do. |
| 172 if (active_only && !tab.is_active) |
| 173 continue; |
167 RegisterForNotifications(&tab.contents->GetController()); | 174 RegisterForNotifications(&tab.contents->GetController()); |
168 if (tab.is_active) { | 175 if (tab.is_active) { |
169 RenderWidgetHost* render_widget_host = | 176 RenderWidgetHost* render_widget_host = |
170 GetRenderWidgetHost(&tab.contents->GetController()); | 177 GetRenderWidgetHost(&tab.contents->GetController()); |
171 render_widget_hosts_loading_.insert(render_widget_host); | 178 render_widget_hosts_loading_.insert(render_widget_host); |
172 } | 179 } |
173 } | 180 } |
174 } | 181 } |
175 | 182 |
176 void SessionRestoreStatsCollector::RemoveTab(NavigationController* tab) { | 183 void SessionRestoreStatsCollector::RemoveTab(NavigationController* tab) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 218 } |
212 | 219 |
213 void SessionRestoreStatsCollector::RegisterForNotifications( | 220 void SessionRestoreStatsCollector::RegisterForNotifications( |
214 NavigationController* tab) { | 221 NavigationController* tab) { |
215 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 222 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
216 content::Source<WebContents>(tab->GetWebContents())); | 223 content::Source<WebContents>(tab->GetWebContents())); |
217 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 224 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
218 content::Source<NavigationController>(tab)); | 225 content::Source<NavigationController>(tab)); |
219 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 226 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
220 content::Source<NavigationController>(tab)); | 227 content::Source<NavigationController>(tab)); |
221 ++tab_count_; | |
222 tabs_tracked_.insert(tab); | 228 tabs_tracked_.insert(tab); |
223 } | 229 } |
224 | 230 |
225 RenderWidgetHost* SessionRestoreStatsCollector::GetRenderWidgetHost( | 231 RenderWidgetHost* SessionRestoreStatsCollector::GetRenderWidgetHost( |
226 NavigationController* tab) { | 232 NavigationController* tab) { |
227 WebContents* web_contents = tab->GetWebContents(); | 233 WebContents* web_contents = tab->GetWebContents(); |
228 if (web_contents) { | 234 if (web_contents) { |
229 content::RenderWidgetHostView* render_widget_host_view = | 235 content::RenderWidgetHostView* render_widget_host_view = |
230 web_contents->GetRenderWidgetHostView(); | 236 web_contents->GetRenderWidgetHostView(); |
231 if (render_widget_host_view) | 237 if (render_widget_host_view) |
232 return render_widget_host_view->GetRenderWidgetHost(); | 238 return render_widget_host_view->GetRenderWidgetHost(); |
233 } | 239 } |
234 return nullptr; | 240 return nullptr; |
235 } | 241 } |
236 | 242 |
237 // static | 243 // static |
238 SessionRestoreStatsCollector* SessionRestoreStatsCollector::shared_collector_ = | 244 SessionRestoreStatsCollector* SessionRestoreStatsCollector::shared_collector_ = |
239 nullptr; | 245 nullptr; |
OLD | NEW |