blob: b79878fbdcef21feb7571e0778eacf6e5c51887e [file] [log] [blame]
[email protected]5bdaa2d2014-05-19 14:59:511// Copyright 2014 The Chromium Authors. All rights reserved.
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_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
6#define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
7
8#include <string>
9
10#include "base/basictypes.h"
[email protected]4b4892b2014-05-22 15:06:1511#include "base/callback.h"
[email protected]037642f2014-05-29 20:40:5012#include "base/memory/scoped_ptr.h"
[email protected]4b4892b2014-05-22 15:06:1513#include "base/memory/weak_ptr.h"
[email protected]d7ea39e2014-05-22 03:59:1814#include "base/threading/thread_checker.h"
asvitkine89406d1f2015-01-17 06:57:1015#include "chrome/browser/metrics/metrics_memory_details.h"
[email protected]5bdaa2d2014-05-19 14:59:5116#include "components/metrics/metrics_service_client.h"
gunsch840bc412014-09-18 19:38:0617#include "components/metrics/profiler/tracking_synchronizer_observer.h"
blundell26b95242015-08-17 10:29:2418#include "components/omnibox/browser/omnibox_event_global_tracker.h"
[email protected]d7ea39e2014-05-22 03:59:1819#include "content/public/browser/notification_observer.h"
20#include "content/public/browser/notification_registrar.h"
21
[email protected]51994b22014-05-30 13:24:2122class ChromeOSMetricsProvider;
[email protected]4a55a712014-06-08 16:50:3423class GoogleUpdateMetricsProviderWin;
[email protected]4a55a712014-06-08 16:50:3424class PluginMetricsProvider;
25class PrefRegistrySimple;
ishermanfc021e912015-03-25 23:33:3326class PrefService;
[email protected]4a55a712014-06-08 16:50:3427
[email protected]1e39b642014-08-15 04:55:4728#if !defined(OS_CHROMEOS) && !defined(OS_IOS)
[email protected]7aee4f7e2014-08-12 01:15:0329class SigninStatusMetricsProvider;
30#endif
31
[email protected]037642f2014-05-29 20:40:5032namespace metrics {
blundellb5c6b5a2015-07-30 20:18:3033class DriveMetricsProvider;
asvitkinecbd420732014-08-26 22:15:4034class MetricsService;
[email protected]037642f2014-05-29 20:40:5035class MetricsStateManager;
gunsch840bc412014-09-18 19:38:0636class ProfilerMetricsProvider;
siggi5e62f7e2014-11-21 21:55:4537} // namespace metrics
[email protected]037642f2014-05-29 20:40:5038
[email protected]5bdaa2d2014-05-19 14:59:5139// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
40// that depends on chrome/.
[email protected]4a55a712014-06-08 16:50:3441class ChromeMetricsServiceClient
42 : public metrics::MetricsServiceClient,
gunsch840bc412014-09-18 19:38:0643 public metrics::TrackingSynchronizerObserver,
[email protected]4a55a712014-06-08 16:50:3444 public content::NotificationObserver {
[email protected]5bdaa2d2014-05-19 14:59:5145 public:
Daniel Chenga542fca2014-10-21 09:51:2946 ~ChromeMetricsServiceClient() override;
[email protected]5bdaa2d2014-05-19 14:59:5147
[email protected]037642f2014-05-29 20:40:5048 // Factory function.
49 static scoped_ptr<ChromeMetricsServiceClient> Create(
50 metrics::MetricsStateManager* state_manager,
51 PrefService* local_state);
52
[email protected]4a55a712014-06-08 16:50:3453 // Registers local state prefs used by this class.
54 static void RegisterPrefs(PrefRegistrySimple* registry);
55
[email protected]5bdaa2d2014-05-19 14:59:5156 // metrics::MetricsServiceClient:
blundellfecea528d2015-10-21 10:10:2257 metrics::MetricsService* GetMetricsService() override;
Daniel Chenga542fca2014-10-21 09:51:2958 void SetMetricsClientId(const std::string& client_id) override;
Mark Mentovaic67fa64f2015-03-24 14:00:0659 void OnRecordingDisabled() override;
Daniel Chenga542fca2014-10-21 09:51:2960 bool IsOffTheRecordSessionActive() override;
61 int32 GetProduct() override;
62 std::string GetApplicationLocale() override;
63 bool GetBrand(std::string* brand_code) override;
64 metrics::SystemProfileProto::Channel GetChannel() override;
65 std::string GetVersionString() override;
66 void OnLogUploadComplete() override;
ishermanb6705682015-08-29 00:01:0067 void InitializeSystemProfileMetrics(
68 const base::Closure& done_callback) override;
69 void CollectFinalMetricsForLog(const base::Closure& done_callback) override;
Daniel Chenga542fca2014-10-21 09:51:2970 scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
mostynb2b52d1db2014-10-07 02:47:1771 const base::Callback<void(int)>& on_upload_complete) override;
gunsch7cbdcb22015-03-13 17:02:0572 base::TimeDelta GetStandardUploadInterval() override;
Daniel Chenga542fca2014-10-21 09:51:2973 base::string16 GetRegistryBackupKey() override;
blundellfecea528d2015-10-21 10:10:2274 void OnPluginLoadingError(const base::FilePath& plugin_path) override;
[email protected]4a55a712014-06-08 16:50:3475
[email protected]5bdaa2d2014-05-19 14:59:5176 private:
[email protected]037642f2014-05-29 20:40:5077 explicit ChromeMetricsServiceClient(
78 metrics::MetricsStateManager* state_manager);
79
[email protected]51994b22014-05-30 13:24:2180 // Completes the two-phase initialization of ChromeMetricsServiceClient.
81 void Initialize();
82
[email protected]4a55a712014-06-08 16:50:3483 // Callback that continues the init task by loading plugin information.
84 void OnInitTaskGotHardwareClass();
85
86 // Called after the Plugin init task has been completed that continues the
87 // init task by launching a task to gather Google Update statistics.
88 void OnInitTaskGotPluginInfo();
89
90 // Called after GoogleUpdate init task has been completed that continues the
ishermanfcf4639e82015-08-26 00:33:4991 // init task by loading drive metrics.
[email protected]4a55a712014-06-08 16:50:3492 void OnInitTaskGotGoogleUpdateData();
93
ishermanfcf4639e82015-08-26 00:33:4994 // Called after the drive metrics init task has been completed that continues
95 // the init task by loading profiler data.
96 void OnInitTaskGotDriveMetrics();
amistry9e2a8b42015-06-13 01:11:2797
isherman213b47c2015-08-28 08:20:4698 // Returns true iff profiler data should be included in the next metrics log.
99 // NOTE: This method is probabilistic and also updates internal state as a
100 // side-effect when called, so it should only be called once per log.
101 bool ShouldIncludeProfilerDataInLog();
102
[email protected]4a55a712014-06-08 16:50:34103 // TrackingSynchronizerObserver:
Daniel Chenga542fca2014-10-21 09:51:29104 void ReceivedProfilerData(
vadimte2de4732015-04-27 21:43:02105 const metrics::ProfilerDataAttributes& attributes,
vadimt379d7fe2015-04-01 00:09:35106 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase,
vadimt379d7fe2015-04-01 00:09:35107 const metrics::ProfilerEvents& past_profiler_events) override;
Daniel Chenga542fca2014-10-21 09:51:29108 void FinishedReceivingProfilerData() override;
[email protected]4a55a712014-06-08 16:50:34109
[email protected]4b4892b2014-05-22 15:06:15110 // Callbacks for various stages of final log info collection. Do not call
111 // these directly.
ishermanfcf4639e82015-08-26 00:33:49112 void CollectFinalHistograms();
[email protected]4b4892b2014-05-22 15:06:15113 void OnMemoryDetailCollectionDone();
114 void OnHistogramSynchronizationDone();
115
[email protected]daed87e2014-05-22 19:41:22116 // Records metrics about the switches present on the command line.
117 void RecordCommandLineMetrics();
118
[email protected]d7ea39e2014-05-22 03:59:18119 // Registers |this| as an observer for notifications which indicate that a
120 // user is performing work. This is useful to allow some features to sleep,
121 // until the machine becomes active, such as precluding UMA uploads unless
122 // there was recent activity.
123 void RegisterForNotifications();
124
125 // content::NotificationObserver:
Daniel Chenga542fca2014-10-21 09:51:29126 void Observe(int type,
127 const content::NotificationSource& source,
128 const content::NotificationDetails& details) override;
[email protected]d7ea39e2014-05-22 03:59:18129
blundell26b95242015-08-17 10:29:24130 // Called when a URL is opened from the Omnibox.
131 void OnURLOpenedFromOmnibox(OmniboxLog* log);
132
[email protected]e2481a702014-05-23 21:06:50133#if defined(OS_WIN)
134 // Counts (and removes) the browser crash dump attempt signals left behind by
135 // any previous browser processes which generated a crash dump.
136 void CountBrowserCrashDumpAttempts();
137#endif // OS_WIN
138
[email protected]4b4892b2014-05-22 15:06:15139 base::ThreadChecker thread_checker_;
140
[email protected]51994b22014-05-30 13:24:21141 // Weak pointer to the MetricsStateManager.
142 metrics::MetricsStateManager* metrics_state_manager_;
143
[email protected]037642f2014-05-29 20:40:50144 // The MetricsService that |this| is a client of.
asvitkinecbd420732014-08-26 22:15:40145 scoped_ptr<metrics::MetricsService> metrics_service_;
[email protected]d7ea39e2014-05-22 03:59:18146
147 content::NotificationRegistrar registrar_;
[email protected]d7ea39e2014-05-22 03:59:18148
[email protected]51994b22014-05-30 13:24:21149 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
150 // that has been registered with MetricsService. On other platforms, is NULL.
151 ChromeOSMetricsProvider* chromeos_metrics_provider_;
152
ishermanb6705682015-08-29 00:01:00153 // Saved callback received from CollectFinalMetricsForLog().
[email protected]4b4892b2014-05-22 15:06:15154 base::Closure collect_final_metrics_done_callback_;
155
156 // Indicates that collect final metrics step is running.
157 bool waiting_for_collect_final_metrics_step_;
158
159 // Number of async histogram fetch requests in progress.
160 int num_async_histogram_fetches_in_progress_;
161
[email protected]4a55a712014-06-08 16:50:34162 // The ProfilerMetricsProvider instance that was registered with
163 // MetricsService. Has the same lifetime as |metrics_service_|.
gunsch840bc412014-09-18 19:38:06164 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
[email protected]4a55a712014-06-08 16:50:34165
166#if defined(ENABLE_PLUGINS)
167 // The PluginMetricsProvider instance that was registered with
168 // MetricsService. Has the same lifetime as |metrics_service_|.
169 PluginMetricsProvider* plugin_metrics_provider_;
170#endif
171
172#if defined(OS_WIN)
173 // The GoogleUpdateMetricsProviderWin instance that was registered with
174 // MetricsService. Has the same lifetime as |metrics_service_|.
175 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
176#endif
177
dbeam64c37842015-03-18 02:23:35178 // The DriveMetricsProvider instance that was registered with MetricsService.
179 // Has the same lifetime as |metrics_service_|.
blundellb5c6b5a2015-07-30 20:18:30180 metrics::DriveMetricsProvider* drive_metrics_provider_;
dbeam64c37842015-03-18 02:23:35181
[email protected]4a55a712014-06-08 16:50:34182 // Callback that is called when initial metrics gathering is complete.
ishermanb6705682015-08-29 00:01:00183 base::Closure finished_init_task_callback_;
[email protected]4a55a712014-06-08 16:50:34184
[email protected]8a5b2da2014-07-07 10:56:51185 // The MemoryGrowthTracker instance that tracks memory usage growth in
186 // MemoryDetails.
187 MemoryGrowthTracker memory_growth_tracker_;
188
gunsch7cbdcb22015-03-13 17:02:05189 // Callback to determine whether or not a cellular network is currently being
190 // used.
191 base::Callback<void(bool*)> cellular_callback_;
192
vadimte2de4732015-04-27 21:43:02193 // Time of this object's creation.
194 const base::TimeTicks start_time_;
195
blundell26b95242015-08-17 10:29:24196 // Subscription for receiving callbacks that a URL was opened from the
197 // omnibox.
198 scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription>
199 omnibox_url_opened_subscription_;
200
isherman213b47c2015-08-28 08:20:46201 // Whether this client has already uploaded profiler data during this session.
202 // Profiler data is uploaded at most once per session.
203 bool has_uploaded_profiler_data_;
204
[email protected]4b4892b2014-05-22 15:06:15205 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
206
[email protected]5bdaa2d2014-05-19 14:59:51207 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
208};
209
210#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_