Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame^] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_ |
| 6 | #define CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_ |
| 7 | |
Jinho Bang | 361a8c10 | 2022-05-22 10:21:47 | [diff] [blame] | 8 | #include "base/callback_list.h" |
kouhei | ae802877 | 2015-08-17 03:01:46 | [diff] [blame] | 9 | #include "chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h" |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 10 | #include "content/public/browser/notification_observer.h" |
kouhei | ae802877 | 2015-08-17 03:01:46 | [diff] [blame] | 11 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 12 | |
| 13 | namespace chrome { |
| 14 | |
| 15 | // This object is instantiated when the first Browser object is added to the |
| 16 | // list and delete when the last one is removed. It watches for loads and |
| 17 | // creates histograms of some global object counts. |
| 18 | class UMABrowsingActivityObserver : public content::NotificationObserver { |
| 19 | public: |
Peter Boström | c75681ac | 2021-09-24 16:58:41 | [diff] [blame] | 20 | UMABrowsingActivityObserver(const UMABrowsingActivityObserver&) = delete; |
| 21 | UMABrowsingActivityObserver& operator=(const UMABrowsingActivityObserver&) = |
| 22 | delete; |
| 23 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 24 | static void Init(); |
| 25 | |
| 26 | private: |
| 27 | UMABrowsingActivityObserver(); |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 28 | ~UMABrowsingActivityObserver() override; |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 29 | |
| 30 | // content::NotificationObserver implementation. |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 31 | void Observe(int type, |
| 32 | const content::NotificationSource& source, |
| 33 | const content::NotificationDetails& details) override; |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 34 | |
Jinho Bang | 361a8c10 | 2022-05-22 10:21:47 | [diff] [blame] | 35 | void OnAppTerminating() const; |
| 36 | |
Kyle Spiers | 6fef8a8 | 2019-05-08 23:05:07 | [diff] [blame] | 37 | // Calculates the time from an update being visible to the browser and |
| 38 | // the browser restarting or quitting and logs it. |
| 39 | void LogTimeBeforeUpdate() const; |
| 40 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 41 | // Counts the number of active RenderProcessHosts and logs them. |
| 42 | void LogRenderProcessHostCount() const; |
| 43 | |
| 44 | // Counts the number of tabs in each browser window and logs them. This is |
| 45 | // different than the number of WebContents objects since WebContents objects |
| 46 | // can be used for popups and in dialog boxes. We're just counting toplevel |
| 47 | // tabs here. |
| 48 | void LogBrowserTabCount() const; |
| 49 | |
Charlene Yan | 22ab811 | 2020-10-02 17:28:14 | [diff] [blame] | 50 | // Maps |total_tab_count| to the corresponding histogram bucket with the |
| 51 | // proper name suffix. |
| 52 | std::string AppendTabBucketCountToHistogramName(int total_tab_count) const; |
| 53 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 54 | content::NotificationRegistrar registrar_; |
kouhei | ae802877 | 2015-08-17 03:01:46 | [diff] [blame] | 55 | TabStripModelStatsRecorder tab_recorder_; |
Jinho Bang | 361a8c10 | 2022-05-22 10:21:47 | [diff] [blame] | 56 | base::CallbackListSubscription subscription_; |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // namespace chrome |
| 60 | |
| 61 | #endif // CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_ |