Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / sessions / session_restore_stats_collector.h
blobd166f845a1dc3110b8df72cac1f452e971658bc0
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_
8 #include <set>
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"
17 namespace content {
18 class NavigationController;
21 // SessionRestoreStatsCollector observes SessionRestore events ands records UMA
22 // accordingly.
23 class SessionRestoreStatsCollector
24 : public content::NotificationObserver,
25 public base::RefCounted<SessionRestoreStatsCollector> {
26 public:
27 // Called to start tracking tabs. If a restore is already occuring, the tabs
28 // are added to the existing list of tracked tabs. If |active_only| is true,
29 // only tabs that are marked as active will be tracked (for example when
30 // background tabs are not loaded during session restore).
31 static void TrackTabs(
32 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs,
33 const base::TimeTicks& restore_started,
34 bool active_only);
36 private:
37 friend class base::RefCounted<SessionRestoreStatsCollector>;
39 using RenderWidgetHostSet = std::set<content::RenderWidgetHost*>;
41 explicit SessionRestoreStatsCollector(const base::TimeTicks& restore_started);
42 ~SessionRestoreStatsCollector() override;
44 // NotificationObserver method.
45 void Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) override;
49 // Adds new tabs to the list of tracked tabs. If |active_only| is true,
50 // only tabs that are marked as active will be tracked (for example when
51 // background tabs are not loaded during session restore).
52 void AddTabs(const std::vector<SessionRestoreDelegate::RestoredTab>& tabs,
53 bool active_only);
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.
84 int tab_count_;
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
96 // at this time.
97 static SessionRestoreStatsCollector* shared_collector_;
99 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollector);
102 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_