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

Side by Side Diff: chrome/browser/sessions/session_restore_stats_collector.h

Issue 1136523004: [Sessions] Add detailed logging of SessionRestore events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored per sky@'s suggestion. Created 5 years, 7 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
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 #ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_
7 7
8 #include <map>
8 #include <set> 9 #include <set>
9 10
10 #include "base/callback_list.h" 11 #include "base/callback_list.h"
11 #include "chrome/browser/sessions/session_restore.h" 12 #include "chrome/browser/sessions/session_restore.h"
12 #include "chrome/browser/sessions/session_restore_delegate.h" 13 #include "chrome/browser/sessions/session_restore_delegate.h"
13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/render_widget_host.h" 16 #include "content/public/browser/render_widget_host.h"
16 17
17 namespace content { 18 namespace content {
18 class NavigationController; 19 class NavigationController;
19 } 20 }
20 21
21 // SessionRestoreStatsCollector observes SessionRestore events ands records UMA 22 // SessionRestoreStatsCollector observes SessionRestore events ands records UMA
22 // accordingly. 23 // accordingly.
23 class SessionRestoreStatsCollector 24 class SessionRestoreStatsCollector
24 : public content::NotificationObserver, 25 : public content::NotificationObserver,
25 public base::RefCounted<SessionRestoreStatsCollector> { 26 public base::RefCounted<SessionRestoreStatsCollector> {
26 public: 27 public:
27 // Called to start tracking tabs. If a restore is already occuring, the tabs 28 // Called to start tracking tabs. If a restore is already occuring, the tabs
28 // are added to the existing list of tracked tabs. 29 // are added to the existing list of tracked tabs.
29 static void TrackTabs( 30 static void TrackTabs(
30 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs, 31 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs,
31 const base::TimeTicks& restore_started); 32 const base::TimeTicks& restore_started);
32 33
34 // Called to indicate that the loading of a tab has been deferred by session
35 // restore. If the reason for the deferral was memory pressure this will be
36 // recorded.
37 static void DeferTab(content::NavigationController* tab);
38
33 private: 39 private:
34 friend class base::RefCounted<SessionRestoreStatsCollector>; 40 friend class base::RefCounted<SessionRestoreStatsCollector>;
35 41
36 using RenderWidgetHostSet = std::set<content::RenderWidgetHost*>; 42 using RenderWidgetHostSet = std::set<content::RenderWidgetHost*>;
37 43
38 explicit SessionRestoreStatsCollector(const base::TimeTicks& restore_started); 44 explicit SessionRestoreStatsCollector(const base::TimeTicks& restore_started);
39 ~SessionRestoreStatsCollector() override; 45 ~SessionRestoreStatsCollector() override;
40 46
41 // NotificationObserver method. 47 // NotificationObserver method.
42 void Observe(int type, 48 void Observe(int type,
43 const content::NotificationSource& source, 49 const content::NotificationSource& source,
44 const content::NotificationDetails& details) override; 50 const content::NotificationDetails& details) override;
45 51
46 // Adds new tabs to the list of tracked tabs. 52 // Adds new tabs to the list of tracked tabs.
47 void AddTabs(const std::vector<SessionRestoreDelegate::RestoredTab>& tabs); 53 void AddTabs(const std::vector<SessionRestoreDelegate::RestoredTab>& tabs);
48 54
49 // Called when a tab is no longer tracked. 55 // Called to indicate that the loading of a tab has been deferred by session
50 void RemoveTab(content::NavigationController* tab); 56 // restore. Called by the static DeferTab.
57 void DeferTabImpl(content::NavigationController* tab);
58
59 // Called when a tab is no longer tracked. This is called by the 'Observe'
60 // notification callback.
61 void RemoveTab(bool is_deferred, content::NavigationController* tab);
51 62
52 // Registers for relevant notifications for a tab. 63 // Registers for relevant notifications for a tab.
53 void RegisterForNotifications(content::NavigationController* tab); 64 void RegisterForNotifications(content::NavigationController* tab);
54 65
55 // Returns the RenderWidgetHost of a tab. 66 // Returns the RenderWidgetHost of a tab.
56 content::RenderWidgetHost* GetRenderWidgetHost( 67 content::RenderWidgetHost* GetRenderWidgetHost(
57 content::NavigationController* tab); 68 content::NavigationController* tab);
58 69
70 // Returns true if the specified tab had it's loading deferred by an active
71 // session restore.
72 bool IsDeferred(content::NavigationController* tab);
73
59 // Have we recorded the times for a foreground tab load? 74 // Have we recorded the times for a foreground tab load?
60 bool got_first_foreground_load_; 75 bool got_first_foreground_load_;
61 76
62 // Have we recorded the times for a foreground tab paint? 77 // Have we recorded the times for a foreground tab paint?
63 bool got_first_paint_; 78 bool got_first_paint_;
64 79
65 // The time the restore process started. 80 // The time the restore process started.
66 base::TimeTicks restore_started_; 81 base::TimeTicks restore_started_;
67 82
68 // The renderers we have started loading into. 83 // The renderers we have started loading into.
69 RenderWidgetHostSet render_widget_hosts_loading_; 84 RenderWidgetHostSet render_widget_hosts_loading_;
70 85
71 // The renderers we have loaded and are waiting on to paint. 86 // The renderers we have loaded and are waiting on to paint.
72 RenderWidgetHostSet render_widget_hosts_to_paint_; 87 RenderWidgetHostSet render_widget_hosts_to_paint_;
73 88
74 // List of tracked tabs. 89 // List of tracked tabs. Each tab is associated with the automatically
75 std::set<content::NavigationController*> tabs_tracked_; 90 // assigned ID of the ongoing session restore that created the tab.
91 std::map<content::NavigationController*, int> tabs_tracked_;
76 92
77 // The number of tabs that have been restored. 93 // List of deferred tabs. Each tab is associated with its session restore ID,
94 // as with tabs_tracked_.
95 std::map<content::NavigationController*, int> tabs_deferred_;
96
97 // A set of session restore IDs that have had tabs deferred. Absence from this
98 // set means the session restore did not defer any tabs.
99 std::set<int> deferred_tabs_seen_;
100
101 // The number of tabs that have been restored. This is across all overlapping
102 // session restores.
78 int tab_count_; 103 int tab_count_;
79 104
105 // The number of tabs that have been deferred. This is across all overlapping
106 // session restores.
107 int tab_deferred_count_;
108
109 // The ID of the most recently initiated session restore. Incremented by
110 // calls to AddTabs.
111 int session_restore_id_;
112
80 // Max number of tabs that were loaded in parallel (for metrics). 113 // Max number of tabs that were loaded in parallel (for metrics).
81 size_t max_parallel_tab_loads_; 114 size_t max_parallel_tab_loads_;
82 115
83 // Notification registrar. 116 // Notification registrar.
84 content::NotificationRegistrar registrar_; 117 content::NotificationRegistrar registrar_;
85 118
86 // To keep the collector alive as long as needed. 119 // To keep the collector alive as long as needed.
87 scoped_refptr<SessionRestoreStatsCollector> this_retainer_; 120 scoped_refptr<SessionRestoreStatsCollector> this_retainer_;
88 121
89 // The shared SessionRestoreNotifier instance for all SessionRestores running 122 // The shared SessionRestoreNotifier instance for all SessionRestores running
90 // at this time. 123 // at this time.
91 static SessionRestoreStatsCollector* shared_collector_; 124 static SessionRestoreStatsCollector* shared_collector_;
92 125
93 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollector); 126 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollector);
94 }; 127 };
95 128
96 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_ 129 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698