Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_metrics_service_client.h
blob0ef629493e22d5045f54a00d5fcce73796783c58
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/memory_details.h"
16 #include "chrome/browser/metrics/network_stats_uploader.h"
17 #include "components/metrics/metrics_service_client.h"
18 #include "components/metrics/profiler/tracking_synchronizer_observer.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
22 class ChromeOSMetricsProvider;
23 class GoogleUpdateMetricsProviderWin;
24 class PluginMetricsProvider;
25 class PrefRegistrySimple;
27 #if !defined(OS_CHROMEOS) && !defined(OS_IOS)
28 class SigninStatusMetricsProvider;
29 #endif
31 namespace base {
32 class FilePath;
35 namespace metrics {
36 class MetricsService;
37 class MetricsStateManager;
38 class ProfilerMetricsProvider;
41 // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
42 // that depends on chrome/.
43 class ChromeMetricsServiceClient
44 : public metrics::MetricsServiceClient,
45 public metrics::TrackingSynchronizerObserver,
46 public content::NotificationObserver {
47 public:
48 virtual ~ChromeMetricsServiceClient();
50 // Factory function.
51 static scoped_ptr<ChromeMetricsServiceClient> Create(
52 metrics::MetricsStateManager* state_manager,
53 PrefService* local_state);
55 // Registers local state prefs used by this class.
56 static void RegisterPrefs(PrefRegistrySimple* registry);
58 // metrics::MetricsServiceClient:
59 virtual void SetMetricsClientId(const std::string& client_id) override;
60 virtual bool IsOffTheRecordSessionActive() override;
61 virtual int32 GetProduct() override;
62 virtual std::string GetApplicationLocale() override;
63 virtual bool GetBrand(std::string* brand_code) override;
64 virtual metrics::SystemProfileProto::Channel GetChannel() override;
65 virtual std::string GetVersionString() override;
66 virtual void OnLogUploadComplete() override;
67 virtual void StartGatheringMetrics(
68 const base::Closure& done_callback) override;
69 virtual void CollectFinalMetrics(const base::Closure& done_callback)
70 override;
71 virtual scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
72 const std::string& server_url,
73 const std::string& mime_type,
74 const base::Callback<void(int)>& on_upload_complete) override;
75 virtual base::string16 GetRegistryBackupKey() override;
77 metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
79 void LogPluginLoadingError(const base::FilePath& plugin_path);
81 private:
82 explicit ChromeMetricsServiceClient(
83 metrics::MetricsStateManager* state_manager);
85 // Completes the two-phase initialization of ChromeMetricsServiceClient.
86 void Initialize();
88 // Callback that continues the init task by loading plugin information.
89 void OnInitTaskGotHardwareClass();
91 // Called after the Plugin init task has been completed that continues the
92 // init task by launching a task to gather Google Update statistics.
93 void OnInitTaskGotPluginInfo();
95 // Called after GoogleUpdate init task has been completed that continues the
96 // init task by loading profiler data.
97 void OnInitTaskGotGoogleUpdateData();
99 // TrackingSynchronizerObserver:
100 virtual void ReceivedProfilerData(
101 const tracked_objects::ProcessDataSnapshot& process_data,
102 int process_type) override;
103 virtual void FinishedReceivingProfilerData() override;
105 // Callbacks for various stages of final log info collection. Do not call
106 // these directly.
107 void OnMemoryDetailCollectionDone();
108 void OnHistogramSynchronizationDone();
110 // Records metrics about the switches present on the command line.
111 void RecordCommandLineMetrics();
113 // 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();
119 // content::NotificationObserver:
120 virtual void Observe(int type,
121 const content::NotificationSource& source,
122 const content::NotificationDetails& details) override;
124 #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
130 base::ThreadChecker thread_checker_;
132 // Weak pointer to the MetricsStateManager.
133 metrics::MetricsStateManager* metrics_state_manager_;
135 // The MetricsService that |this| is a client of.
136 scoped_ptr<metrics::MetricsService> metrics_service_;
138 content::NotificationRegistrar registrar_;
140 // 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_;
144 NetworkStatsUploader network_stats_uploader_;
146 // Saved callback received from CollectFinalMetrics().
147 base::Closure collect_final_metrics_done_callback_;
149 // Indicates that collect final metrics step is running.
150 bool waiting_for_collect_final_metrics_step_;
152 // Number of async histogram fetch requests in progress.
153 int num_async_histogram_fetches_in_progress_;
155 // The ProfilerMetricsProvider instance that was registered with
156 // MetricsService. Has the same lifetime as |metrics_service_|.
157 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
159 #if defined(ENABLE_PLUGINS)
160 // The PluginMetricsProvider instance that was registered with
161 // MetricsService. Has the same lifetime as |metrics_service_|.
162 PluginMetricsProvider* plugin_metrics_provider_;
163 #endif
165 #if defined(OS_WIN)
166 // The GoogleUpdateMetricsProviderWin instance that was registered with
167 // MetricsService. Has the same lifetime as |metrics_service_|.
168 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
169 #endif
171 #if !defined(OS_CHROMEOS) && !defined(OS_IOS)
172 // The SigninStatusMetricsProvider instance that was registered with
173 // MetricsService. Has the same lifetime as |metrics_service_|.
174 SigninStatusMetricsProvider* signin_status_metrics_provider_;
175 #endif
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 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
186 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
189 #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_