blob: c6d116635ad0b0b5ed51c256f4d688b224fe1e32 [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"
[email protected]8a5b2da2014-07-07 10:56:5115#include "chrome/browser/memory_details.h"
[email protected]73929422014-05-22 08:19:0516#include "chrome/browser/metrics/network_stats_uploader.h"
[email protected]4a55a712014-06-08 16:50:3417#include "chrome/browser/metrics/tracking_synchronizer_observer.h"
[email protected]5bdaa2d2014-05-19 14:59:5118#include "components/metrics/metrics_service_client.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]d7ea39e2014-05-22 03:59:1824class MetricsService;
[email protected]4a55a712014-06-08 16:50:3425class PluginMetricsProvider;
26class PrefRegistrySimple;
27class ProfilerMetricsProvider;
28
29namespace base {
30class FilePath;
31}
[email protected]5bdaa2d2014-05-19 14:59:5132
[email protected]037642f2014-05-29 20:40:5033namespace metrics {
34class MetricsStateManager;
35}
36
[email protected]5bdaa2d2014-05-19 14:59:5137// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
38// that depends on chrome/.
[email protected]4a55a712014-06-08 16:50:3439class ChromeMetricsServiceClient
40 : public metrics::MetricsServiceClient,
41 public chrome_browser_metrics::TrackingSynchronizerObserver,
42 public content::NotificationObserver {
[email protected]5bdaa2d2014-05-19 14:59:5143 public:
[email protected]5bdaa2d2014-05-19 14:59:5144 virtual ~ChromeMetricsServiceClient();
45
[email protected]037642f2014-05-29 20:40:5046 // Factory function.
47 static scoped_ptr<ChromeMetricsServiceClient> Create(
48 metrics::MetricsStateManager* state_manager,
49 PrefService* local_state);
50
[email protected]4a55a712014-06-08 16:50:3451 // Registers local state prefs used by this class.
52 static void RegisterPrefs(PrefRegistrySimple* registry);
53
[email protected]5bdaa2d2014-05-19 14:59:5154 // metrics::MetricsServiceClient:
55 virtual void SetClientID(const std::string& client_id) OVERRIDE;
56 virtual bool IsOffTheRecordSessionActive() OVERRIDE;
57 virtual std::string GetApplicationLocale() OVERRIDE;
58 virtual bool GetBrand(std::string* brand_code) OVERRIDE;
59 virtual metrics::SystemProfileProto::Channel GetChannel() OVERRIDE;
60 virtual std::string GetVersionString() OVERRIDE;
[email protected]91b1d912014-06-05 10:52:0861 virtual int64 GetInstallDate() OVERRIDE;
[email protected]73929422014-05-22 08:19:0562 virtual void OnLogUploadComplete() OVERRIDE;
[email protected]06c10832014-05-23 10:55:5563 virtual void StartGatheringMetrics(
64 const base::Closure& done_callback) OVERRIDE;
[email protected]4b4892b2014-05-22 15:06:1565 virtual void CollectFinalMetrics(const base::Closure& done_callback)
66 OVERRIDE;
[email protected]0d5a61a82014-05-31 22:28:3467 virtual scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
68 const std::string& server_url,
69 const std::string& mime_type,
70 const base::Callback<void(int)>& on_upload_complete) OVERRIDE;
[email protected]5bdaa2d2014-05-19 14:59:5171
[email protected]037642f2014-05-29 20:40:5072 MetricsService* metrics_service() { return metrics_service_.get(); }
[email protected]d7ea39e2014-05-22 03:59:1873
[email protected]4a55a712014-06-08 16:50:3474 void LogPluginLoadingError(const base::FilePath& plugin_path);
75
[email protected]5bdaa2d2014-05-19 14:59:5176 private:
[email protected]037642f2014-05-29 20:40:5077 explicit ChromeMetricsServiceClient(
78 metrics::MetricsStateManager* state_manager);
79
[email protected]51994b22014-05-30 13:24:2180 // Completes the two-phase initialization of ChromeMetricsServiceClient.
81 void Initialize();
82
[email protected]4a55a712014-06-08 16:50:3483 // Callback that continues the init task by loading plugin information.
84 void OnInitTaskGotHardwareClass();
85
86 // Called after the Plugin init task has been completed that continues the
87 // init task by launching a task to gather Google Update statistics.
88 void OnInitTaskGotPluginInfo();
89
90 // Called after GoogleUpdate init task has been completed that continues the
91 // init task by loading profiler data.
92 void OnInitTaskGotGoogleUpdateData();
93
94 // TrackingSynchronizerObserver:
95 virtual void ReceivedProfilerData(
96 const tracked_objects::ProcessDataSnapshot& process_data,
97 int process_type) OVERRIDE;
98 virtual void FinishedReceivingProfilerData() OVERRIDE;
99
[email protected]4b4892b2014-05-22 15:06:15100 // Callbacks for various stages of final log info collection. Do not call
101 // these directly.
102 void OnMemoryDetailCollectionDone();
103 void OnHistogramSynchronizationDone();
104
[email protected]daed87e2014-05-22 19:41:22105 // Records metrics about the switches present on the command line.
106 void RecordCommandLineMetrics();
107
[email protected]d7ea39e2014-05-22 03:59:18108 // Registers |this| as an observer for notifications which indicate that a
109 // user is performing work. This is useful to allow some features to sleep,
110 // until the machine becomes active, such as precluding UMA uploads unless
111 // there was recent activity.
112 void RegisterForNotifications();
113
114 // content::NotificationObserver:
115 virtual void Observe(int type,
116 const content::NotificationSource& source,
117 const content::NotificationDetails& details) OVERRIDE;
118
[email protected]e2481a702014-05-23 21:06:50119#if defined(OS_WIN)
120 // Counts (and removes) the browser crash dump attempt signals left behind by
121 // any previous browser processes which generated a crash dump.
122 void CountBrowserCrashDumpAttempts();
123#endif // OS_WIN
124
[email protected]4b4892b2014-05-22 15:06:15125 base::ThreadChecker thread_checker_;
126
[email protected]51994b22014-05-30 13:24:21127 // Weak pointer to the MetricsStateManager.
128 metrics::MetricsStateManager* metrics_state_manager_;
129
[email protected]037642f2014-05-29 20:40:50130 // The MetricsService that |this| is a client of.
131 scoped_ptr<MetricsService> metrics_service_;
[email protected]d7ea39e2014-05-22 03:59:18132
133 content::NotificationRegistrar registrar_;
[email protected]d7ea39e2014-05-22 03:59:18134
[email protected]51994b22014-05-30 13:24:21135 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
136 // that has been registered with MetricsService. On other platforms, is NULL.
137 ChromeOSMetricsProvider* chromeos_metrics_provider_;
138
[email protected]73929422014-05-22 08:19:05139 NetworkStatsUploader network_stats_uploader_;
140
[email protected]4b4892b2014-05-22 15:06:15141 // Saved callback received from CollectFinalMetrics().
142 base::Closure collect_final_metrics_done_callback_;
143
144 // Indicates that collect final metrics step is running.
145 bool waiting_for_collect_final_metrics_step_;
146
147 // Number of async histogram fetch requests in progress.
148 int num_async_histogram_fetches_in_progress_;
149
[email protected]4a55a712014-06-08 16:50:34150 // The ProfilerMetricsProvider instance that was registered with
151 // MetricsService. Has the same lifetime as |metrics_service_|.
152 ProfilerMetricsProvider* profiler_metrics_provider_;
153
154#if defined(ENABLE_PLUGINS)
155 // The PluginMetricsProvider instance that was registered with
156 // MetricsService. Has the same lifetime as |metrics_service_|.
157 PluginMetricsProvider* plugin_metrics_provider_;
158#endif
159
160#if defined(OS_WIN)
161 // The GoogleUpdateMetricsProviderWin instance that was registered with
162 // MetricsService. Has the same lifetime as |metrics_service_|.
163 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
164#endif
165
166 // Callback that is called when initial metrics gathering is complete.
167 base::Closure finished_gathering_initial_metrics_callback_;
168
[email protected]8a5b2da2014-07-07 10:56:51169 // The MemoryGrowthTracker instance that tracks memory usage growth in
170 // MemoryDetails.
171 MemoryGrowthTracker memory_growth_tracker_;
172
[email protected]4b4892b2014-05-22 15:06:15173 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
174
[email protected]5bdaa2d2014-05-19 14:59:51175 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
176};
177
178#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_