blob: 81238232efeb920d4db164372ff7685fc4aebdb6 [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"
[email protected]d7ea39e2014-05-22 03:59:1818#include "content/public/browser/notification_observer.h"
19#include "content/public/browser/notification_registrar.h"
20
[email protected]51994b22014-05-30 13:24:2121class ChromeOSMetricsProvider;
dbeam64c37842015-03-18 02:23:3522class DriveMetricsProvider;
[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]4a55a712014-06-08 16:50:3432namespace base {
33class FilePath;
siggi5e62f7e2014-11-21 21:55:4534} // namespace base
[email protected]5bdaa2d2014-05-19 14:59:5135
[email protected]037642f2014-05-29 20:40:5036namespace metrics {
asvitkinecbd420732014-08-26 22:15:4037class MetricsService;
[email protected]037642f2014-05-29 20:40:5038class MetricsStateManager;
gunsch840bc412014-09-18 19:38:0639class ProfilerMetricsProvider;
siggi5e62f7e2014-11-21 21:55:4540} // namespace metrics
[email protected]037642f2014-05-29 20:40:5041
[email protected]5bdaa2d2014-05-19 14:59:5142// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
43// that depends on chrome/.
[email protected]4a55a712014-06-08 16:50:3444class ChromeMetricsServiceClient
45 : public metrics::MetricsServiceClient,
gunsch840bc412014-09-18 19:38:0646 public metrics::TrackingSynchronizerObserver,
[email protected]4a55a712014-06-08 16:50:3447 public content::NotificationObserver {
[email protected]5bdaa2d2014-05-19 14:59:5148 public:
Daniel Chenga542fca2014-10-21 09:51:2949 ~ChromeMetricsServiceClient() override;
[email protected]5bdaa2d2014-05-19 14:59:5150
[email protected]037642f2014-05-29 20:40:5051 // Factory function.
52 static scoped_ptr<ChromeMetricsServiceClient> Create(
53 metrics::MetricsStateManager* state_manager,
54 PrefService* local_state);
55
[email protected]4a55a712014-06-08 16:50:3456 // Registers local state prefs used by this class.
57 static void RegisterPrefs(PrefRegistrySimple* registry);
58
[email protected]5bdaa2d2014-05-19 14:59:5159 // metrics::MetricsServiceClient:
Daniel Chenga542fca2014-10-21 09:51:2960 void SetMetricsClientId(const std::string& client_id) override;
Mark Mentovaic67fa64f2015-03-24 14:00:0661 void OnRecordingDisabled() override;
Daniel Chenga542fca2014-10-21 09:51:2962 bool IsOffTheRecordSessionActive() override;
63 int32 GetProduct() override;
64 std::string GetApplicationLocale() override;
65 bool GetBrand(std::string* brand_code) override;
66 metrics::SystemProfileProto::Channel GetChannel() override;
67 std::string GetVersionString() override;
68 void OnLogUploadComplete() override;
69 void StartGatheringMetrics(const base::Closure& done_callback) override;
70 void CollectFinalMetrics(const base::Closure& done_callback) override;
71 scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
mostynb2b52d1db2014-10-07 02:47:1772 const base::Callback<void(int)>& on_upload_complete) override;
gunsch7cbdcb22015-03-13 17:02:0573 base::TimeDelta GetStandardUploadInterval() override;
Daniel Chenga542fca2014-10-21 09:51:2974 base::string16 GetRegistryBackupKey() override;
[email protected]5bdaa2d2014-05-19 14:59:5175
asvitkinecbd420732014-08-26 22:15:4076 metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
[email protected]d7ea39e2014-05-22 03:59:1877
[email protected]4a55a712014-06-08 16:50:3478 void LogPluginLoadingError(const base::FilePath& plugin_path);
79
[email protected]5bdaa2d2014-05-19 14:59:5180 private:
[email protected]037642f2014-05-29 20:40:5081 explicit ChromeMetricsServiceClient(
82 metrics::MetricsStateManager* state_manager);
83
[email protected]51994b22014-05-30 13:24:2184 // Completes the two-phase initialization of ChromeMetricsServiceClient.
85 void Initialize();
86
[email protected]4a55a712014-06-08 16:50:3487 // Callback that continues the init task by loading plugin information.
88 void OnInitTaskGotHardwareClass();
89
90 // Called after the Plugin init task has been completed that continues the
91 // init task by launching a task to gather Google Update statistics.
92 void OnInitTaskGotPluginInfo();
93
94 // Called after GoogleUpdate init task has been completed that continues the
95 // init task by loading profiler data.
96 void OnInitTaskGotGoogleUpdateData();
97
98 // TrackingSynchronizerObserver:
Daniel Chenga542fca2014-10-21 09:51:2999 void ReceivedProfilerData(
vadimte2de4732015-04-27 21:43:02100 const metrics::ProfilerDataAttributes& attributes,
vadimt379d7fe2015-04-01 00:09:35101 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase,
vadimt379d7fe2015-04-01 00:09:35102 const metrics::ProfilerEvents& past_profiler_events) override;
Daniel Chenga542fca2014-10-21 09:51:29103 void FinishedReceivingProfilerData() override;
[email protected]4a55a712014-06-08 16:50:34104
[email protected]4b4892b2014-05-22 15:06:15105 // Callbacks for various stages of final log info collection. Do not call
106 // these directly.
107 void OnMemoryDetailCollectionDone();
108 void OnHistogramSynchronizationDone();
109
[email protected]daed87e2014-05-22 19:41:22110 // Records metrics about the switches present on the command line.
111 void RecordCommandLineMetrics();
112
[email protected]d7ea39e2014-05-22 03:59:18113 // Registers |this| as an observer for notifications which indicate that a
114 // user is performing work. This is useful to allow some features to sleep,
115 // until the machine becomes active, such as precluding UMA uploads unless
116 // there was recent activity.
117 void RegisterForNotifications();
118
119 // content::NotificationObserver:
Daniel Chenga542fca2014-10-21 09:51:29120 void Observe(int type,
121 const content::NotificationSource& source,
122 const content::NotificationDetails& details) override;
[email protected]d7ea39e2014-05-22 03:59:18123
[email protected]e2481a702014-05-23 21:06:50124#if defined(OS_WIN)
125 // Counts (and removes) the browser crash dump attempt signals left behind by
126 // any previous browser processes which generated a crash dump.
127 void CountBrowserCrashDumpAttempts();
128#endif // OS_WIN
129
[email protected]4b4892b2014-05-22 15:06:15130 base::ThreadChecker thread_checker_;
131
[email protected]51994b22014-05-30 13:24:21132 // Weak pointer to the MetricsStateManager.
133 metrics::MetricsStateManager* metrics_state_manager_;
134
[email protected]037642f2014-05-29 20:40:50135 // The MetricsService that |this| is a client of.
asvitkinecbd420732014-08-26 22:15:40136 scoped_ptr<metrics::MetricsService> metrics_service_;
[email protected]d7ea39e2014-05-22 03:59:18137
138 content::NotificationRegistrar registrar_;
[email protected]d7ea39e2014-05-22 03:59:18139
[email protected]51994b22014-05-30 13:24:21140 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
141 // that has been registered with MetricsService. On other platforms, is NULL.
142 ChromeOSMetricsProvider* chromeos_metrics_provider_;
143
[email protected]4b4892b2014-05-22 15:06:15144 // Saved callback received from CollectFinalMetrics().
145 base::Closure collect_final_metrics_done_callback_;
146
147 // Indicates that collect final metrics step is running.
148 bool waiting_for_collect_final_metrics_step_;
149
150 // Number of async histogram fetch requests in progress.
151 int num_async_histogram_fetches_in_progress_;
152
[email protected]4a55a712014-06-08 16:50:34153 // The ProfilerMetricsProvider instance that was registered with
154 // MetricsService. Has the same lifetime as |metrics_service_|.
gunsch840bc412014-09-18 19:38:06155 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
[email protected]4a55a712014-06-08 16:50:34156
157#if defined(ENABLE_PLUGINS)
158 // The PluginMetricsProvider instance that was registered with
159 // MetricsService. Has the same lifetime as |metrics_service_|.
160 PluginMetricsProvider* plugin_metrics_provider_;
161#endif
162
163#if defined(OS_WIN)
164 // The GoogleUpdateMetricsProviderWin instance that was registered with
165 // MetricsService. Has the same lifetime as |metrics_service_|.
166 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
167#endif
168
dbeam64c37842015-03-18 02:23:35169 // The DriveMetricsProvider instance that was registered with MetricsService.
170 // Has the same lifetime as |metrics_service_|.
171 DriveMetricsProvider* drive_metrics_provider_;
172
[email protected]4a55a712014-06-08 16:50:34173 // Callback that is called when initial metrics gathering is complete.
174 base::Closure finished_gathering_initial_metrics_callback_;
175
[email protected]8a5b2da2014-07-07 10:56:51176 // The MemoryGrowthTracker instance that tracks memory usage growth in
177 // MemoryDetails.
178 MemoryGrowthTracker memory_growth_tracker_;
179
gunsch7cbdcb22015-03-13 17:02:05180 // Callback to determine whether or not a cellular network is currently being
181 // used.
182 base::Callback<void(bool*)> cellular_callback_;
183
vadimte2de4732015-04-27 21:43:02184 // Time of this object's creation.
185 const base::TimeTicks start_time_;
186
[email protected]4b4892b2014-05-22 15:06:15187 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
188
[email protected]5bdaa2d2014-05-19 14:59:51189 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
190};
191
192#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_