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" |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 10 | #include "content/public/browser/web_contents_observer.h" |
| 11 | #include "content/public/browser/web_contents_user_data.h" |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 12 | |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 13 | // This object is instantiated during startup, before the first Browser object |
| 14 | // is added to the list and deleted during shutdown. It watches for loads and |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 15 | // creates histograms of some global object counts. |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 16 | class UMABrowsingActivityObserver { |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 17 | public: |
Peter Boström | c75681ac | 2021-09-24 16:58:41 | [diff] [blame] | 18 | UMABrowsingActivityObserver(const UMABrowsingActivityObserver&) = delete; |
| 19 | UMABrowsingActivityObserver& operator=(const UMABrowsingActivityObserver&) = |
| 20 | delete; |
| 21 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 22 | static void Init(); |
| 23 | |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 24 | // Notifies `UMABrowsingActivityObserver` with tab related events. |
| 25 | class TabHelper : public content::WebContentsObserver, |
| 26 | public content::WebContentsUserData<TabHelper> { |
| 27 | public: |
| 28 | TabHelper(const TabHelper&) = delete; |
| 29 | TabHelper& operator=(const TabHelper&) = delete; |
| 30 | ~TabHelper() override; |
| 31 | |
| 32 | // content::WebContentsObserver |
Kevin McNee | 8f72d5d | 2024-01-16 16:07:43 | [diff] [blame] | 33 | void NavigationEntryCommitted( |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 34 | const content::LoadCommittedDetails& load_details) override; |
| 35 | |
| 36 | private: |
| 37 | explicit TabHelper(content::WebContents* web_contents); |
| 38 | friend class content::WebContentsUserData<TabHelper>; |
| 39 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| 40 | }; |
| 41 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 42 | private: |
| 43 | UMABrowsingActivityObserver(); |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 44 | ~UMABrowsingActivityObserver(); |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 45 | |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 46 | void OnNavigationEntryCommitted( |
| 47 | content::WebContents* web_contents, |
| 48 | const content::LoadCommittedDetails& load_details) const; |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 49 | |
Jinho Bang | 361a8c10 | 2022-05-22 10:21:47 | [diff] [blame] | 50 | void OnAppTerminating() const; |
| 51 | |
Kyle Spiers | 6fef8a8 | 2019-05-08 23:05:07 | [diff] [blame] | 52 | // Calculates the time from an update being visible to the browser and |
| 53 | // the browser restarting or quitting and logs it. |
| 54 | void LogTimeBeforeUpdate() const; |
| 55 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 56 | // Counts the number of tabs in each browser window and logs them. This is |
| 57 | // different than the number of WebContents objects since WebContents objects |
| 58 | // can be used for popups and in dialog boxes. We're just counting toplevel |
| 59 | // tabs here. |
| 60 | void LogBrowserTabCount() const; |
| 61 | |
Kevin McNee | 77789ff | 2023-12-05 21:29:47 | [diff] [blame] | 62 | const TabStripModelStatsRecorder tab_recorder_; |
Jinho Bang | 361a8c10 | 2022-05-22 10:21:47 | [diff] [blame] | 63 | base::CallbackListSubscription subscription_; |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 64 | }; |
| 65 | |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 66 | #endif // CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_ |