Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_metrics_service_client.h
blob7456d1dc15065b07d4d2322ff0671c26a8eeb1fc
1 // 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.
5 #ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
6 #define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/metrics/metrics_memory_details.h"
16 #include "components/metrics/metrics_service_client.h"
17 #include "components/metrics/profiler/tracking_synchronizer_observer.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
21 class ChromeOSMetricsProvider;
22 class DriveMetricsProvider;
23 class GoogleUpdateMetricsProviderWin;
24 class PluginMetricsProvider;
25 class PrefRegistrySimple;
26 class PrefService;
28 #if !defined(OS_CHROMEOS) && !defined(OS_IOS)
29 class SigninStatusMetricsProvider;
30 #endif
32 namespace base {
33 class FilePath;
34 } // namespace base
36 namespace metrics {
37 class MetricsService;
38 class MetricsStateManager;
39 class ProfilerMetricsProvider;
40 } // namespace metrics
42 // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
43 // that depends on chrome/.
44 class ChromeMetricsServiceClient
45 : public metrics::MetricsServiceClient,
46 public metrics::TrackingSynchronizerObserver,
47 public content::NotificationObserver {
48 public:
49 ~ChromeMetricsServiceClient() override;
51 // Factory function.
52 static scoped_ptr<ChromeMetricsServiceClient> Create(
53 metrics::MetricsStateManager* state_manager,
54 PrefService* local_state);
56 // Registers local state prefs used by this class.
57 static void RegisterPrefs(PrefRegistrySimple* registry);
59 // metrics::MetricsServiceClient:
60 void SetMetricsClientId(const std::string& client_id) override;
61 void OnRecordingDisabled() override;
62 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(
72 const base::Callback<void(int)>& on_upload_complete) override;
73 base::TimeDelta GetStandardUploadInterval() override;
74 base::string16 GetRegistryBackupKey() override;
76 metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
78 void LogPluginLoadingError(const base::FilePath& plugin_path);
80 private:
81 explicit ChromeMetricsServiceClient(
82 metrics::MetricsStateManager* state_manager);
84 // Completes the two-phase initialization of ChromeMetricsServiceClient.
85 void Initialize();
87 // Callback that continues the init task by loading plugin information.
88 void OnInitTaskGotHardwareClass();
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();
94 // Called after GoogleUpdate init task has been completed that continues the
95 // init task by loading profiler data.
96 void OnInitTaskGotGoogleUpdateData();
98 // TrackingSynchronizerObserver:
99 void ReceivedProfilerData(
100 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase,
101 base::ProcessId process_id,
102 content::ProcessType process_type,
103 int profiling_phase,
104 base::TimeDelta phase_start,
105 base::TimeDelta phase_finish,
106 const metrics::ProfilerEvents& past_profiler_events) override;
107 void FinishedReceivingProfilerData() override;
109 // Callbacks for various stages of final log info collection. Do not call
110 // these directly.
111 void OnMemoryDetailCollectionDone();
112 void OnHistogramSynchronizationDone();
114 // Records metrics about the switches present on the command line.
115 void RecordCommandLineMetrics();
117 // Registers |this| as an observer for notifications which indicate that a
118 // user is performing work. This is useful to allow some features to sleep,
119 // until the machine becomes active, such as precluding UMA uploads unless
120 // there was recent activity.
121 void RegisterForNotifications();
123 // content::NotificationObserver:
124 void Observe(int type,
125 const content::NotificationSource& source,
126 const content::NotificationDetails& details) override;
128 #if defined(OS_WIN)
129 // Counts (and removes) the browser crash dump attempt signals left behind by
130 // any previous browser processes which generated a crash dump.
131 void CountBrowserCrashDumpAttempts();
132 #endif // OS_WIN
134 base::ThreadChecker thread_checker_;
136 // Weak pointer to the MetricsStateManager.
137 metrics::MetricsStateManager* metrics_state_manager_;
139 // The MetricsService that |this| is a client of.
140 scoped_ptr<metrics::MetricsService> metrics_service_;
142 content::NotificationRegistrar registrar_;
144 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
145 // that has been registered with MetricsService. On other platforms, is NULL.
146 ChromeOSMetricsProvider* chromeos_metrics_provider_;
148 // Saved callback received from CollectFinalMetrics().
149 base::Closure collect_final_metrics_done_callback_;
151 // Indicates that collect final metrics step is running.
152 bool waiting_for_collect_final_metrics_step_;
154 // Number of async histogram fetch requests in progress.
155 int num_async_histogram_fetches_in_progress_;
157 // The ProfilerMetricsProvider instance that was registered with
158 // MetricsService. Has the same lifetime as |metrics_service_|.
159 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
161 #if defined(ENABLE_PLUGINS)
162 // The PluginMetricsProvider instance that was registered with
163 // MetricsService. Has the same lifetime as |metrics_service_|.
164 PluginMetricsProvider* plugin_metrics_provider_;
165 #endif
167 #if defined(OS_WIN)
168 // The GoogleUpdateMetricsProviderWin instance that was registered with
169 // MetricsService. Has the same lifetime as |metrics_service_|.
170 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
171 #endif
173 // The DriveMetricsProvider instance that was registered with MetricsService.
174 // Has the same lifetime as |metrics_service_|.
175 DriveMetricsProvider* drive_metrics_provider_;
177 // Callback that is called when initial metrics gathering is complete.
178 base::Closure finished_gathering_initial_metrics_callback_;
180 // The MemoryGrowthTracker instance that tracks memory usage growth in
181 // MemoryDetails.
182 MemoryGrowthTracker memory_growth_tracker_;
184 // Callback to determine whether or not a cellular network is currently being
185 // used.
186 base::Callback<void(bool*)> cellular_callback_;
188 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
190 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
193 #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_