blob: c2f1c6e8bb2635ac94eec52cdf81e7998415d383 [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]73929422014-05-22 08:19:0516#include "chrome/browser/metrics/network_stats_uploader.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;
[email protected]4a55a712014-06-08 16:50:3423class GoogleUpdateMetricsProviderWin;
[email protected]4a55a712014-06-08 16:50:3424class PluginMetricsProvider;
25class PrefRegistrySimple;
[email protected]4a55a712014-06-08 16:50:3426
[email protected]1e39b642014-08-15 04:55:4727#if !defined(OS_CHROMEOS) && !defined(OS_IOS)
[email protected]7aee4f7e2014-08-12 01:15:0328class SigninStatusMetricsProvider;
29#endif
30
[email protected]4a55a712014-06-08 16:50:3431namespace base {
32class FilePath;
siggi5e62f7e2014-11-21 21:55:4533} // namespace base
[email protected]5bdaa2d2014-05-19 14:59:5134
[email protected]037642f2014-05-29 20:40:5035namespace metrics {
asvitkinecbd420732014-08-26 22:15:4036class MetricsService;
[email protected]037642f2014-05-29 20:40:5037class MetricsStateManager;
gunsch840bc412014-09-18 19:38:0638class ProfilerMetricsProvider;
siggi5e62f7e2014-11-21 21:55:4539} // namespace metrics
[email protected]037642f2014-05-29 20:40:5040
[email protected]5bdaa2d2014-05-19 14:59:5141// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
42// that depends on chrome/.
[email protected]4a55a712014-06-08 16:50:3443class ChromeMetricsServiceClient
44 : public metrics::MetricsServiceClient,
gunsch840bc412014-09-18 19:38:0645 public metrics::TrackingSynchronizerObserver,
[email protected]4a55a712014-06-08 16:50:3446 public content::NotificationObserver {
[email protected]5bdaa2d2014-05-19 14:59:5147 public:
Daniel Chenga542fca2014-10-21 09:51:2948 ~ChromeMetricsServiceClient() override;
[email protected]5bdaa2d2014-05-19 14:59:5149
[email protected]037642f2014-05-29 20:40:5050 // Factory function.
51 static scoped_ptr<ChromeMetricsServiceClient> Create(
52 metrics::MetricsStateManager* state_manager,
53 PrefService* local_state);
54
[email protected]4a55a712014-06-08 16:50:3455 // Registers local state prefs used by this class.
56 static void RegisterPrefs(PrefRegistrySimple* registry);
57
[email protected]5bdaa2d2014-05-19 14:59:5158 // metrics::MetricsServiceClient:
Daniel Chenga542fca2014-10-21 09:51:2959 void SetMetricsClientId(const std::string& client_id) override;
60 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;
67 void StartGatheringMetrics(const base::Closure& done_callback) override;
68 void CollectFinalMetrics(const base::Closure& done_callback) override;
69 scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
mostynb2b52d1db2014-10-07 02:47:1770 const base::Callback<void(int)>& on_upload_complete) override;
gunsch7cbdcb22015-03-13 17:02:0571 base::TimeDelta GetStandardUploadInterval() override;
Daniel Chenga542fca2014-10-21 09:51:2972 base::string16 GetRegistryBackupKey() override;
[email protected]5bdaa2d2014-05-19 14:59:5173
asvitkinecbd420732014-08-26 22:15:4074 metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
[email protected]d7ea39e2014-05-22 03:59:1875
[email protected]4a55a712014-06-08 16:50:3476 void LogPluginLoadingError(const base::FilePath& plugin_path);
77
[email protected]5bdaa2d2014-05-19 14:59:5178 private:
[email protected]037642f2014-05-29 20:40:5079 explicit ChromeMetricsServiceClient(
80 metrics::MetricsStateManager* state_manager);
81
[email protected]51994b22014-05-30 13:24:2182 // Completes the two-phase initialization of ChromeMetricsServiceClient.
83 void Initialize();
84
[email protected]4a55a712014-06-08 16:50:3485 // Callback that continues the init task by loading plugin information.
86 void OnInitTaskGotHardwareClass();
87
88 // Called after the Plugin init task has been completed that continues the
89 // init task by launching a task to gather Google Update statistics.
90 void OnInitTaskGotPluginInfo();
91
92 // Called after GoogleUpdate init task has been completed that continues the
93 // init task by loading profiler data.
94 void OnInitTaskGotGoogleUpdateData();
95
96 // TrackingSynchronizerObserver:
Daniel Chenga542fca2014-10-21 09:51:2997 void ReceivedProfilerData(
[email protected]4a55a712014-06-08 16:50:3498 const tracked_objects::ProcessDataSnapshot& process_data,
mostynb2b52d1db2014-10-07 02:47:1799 int process_type) override;
Daniel Chenga542fca2014-10-21 09:51:29100 void FinishedReceivingProfilerData() override;
[email protected]4a55a712014-06-08 16:50:34101
[email protected]4b4892b2014-05-22 15:06:15102 // Callbacks for various stages of final log info collection. Do not call
103 // these directly.
104 void OnMemoryDetailCollectionDone();
105 void OnHistogramSynchronizationDone();
106
[email protected]daed87e2014-05-22 19:41:22107 // Records metrics about the switches present on the command line.
108 void RecordCommandLineMetrics();
109
[email protected]d7ea39e2014-05-22 03:59:18110 // Registers |this| as an observer for notifications which indicate that a
111 // user is performing work. This is useful to allow some features to sleep,
112 // until the machine becomes active, such as precluding UMA uploads unless
113 // there was recent activity.
114 void RegisterForNotifications();
115
116 // content::NotificationObserver:
Daniel Chenga542fca2014-10-21 09:51:29117 void Observe(int type,
118 const content::NotificationSource& source,
119 const content::NotificationDetails& details) override;
[email protected]d7ea39e2014-05-22 03:59:18120
[email protected]e2481a702014-05-23 21:06:50121#if defined(OS_WIN)
122 // Counts (and removes) the browser crash dump attempt signals left behind by
123 // any previous browser processes which generated a crash dump.
124 void CountBrowserCrashDumpAttempts();
125#endif // OS_WIN
126
[email protected]4b4892b2014-05-22 15:06:15127 base::ThreadChecker thread_checker_;
128
[email protected]51994b22014-05-30 13:24:21129 // Weak pointer to the MetricsStateManager.
130 metrics::MetricsStateManager* metrics_state_manager_;
131
[email protected]037642f2014-05-29 20:40:50132 // The MetricsService that |this| is a client of.
asvitkinecbd420732014-08-26 22:15:40133 scoped_ptr<metrics::MetricsService> metrics_service_;
[email protected]d7ea39e2014-05-22 03:59:18134
135 content::NotificationRegistrar registrar_;
[email protected]d7ea39e2014-05-22 03:59:18136
[email protected]51994b22014-05-30 13:24:21137 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
138 // that has been registered with MetricsService. On other platforms, is NULL.
139 ChromeOSMetricsProvider* chromeos_metrics_provider_;
140
[email protected]73929422014-05-22 08:19:05141 NetworkStatsUploader network_stats_uploader_;
142
[email protected]4b4892b2014-05-22 15:06:15143 // Saved callback received from CollectFinalMetrics().
144 base::Closure collect_final_metrics_done_callback_;
145
146 // Indicates that collect final metrics step is running.
147 bool waiting_for_collect_final_metrics_step_;
148
149 // Number of async histogram fetch requests in progress.
150 int num_async_histogram_fetches_in_progress_;
151
[email protected]4a55a712014-06-08 16:50:34152 // The ProfilerMetricsProvider instance that was registered with
153 // MetricsService. Has the same lifetime as |metrics_service_|.
gunsch840bc412014-09-18 19:38:06154 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
[email protected]4a55a712014-06-08 16:50:34155
156#if defined(ENABLE_PLUGINS)
157 // The PluginMetricsProvider instance that was registered with
158 // MetricsService. Has the same lifetime as |metrics_service_|.
159 PluginMetricsProvider* plugin_metrics_provider_;
160#endif
161
162#if defined(OS_WIN)
163 // The GoogleUpdateMetricsProviderWin instance that was registered with
164 // MetricsService. Has the same lifetime as |metrics_service_|.
165 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
166#endif
167
168 // Callback that is called when initial metrics gathering is complete.
169 base::Closure finished_gathering_initial_metrics_callback_;
170
[email protected]8a5b2da2014-07-07 10:56:51171 // The MemoryGrowthTracker instance that tracks memory usage growth in
172 // MemoryDetails.
173 MemoryGrowthTracker memory_growth_tracker_;
174
gunsch7cbdcb22015-03-13 17:02:05175 // Callback to determine whether or not a cellular network is currently being
176 // used.
177 base::Callback<void(bool*)> cellular_callback_;
178
[email protected]4b4892b2014-05-22 15:06:15179 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
180
[email protected]5bdaa2d2014-05-19 14:59:51181 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
182};
183
184#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_