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