blob: 3bc7212816b1a869e7d9478491f30cecf376b542 [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"
amistry9e2a8b42015-06-13 01:11:2712#include "base/containers/scoped_ptr_map.h"
[email protected]037642f2014-05-29 20:40:5013#include "base/memory/scoped_ptr.h"
[email protected]4b4892b2014-05-22 15:06:1514#include "base/memory/weak_ptr.h"
[email protected]d7ea39e2014-05-22 03:59:1815#include "base/threading/thread_checker.h"
asvitkine89406d1f2015-01-17 06:57:1016#include "chrome/browser/metrics/metrics_memory_details.h"
[email protected]5bdaa2d2014-05-19 14:59:5117#include "components/metrics/metrics_service_client.h"
gunsch840bc412014-09-18 19:38:0618#include "components/metrics/profiler/tracking_synchronizer_observer.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;
dbeam64c37842015-03-18 02:23:3523class DriveMetricsProvider;
[email protected]4a55a712014-06-08 16:50:3424class GoogleUpdateMetricsProviderWin;
[email protected]4a55a712014-06-08 16:50:3425class PluginMetricsProvider;
26class PrefRegistrySimple;
ishermanfc021e912015-03-25 23:33:3327class PrefService;
amistry9e2a8b42015-06-13 01:11:2728class ProcessResourceUsage;
[email protected]4a55a712014-06-08 16:50:3429
[email protected]1e39b642014-08-15 04:55:4730#if !defined(OS_CHROMEOS) && !defined(OS_IOS)
[email protected]7aee4f7e2014-08-12 01:15:0331class SigninStatusMetricsProvider;
32#endif
33
[email protected]4a55a712014-06-08 16:50:3434namespace base {
35class FilePath;
siggi5e62f7e2014-11-21 21:55:4536} // namespace base
[email protected]5bdaa2d2014-05-19 14:59:5137
[email protected]037642f2014-05-29 20:40:5038namespace metrics {
asvitkinecbd420732014-08-26 22:15:4039class MetricsService;
[email protected]037642f2014-05-29 20:40:5040class MetricsStateManager;
gunsch840bc412014-09-18 19:38:0641class ProfilerMetricsProvider;
siggi5e62f7e2014-11-21 21:55:4542} // namespace metrics
[email protected]037642f2014-05-29 20:40:5043
[email protected]5bdaa2d2014-05-19 14:59:5144// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
45// that depends on chrome/.
[email protected]4a55a712014-06-08 16:50:3446class ChromeMetricsServiceClient
47 : public metrics::MetricsServiceClient,
gunsch840bc412014-09-18 19:38:0648 public metrics::TrackingSynchronizerObserver,
[email protected]4a55a712014-06-08 16:50:3449 public content::NotificationObserver {
[email protected]5bdaa2d2014-05-19 14:59:5150 public:
Daniel Chenga542fca2014-10-21 09:51:2951 ~ChromeMetricsServiceClient() override;
[email protected]5bdaa2d2014-05-19 14:59:5152
[email protected]037642f2014-05-29 20:40:5053 // Factory function.
54 static scoped_ptr<ChromeMetricsServiceClient> Create(
55 metrics::MetricsStateManager* state_manager,
56 PrefService* local_state);
57
[email protected]4a55a712014-06-08 16:50:3458 // Registers local state prefs used by this class.
59 static void RegisterPrefs(PrefRegistrySimple* registry);
60
[email protected]5bdaa2d2014-05-19 14:59:5161 // metrics::MetricsServiceClient:
Daniel Chenga542fca2014-10-21 09:51:2962 void SetMetricsClientId(const std::string& client_id) override;
Mark Mentovaic67fa64f2015-03-24 14:00:0663 void OnRecordingDisabled() override;
Daniel Chenga542fca2014-10-21 09:51:2964 bool IsOffTheRecordSessionActive() override;
65 int32 GetProduct() override;
66 std::string GetApplicationLocale() override;
67 bool GetBrand(std::string* brand_code) override;
68 metrics::SystemProfileProto::Channel GetChannel() override;
69 std::string GetVersionString() override;
70 void OnLogUploadComplete() override;
71 void StartGatheringMetrics(const base::Closure& done_callback) override;
72 void CollectFinalMetrics(const base::Closure& done_callback) override;
73 scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
mostynb2b52d1db2014-10-07 02:47:1774 const base::Callback<void(int)>& on_upload_complete) override;
gunsch7cbdcb22015-03-13 17:02:0575 base::TimeDelta GetStandardUploadInterval() override;
Daniel Chenga542fca2014-10-21 09:51:2976 base::string16 GetRegistryBackupKey() override;
[email protected]5bdaa2d2014-05-19 14:59:5177
asvitkinecbd420732014-08-26 22:15:4078 metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
[email protected]d7ea39e2014-05-22 03:59:1879
[email protected]4a55a712014-06-08 16:50:3480 void LogPluginLoadingError(const base::FilePath& plugin_path);
81
[email protected]5bdaa2d2014-05-19 14:59:5182 private:
[email protected]037642f2014-05-29 20:40:5083 explicit ChromeMetricsServiceClient(
84 metrics::MetricsStateManager* state_manager);
85
[email protected]51994b22014-05-30 13:24:2186 // Completes the two-phase initialization of ChromeMetricsServiceClient.
87 void Initialize();
88
[email protected]4a55a712014-06-08 16:50:3489 // Callback that continues the init task by loading plugin information.
90 void OnInitTaskGotHardwareClass();
91
92 // Called after the Plugin init task has been completed that continues the
93 // init task by launching a task to gather Google Update statistics.
94 void OnInitTaskGotPluginInfo();
95
96 // Called after GoogleUpdate init task has been completed that continues the
97 // init task by loading profiler data.
98 void OnInitTaskGotGoogleUpdateData();
99
amistry9e2a8b42015-06-13 01:11:27100 // Called after WebCache statistics have been received from a renderer
101 // process.
102 void OnWebCacheStatsRefresh(int host_id);
103
[email protected]4a55a712014-06-08 16:50:34104 // TrackingSynchronizerObserver:
Daniel Chenga542fca2014-10-21 09:51:29105 void ReceivedProfilerData(
vadimte2de4732015-04-27 21:43:02106 const metrics::ProfilerDataAttributes& attributes,
vadimt379d7fe2015-04-01 00:09:35107 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase,
vadimt379d7fe2015-04-01 00:09:35108 const metrics::ProfilerEvents& past_profiler_events) override;
Daniel Chenga542fca2014-10-21 09:51:29109 void FinishedReceivingProfilerData() override;
[email protected]4a55a712014-06-08 16:50:34110
[email protected]4b4892b2014-05-22 15:06:15111 // Callbacks for various stages of final log info collection. Do not call
112 // these directly.
113 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
[email protected]e2481a702014-05-23 21:06:50130#if defined(OS_WIN)
131 // Counts (and removes) the browser crash dump attempt signals left behind by
132 // any previous browser processes which generated a crash dump.
133 void CountBrowserCrashDumpAttempts();
134#endif // OS_WIN
135
[email protected]4b4892b2014-05-22 15:06:15136 base::ThreadChecker thread_checker_;
137
[email protected]51994b22014-05-30 13:24:21138 // Weak pointer to the MetricsStateManager.
139 metrics::MetricsStateManager* metrics_state_manager_;
140
[email protected]037642f2014-05-29 20:40:50141 // The MetricsService that |this| is a client of.
asvitkinecbd420732014-08-26 22:15:40142 scoped_ptr<metrics::MetricsService> metrics_service_;
[email protected]d7ea39e2014-05-22 03:59:18143
144 content::NotificationRegistrar registrar_;
[email protected]d7ea39e2014-05-22 03:59:18145
[email protected]51994b22014-05-30 13:24:21146 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
147 // that has been registered with MetricsService. On other platforms, is NULL.
148 ChromeOSMetricsProvider* chromeos_metrics_provider_;
149
[email protected]4b4892b2014-05-22 15:06:15150 // Saved callback received from CollectFinalMetrics().
151 base::Closure collect_final_metrics_done_callback_;
152
153 // Indicates that collect final metrics step is running.
154 bool waiting_for_collect_final_metrics_step_;
155
156 // Number of async histogram fetch requests in progress.
157 int num_async_histogram_fetches_in_progress_;
158
[email protected]4a55a712014-06-08 16:50:34159 // The ProfilerMetricsProvider instance that was registered with
160 // MetricsService. Has the same lifetime as |metrics_service_|.
gunsch840bc412014-09-18 19:38:06161 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
[email protected]4a55a712014-06-08 16:50:34162
163#if defined(ENABLE_PLUGINS)
164 // The PluginMetricsProvider instance that was registered with
165 // MetricsService. Has the same lifetime as |metrics_service_|.
166 PluginMetricsProvider* plugin_metrics_provider_;
167#endif
168
169#if defined(OS_WIN)
170 // The GoogleUpdateMetricsProviderWin instance that was registered with
171 // MetricsService. Has the same lifetime as |metrics_service_|.
172 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
173#endif
174
dbeam64c37842015-03-18 02:23:35175 // The DriveMetricsProvider instance that was registered with MetricsService.
176 // Has the same lifetime as |metrics_service_|.
177 DriveMetricsProvider* drive_metrics_provider_;
178
[email protected]4a55a712014-06-08 16:50:34179 // Callback that is called when initial metrics gathering is complete.
180 base::Closure finished_gathering_initial_metrics_callback_;
181
[email protected]8a5b2da2014-07-07 10:56:51182 // The MemoryGrowthTracker instance that tracks memory usage growth in
183 // MemoryDetails.
184 MemoryGrowthTracker memory_growth_tracker_;
185
gunsch7cbdcb22015-03-13 17:02:05186 // Callback to determine whether or not a cellular network is currently being
187 // used.
188 base::Callback<void(bool*)> cellular_callback_;
189
vadimte2de4732015-04-27 21:43:02190 // Time of this object's creation.
191 const base::TimeTicks start_time_;
192
amistry9e2a8b42015-06-13 01:11:27193 // Map of ProcessResourceUsage from render process host IDs.
194 ScopedPtrMap<int, scoped_ptr<ProcessResourceUsage>> host_resource_usage_map_;
195
[email protected]4b4892b2014-05-22 15:06:15196 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
197
[email protected]5bdaa2d2014-05-19 14:59:51198 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
199};
200
201#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_