blob: 1347d52d00b53ad7986d5c73077769f78f0999c0 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]3770c242012-07-12 22:58:172// 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 Bang361a8c102022-05-22 10:21:478#include "base/callback_list.h"
kouheiae8028772015-08-17 03:01:469#include "chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h"
Kevin McNee77789ff2023-12-05 21:29:4710#include "content/public/browser/web_contents_observer.h"
11#include "content/public/browser/web_contents_user_data.h"
[email protected]3770c242012-07-12 22:58:1712
Kevin McNee77789ff2023-12-05 21:29:4713// 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]3770c242012-07-12 22:58:1715// creates histograms of some global object counts.
Kevin McNee77789ff2023-12-05 21:29:4716class UMABrowsingActivityObserver {
[email protected]3770c242012-07-12 22:58:1717 public:
Peter Boströmc75681ac2021-09-24 16:58:4118 UMABrowsingActivityObserver(const UMABrowsingActivityObserver&) = delete;
19 UMABrowsingActivityObserver& operator=(const UMABrowsingActivityObserver&) =
20 delete;
21
[email protected]3770c242012-07-12 22:58:1722 static void Init();
23
Kevin McNee77789ff2023-12-05 21:29:4724 // 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 McNee8f72d5d2024-01-16 16:07:4333 void NavigationEntryCommitted(
Kevin McNee77789ff2023-12-05 21:29:4734 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]3770c242012-07-12 22:58:1742 private:
43 UMABrowsingActivityObserver();
Kevin McNee77789ff2023-12-05 21:29:4744 ~UMABrowsingActivityObserver();
[email protected]3770c242012-07-12 22:58:1745
Kevin McNee77789ff2023-12-05 21:29:4746 void OnNavigationEntryCommitted(
47 content::WebContents* web_contents,
48 const content::LoadCommittedDetails& load_details) const;
[email protected]3770c242012-07-12 22:58:1749
Jinho Bang361a8c102022-05-22 10:21:4750 void OnAppTerminating() const;
51
Kyle Spiers6fef8a82019-05-08 23:05:0752 // 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]3770c242012-07-12 22:58:1756 // 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 McNee77789ff2023-12-05 21:29:4762 const TabStripModelStatsRecorder tab_recorder_;
Jinho Bang361a8c102022-05-22 10:21:4763 base::CallbackListSubscription subscription_;
[email protected]3770c242012-07-12 22:58:1764};
65
[email protected]3770c242012-07-12 22:58:1766#endif // CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_