blob: bfc9b980111372aec6564ab70abb19c7f9c4c1ce [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"
[email protected]3770c242012-07-12 22:58:1710#include "content/public/browser/notification_observer.h"
kouheiae8028772015-08-17 03:01:4611#include "content/public/browser/notification_registrar.h"
[email protected]3770c242012-07-12 22:58:1712
13namespace 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.
18class UMABrowsingActivityObserver : public content::NotificationObserver {
19 public:
Peter Boströmc75681ac2021-09-24 16:58:4120 UMABrowsingActivityObserver(const UMABrowsingActivityObserver&) = delete;
21 UMABrowsingActivityObserver& operator=(const UMABrowsingActivityObserver&) =
22 delete;
23
[email protected]3770c242012-07-12 22:58:1724 static void Init();
25
26 private:
27 UMABrowsingActivityObserver();
dcheng5dd5ff62014-10-21 12:42:3828 ~UMABrowsingActivityObserver() override;
[email protected]3770c242012-07-12 22:58:1729
30 // content::NotificationObserver implementation.
dcheng5dd5ff62014-10-21 12:42:3831 void Observe(int type,
32 const content::NotificationSource& source,
33 const content::NotificationDetails& details) override;
[email protected]3770c242012-07-12 22:58:1734
Jinho Bang361a8c102022-05-22 10:21:4735 void OnAppTerminating() const;
36
Kyle Spiers6fef8a82019-05-08 23:05:0737 // 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]3770c242012-07-12 22:58:1741 // 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 Yan22ab8112020-10-02 17:28:1450 // 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]3770c242012-07-12 22:58:1754 content::NotificationRegistrar registrar_;
kouheiae8028772015-08-17 03:01:4655 TabStripModelStatsRecorder tab_recorder_;
Jinho Bang361a8c102022-05-22 10:21:4756 base::CallbackListSubscription subscription_;
[email protected]3770c242012-07-12 22:58:1757};
58
59} // namespace chrome
60
61#endif // CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_