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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_
10 #include "base/callback_list.h"
11 #include "chrome/browser/sessions/session_restore.h"
12 #include "chrome/browser/sessions/session_restore_delegate.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/render_widget_host.h"
18 class NavigationController
;
21 // SessionRestoreStatsCollector observes SessionRestore events ands records UMA
23 class SessionRestoreStatsCollector
24 : public content::NotificationObserver
,
25 public base::RefCounted
<SessionRestoreStatsCollector
> {
27 // Called to start tracking tabs. If a restore is already occuring, the tabs
28 // are added to the existing list of tracked tabs.
29 static void TrackTabs(
30 const std::vector
<SessionRestoreDelegate::RestoredTab
>& tabs
,
31 const base::TimeTicks
& restore_started
);
33 // Called to start tracking only active tabs. If a restore is already
34 // occuring, the tabs are added to the existing list of tracked tabs.
35 static void TrackActiveTabs(
36 const std::vector
<SessionRestoreDelegate::RestoredTab
>& tabs
,
37 const base::TimeTicks
& restore_started
);
40 friend class base::RefCounted
<SessionRestoreStatsCollector
>;
42 using RenderWidgetHostSet
= std::set
<content::RenderWidgetHost
*>;
44 explicit SessionRestoreStatsCollector(const base::TimeTicks
& restore_started
);
45 ~SessionRestoreStatsCollector() override
;
47 // NotificationObserver method.
48 void Observe(int type
,
49 const content::NotificationSource
& source
,
50 const content::NotificationDetails
& details
) override
;
52 // Adds new tabs to the list of tracked tabs.
53 void AddTabs(const std::vector
<SessionRestoreDelegate::RestoredTab
>& tabs
);
55 // Called when a tab is no longer tracked.
56 void RemoveTab(content::NavigationController
* tab
);
58 // Registers for relevant notifications for a tab.
59 void RegisterForNotifications(content::NavigationController
* tab
);
61 // Returns the RenderWidgetHost of a tab.
62 content::RenderWidgetHost
* GetRenderWidgetHost(
63 content::NavigationController
* tab
);
65 // Have we recorded the times for a foreground tab load?
66 bool got_first_foreground_load_
;
68 // Have we recorded the times for a foreground tab paint?
69 bool got_first_paint_
;
71 // The time the restore process started.
72 base::TimeTicks restore_started_
;
74 // The renderers we have started loading into.
75 RenderWidgetHostSet render_widget_hosts_loading_
;
77 // The renderers we have loaded and are waiting on to paint.
78 RenderWidgetHostSet render_widget_hosts_to_paint_
;
80 // List of tracked tabs.
81 std::set
<content::NavigationController
*> tabs_tracked_
;
83 // The number of tabs that have been restored.
86 // Max number of tabs that were loaded in parallel (for metrics).
87 size_t max_parallel_tab_loads_
;
89 // Notification registrar.
90 content::NotificationRegistrar registrar_
;
92 // To keep the collector alive as long as needed.
93 scoped_refptr
<SessionRestoreStatsCollector
> this_retainer_
;
95 // The shared SessionRestoreNotifier instance for all SessionRestores running
97 static SessionRestoreStatsCollector
* shared_collector_
;
99 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollector
);
102 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_