[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 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. |
| 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] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 14 | #include "base/threading/thread_checker.h" |
[email protected] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 15 | #include "chrome/browser/metrics/network_stats_uploader.h" |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 16 | #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 17 | #include "components/metrics/metrics_service_client.h" |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 18 | #include "content/public/browser/notification_observer.h" |
| 19 | #include "content/public/browser/notification_registrar.h" |
| 20 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 21 | class ChromeOSMetricsProvider; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 22 | class GoogleUpdateMetricsProviderWin; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 23 | class MetricsService; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 24 | class PluginMetricsProvider; |
| 25 | class PrefRegistrySimple; |
| 26 | class ProfilerMetricsProvider; |
| 27 | |
| 28 | namespace base { |
| 29 | class FilePath; |
| 30 | } |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 31 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 32 | namespace metrics { |
| 33 | class MetricsStateManager; |
| 34 | } |
| 35 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 36 | // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient |
| 37 | // that depends on chrome/. |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 38 | class ChromeMetricsServiceClient |
| 39 | : public metrics::MetricsServiceClient, |
| 40 | public chrome_browser_metrics::TrackingSynchronizerObserver, |
| 41 | public content::NotificationObserver { |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 42 | public: |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 43 | virtual ~ChromeMetricsServiceClient(); |
| 44 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 45 | // Factory function. |
| 46 | static scoped_ptr<ChromeMetricsServiceClient> Create( |
| 47 | metrics::MetricsStateManager* state_manager, |
| 48 | PrefService* local_state); |
| 49 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 50 | // Registers local state prefs used by this class. |
| 51 | static void RegisterPrefs(PrefRegistrySimple* registry); |
| 52 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 53 | // metrics::MetricsServiceClient: |
| 54 | virtual void SetClientID(const std::string& client_id) OVERRIDE; |
| 55 | virtual bool IsOffTheRecordSessionActive() OVERRIDE; |
| 56 | virtual std::string GetApplicationLocale() OVERRIDE; |
| 57 | virtual bool GetBrand(std::string* brand_code) OVERRIDE; |
| 58 | virtual metrics::SystemProfileProto::Channel GetChannel() OVERRIDE; |
| 59 | virtual std::string GetVersionString() OVERRIDE; |
[email protected] | 91b1d91 | 2014-06-05 10:52:08 | [diff] [blame] | 60 | virtual int64 GetInstallDate() OVERRIDE; |
[email protected] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 61 | virtual void OnLogUploadComplete() OVERRIDE; |
[email protected] | 06c1083 | 2014-05-23 10:55:55 | [diff] [blame] | 62 | virtual void StartGatheringMetrics( |
| 63 | const base::Closure& done_callback) OVERRIDE; |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 64 | virtual void CollectFinalMetrics(const base::Closure& done_callback) |
| 65 | OVERRIDE; |
[email protected] | 0d5a61a8 | 2014-05-31 22:28:34 | [diff] [blame] | 66 | virtual scoped_ptr<metrics::MetricsLogUploader> CreateUploader( |
| 67 | const std::string& server_url, |
| 68 | const std::string& mime_type, |
| 69 | const base::Callback<void(int)>& on_upload_complete) OVERRIDE; |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 70 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 71 | MetricsService* metrics_service() { return metrics_service_.get(); } |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 72 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 73 | void LogPluginLoadingError(const base::FilePath& plugin_path); |
| 74 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 75 | private: |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 76 | explicit ChromeMetricsServiceClient( |
| 77 | metrics::MetricsStateManager* state_manager); |
| 78 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 79 | // Completes the two-phase initialization of ChromeMetricsServiceClient. |
| 80 | void Initialize(); |
| 81 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 82 | // Callback that continues the init task by loading plugin information. |
| 83 | void OnInitTaskGotHardwareClass(); |
| 84 | |
| 85 | // Called after the Plugin init task has been completed that continues the |
| 86 | // init task by launching a task to gather Google Update statistics. |
| 87 | void OnInitTaskGotPluginInfo(); |
| 88 | |
| 89 | // Called after GoogleUpdate init task has been completed that continues the |
| 90 | // init task by loading profiler data. |
| 91 | void OnInitTaskGotGoogleUpdateData(); |
| 92 | |
| 93 | // TrackingSynchronizerObserver: |
| 94 | virtual void ReceivedProfilerData( |
| 95 | const tracked_objects::ProcessDataSnapshot& process_data, |
| 96 | int process_type) OVERRIDE; |
| 97 | virtual void FinishedReceivingProfilerData() OVERRIDE; |
| 98 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 99 | // Callbacks for various stages of final log info collection. Do not call |
| 100 | // these directly. |
| 101 | void OnMemoryDetailCollectionDone(); |
| 102 | void OnHistogramSynchronizationDone(); |
| 103 | |
[email protected] | daed87e | 2014-05-22 19:41:22 | [diff] [blame] | 104 | // Records metrics about the switches present on the command line. |
| 105 | void RecordCommandLineMetrics(); |
| 106 | |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 107 | // Registers |this| as an observer for notifications which indicate that a |
| 108 | // user is performing work. This is useful to allow some features to sleep, |
| 109 | // until the machine becomes active, such as precluding UMA uploads unless |
| 110 | // there was recent activity. |
| 111 | void RegisterForNotifications(); |
| 112 | |
| 113 | // content::NotificationObserver: |
| 114 | virtual void Observe(int type, |
| 115 | const content::NotificationSource& source, |
| 116 | const content::NotificationDetails& details) OVERRIDE; |
| 117 | |
[email protected] | e2481a70 | 2014-05-23 21:06:50 | [diff] [blame] | 118 | #if defined(OS_WIN) |
| 119 | // Counts (and removes) the browser crash dump attempt signals left behind by |
| 120 | // any previous browser processes which generated a crash dump. |
| 121 | void CountBrowserCrashDumpAttempts(); |
| 122 | #endif // OS_WIN |
| 123 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 124 | base::ThreadChecker thread_checker_; |
| 125 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 126 | // Weak pointer to the MetricsStateManager. |
| 127 | metrics::MetricsStateManager* metrics_state_manager_; |
| 128 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 129 | // The MetricsService that |this| is a client of. |
| 130 | scoped_ptr<MetricsService> metrics_service_; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 131 | |
| 132 | content::NotificationRegistrar registrar_; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 133 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 134 | // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance |
| 135 | // that has been registered with MetricsService. On other platforms, is NULL. |
| 136 | ChromeOSMetricsProvider* chromeos_metrics_provider_; |
| 137 | |
[email protected] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 138 | NetworkStatsUploader network_stats_uploader_; |
| 139 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 140 | // Saved callback received from CollectFinalMetrics(). |
| 141 | base::Closure collect_final_metrics_done_callback_; |
| 142 | |
| 143 | // Indicates that collect final metrics step is running. |
| 144 | bool waiting_for_collect_final_metrics_step_; |
| 145 | |
| 146 | // Number of async histogram fetch requests in progress. |
| 147 | int num_async_histogram_fetches_in_progress_; |
| 148 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame^] | 149 | // The ProfilerMetricsProvider instance that was registered with |
| 150 | // MetricsService. Has the same lifetime as |metrics_service_|. |
| 151 | ProfilerMetricsProvider* profiler_metrics_provider_; |
| 152 | |
| 153 | #if defined(ENABLE_PLUGINS) |
| 154 | // The PluginMetricsProvider instance that was registered with |
| 155 | // MetricsService. Has the same lifetime as |metrics_service_|. |
| 156 | PluginMetricsProvider* plugin_metrics_provider_; |
| 157 | #endif |
| 158 | |
| 159 | #if defined(OS_WIN) |
| 160 | // The GoogleUpdateMetricsProviderWin instance that was registered with |
| 161 | // MetricsService. Has the same lifetime as |metrics_service_|. |
| 162 | GoogleUpdateMetricsProviderWin* google_update_metrics_provider_; |
| 163 | #endif |
| 164 | |
| 165 | // Callback that is called when initial metrics gathering is complete. |
| 166 | base::Closure finished_gathering_initial_metrics_callback_; |
| 167 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 168 | base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_; |
| 169 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 170 | DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient); |
| 171 | }; |
| 172 | |
| 173 | #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_ |