| 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 #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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/callback_list.h" | 10 #include "base/callback_list.h" |
| 11 #include "chrome/browser/sessions/session_restore.h" | 11 #include "chrome/browser/sessions/session_restore.h" |
| 12 #include "chrome/browser/sessions/session_restore_delegate.h" | 12 #include "chrome/browser/sessions/session_restore_delegate.h" |
| 13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 15 #include "content/public/browser/render_widget_host.h" | 15 #include "content/public/browser/render_widget_host.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class NavigationController; | 18 class NavigationController; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // SessionRestoreStatsCollector observes SessionRestore events ands records UMA | 21 // SessionRestoreStatsCollector observes SessionRestore events ands records UMA |
| 22 // accordingly. | 22 // accordingly. |
| 23 class SessionRestoreStatsCollector | 23 class SessionRestoreStatsCollector |
| 24 : public content::NotificationObserver, | 24 : public content::NotificationObserver, |
| 25 public base::RefCounted<SessionRestoreStatsCollector> { | 25 public base::RefCounted<SessionRestoreStatsCollector> { |
| 26 public: | 26 public: |
| 27 // Called to start tracking tabs. If a restore is already occuring, the tabs | 27 // Called to start tracking tabs. If a restore is already occuring, the tabs |
| 28 // are added to the existing list of tracked 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). |
| 29 static void TrackTabs( | 31 static void TrackTabs( |
| 30 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs, | 32 const std::vector<SessionRestoreDelegate::RestoredTab>& tabs, |
| 31 const base::TimeTicks& restore_started); | 33 const base::TimeTicks& restore_started, |
| 34 bool active_only); |
| 32 | 35 |
| 33 private: | 36 private: |
| 34 friend class base::RefCounted<SessionRestoreStatsCollector>; | 37 friend class base::RefCounted<SessionRestoreStatsCollector>; |
| 35 | 38 |
| 36 using RenderWidgetHostSet = std::set<content::RenderWidgetHost*>; | 39 using RenderWidgetHostSet = std::set<content::RenderWidgetHost*>; |
| 37 | 40 |
| 38 explicit SessionRestoreStatsCollector(const base::TimeTicks& restore_started); | 41 explicit SessionRestoreStatsCollector(const base::TimeTicks& restore_started); |
| 39 ~SessionRestoreStatsCollector() override; | 42 ~SessionRestoreStatsCollector() override; |
| 40 | 43 |
| 41 // NotificationObserver method. | 44 // NotificationObserver method. |
| 42 void Observe(int type, | 45 void Observe(int type, |
| 43 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
| 44 const content::NotificationDetails& details) override; | 47 const content::NotificationDetails& details) override; |
| 45 | 48 |
| 46 // Adds new tabs to the list of tracked tabs. | 49 // Adds new tabs to the list of tracked tabs. If |active_only| is true, |
| 47 void AddTabs(const std::vector<SessionRestoreDelegate::RestoredTab>& tabs); | 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); |
| 48 | 54 |
| 49 // Called when a tab is no longer tracked. | 55 // Called when a tab is no longer tracked. |
| 50 void RemoveTab(content::NavigationController* tab); | 56 void RemoveTab(content::NavigationController* tab); |
| 51 | 57 |
| 52 // Registers for relevant notifications for a tab. | 58 // Registers for relevant notifications for a tab. |
| 53 void RegisterForNotifications(content::NavigationController* tab); | 59 void RegisterForNotifications(content::NavigationController* tab); |
| 54 | 60 |
| 55 // Returns the RenderWidgetHost of a tab. | 61 // Returns the RenderWidgetHost of a tab. |
| 56 content::RenderWidgetHost* GetRenderWidgetHost( | 62 content::RenderWidgetHost* GetRenderWidgetHost( |
| 57 content::NavigationController* tab); | 63 content::NavigationController* tab); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 87 scoped_refptr<SessionRestoreStatsCollector> this_retainer_; | 93 scoped_refptr<SessionRestoreStatsCollector> this_retainer_; |
| 88 | 94 |
| 89 // The shared SessionRestoreNotifier instance for all SessionRestores running | 95 // The shared SessionRestoreNotifier instance for all SessionRestores running |
| 90 // at this time. | 96 // at this time. |
| 91 static SessionRestoreStatsCollector* shared_collector_; | 97 static SessionRestoreStatsCollector* shared_collector_; |
| 92 | 98 |
| 93 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollector); | 99 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollector); |
| 94 }; | 100 }; |
| 95 | 101 |
| 96 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_ | 102 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_STATS_COLLECTOR_H_ |
| OLD | NEW |