[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 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 12 | #include "base/callback.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 16 | #include "base/threading/thread_checker.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 17 | #include "build/build_config.h" |
asvitkine | 89406d1f | 2015-01-17 06:57:10 | [diff] [blame] | 18 | #include "chrome/browser/metrics/metrics_memory_details.h" |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 19 | #include "components/metrics/metrics_service_client.h" |
gunsch | 840bc41 | 2014-09-18 19:38:06 | [diff] [blame] | 20 | #include "components/metrics/profiler/tracking_synchronizer_observer.h" |
blundell | 26b9524 | 2015-08-17 10:29:24 | [diff] [blame] | 21 | #include "components/omnibox/browser/omnibox_event_global_tracker.h" |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 22 | #include "content/public/browser/notification_observer.h" |
| 23 | #include "content/public/browser/notification_registrar.h" |
| 24 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 25 | class ChromeOSMetricsProvider; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 26 | class GoogleUpdateMetricsProviderWin; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 27 | class PluginMetricsProvider; |
| 28 | class PrefRegistrySimple; |
isherman | fc021e91 | 2015-03-25 23:33:33 | [diff] [blame] | 29 | class PrefService; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 30 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame^] | 31 | #if !defined(OS_CHROMEOS) |
[email protected] | 7aee4f7e | 2014-08-12 01:15:03 | [diff] [blame] | 32 | class SigninStatusMetricsProvider; |
| 33 | #endif |
| 34 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 35 | namespace metrics { |
blundell | b5c6b5a | 2015-07-30 20:18:30 | [diff] [blame] | 36 | class DriveMetricsProvider; |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 37 | class MetricsService; |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 38 | class MetricsStateManager; |
gunsch | 840bc41 | 2014-09-18 19:38:06 | [diff] [blame] | 39 | class ProfilerMetricsProvider; |
siggi | 5e62f7e | 2014-11-21 21:55:45 | [diff] [blame] | 40 | } // namespace metrics |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 41 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 42 | // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient |
| 43 | // that depends on chrome/. |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 44 | class ChromeMetricsServiceClient |
| 45 | : public metrics::MetricsServiceClient, |
gunsch | 840bc41 | 2014-09-18 19:38:06 | [diff] [blame] | 46 | public metrics::TrackingSynchronizerObserver, |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 47 | public content::NotificationObserver { |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 48 | public: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 49 | ~ChromeMetricsServiceClient() override; |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 50 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 51 | // Factory function. |
| 52 | static scoped_ptr<ChromeMetricsServiceClient> Create( |
| 53 | metrics::MetricsStateManager* state_manager, |
| 54 | PrefService* local_state); |
| 55 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 56 | // Registers local state prefs used by this class. |
| 57 | static void RegisterPrefs(PrefRegistrySimple* registry); |
| 58 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 59 | // metrics::MetricsServiceClient: |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 60 | metrics::MetricsService* GetMetricsService() override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 61 | void SetMetricsClientId(const std::string& client_id) override; |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 62 | void OnRecordingDisabled() override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 63 | bool IsOffTheRecordSessionActive() override; |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 64 | int32_t GetProduct() override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 65 | std::string GetApplicationLocale() override; |
| 66 | bool GetBrand(std::string* brand_code) override; |
| 67 | metrics::SystemProfileProto::Channel GetChannel() override; |
| 68 | std::string GetVersionString() override; |
| 69 | void OnLogUploadComplete() override; |
isherman | b670568 | 2015-08-29 00:01:00 | [diff] [blame] | 70 | void InitializeSystemProfileMetrics( |
| 71 | const base::Closure& done_callback) override; |
| 72 | void CollectFinalMetricsForLog(const base::Closure& done_callback) override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 73 | scoped_ptr<metrics::MetricsLogUploader> CreateUploader( |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame] | 74 | const base::Callback<void(int)>& on_upload_complete) override; |
gunsch | 7cbdcb2 | 2015-03-13 17:02:05 | [diff] [blame] | 75 | base::TimeDelta GetStandardUploadInterval() override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 76 | base::string16 GetRegistryBackupKey() override; |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 77 | void OnPluginLoadingError(const base::FilePath& plugin_path) override; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 78 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 79 | private: |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 80 | explicit ChromeMetricsServiceClient( |
| 81 | metrics::MetricsStateManager* state_manager); |
| 82 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 83 | // Completes the two-phase initialization of ChromeMetricsServiceClient. |
| 84 | void Initialize(); |
| 85 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 86 | // Callback that continues the init task by loading plugin information. |
| 87 | void OnInitTaskGotHardwareClass(); |
| 88 | |
| 89 | // Called after the Plugin init task has been completed that continues the |
| 90 | // init task by launching a task to gather Google Update statistics. |
| 91 | void OnInitTaskGotPluginInfo(); |
| 92 | |
| 93 | // Called after GoogleUpdate init task has been completed that continues the |
isherman | fcf4639e8 | 2015-08-26 00:33:49 | [diff] [blame] | 94 | // init task by loading drive metrics. |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 95 | void OnInitTaskGotGoogleUpdateData(); |
| 96 | |
isherman | fcf4639e8 | 2015-08-26 00:33:49 | [diff] [blame] | 97 | // Called after the drive metrics init task has been completed that continues |
| 98 | // the init task by loading profiler data. |
| 99 | void OnInitTaskGotDriveMetrics(); |
amistry | 9e2a8b4 | 2015-06-13 01:11:27 | [diff] [blame] | 100 | |
isherman | 213b47c | 2015-08-28 08:20:46 | [diff] [blame] | 101 | // Returns true iff profiler data should be included in the next metrics log. |
| 102 | // NOTE: This method is probabilistic and also updates internal state as a |
| 103 | // side-effect when called, so it should only be called once per log. |
| 104 | bool ShouldIncludeProfilerDataInLog(); |
| 105 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 106 | // TrackingSynchronizerObserver: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 107 | void ReceivedProfilerData( |
vadimt | e2de473 | 2015-04-27 21:43:02 | [diff] [blame] | 108 | const metrics::ProfilerDataAttributes& attributes, |
vadimt | 379d7fe | 2015-04-01 00:09:35 | [diff] [blame] | 109 | const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, |
vadimt | 379d7fe | 2015-04-01 00:09:35 | [diff] [blame] | 110 | const metrics::ProfilerEvents& past_profiler_events) override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 111 | void FinishedReceivingProfilerData() override; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 112 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 113 | // Callbacks for various stages of final log info collection. Do not call |
| 114 | // these directly. |
isherman | fcf4639e8 | 2015-08-26 00:33:49 | [diff] [blame] | 115 | void CollectFinalHistograms(); |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 116 | void OnMemoryDetailCollectionDone(); |
| 117 | void OnHistogramSynchronizationDone(); |
| 118 | |
[email protected] | daed87e | 2014-05-22 19:41:22 | [diff] [blame] | 119 | // Records metrics about the switches present on the command line. |
| 120 | void RecordCommandLineMetrics(); |
| 121 | |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 122 | // Registers |this| as an observer for notifications which indicate that a |
| 123 | // user is performing work. This is useful to allow some features to sleep, |
| 124 | // until the machine becomes active, such as precluding UMA uploads unless |
| 125 | // there was recent activity. |
| 126 | void RegisterForNotifications(); |
| 127 | |
| 128 | // content::NotificationObserver: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 129 | void Observe(int type, |
| 130 | const content::NotificationSource& source, |
| 131 | const content::NotificationDetails& details) override; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 132 | |
blundell | 26b9524 | 2015-08-17 10:29:24 | [diff] [blame] | 133 | // Called when a URL is opened from the Omnibox. |
| 134 | void OnURLOpenedFromOmnibox(OmniboxLog* log); |
| 135 | |
[email protected] | e2481a70 | 2014-05-23 21:06:50 | [diff] [blame] | 136 | #if defined(OS_WIN) |
| 137 | // Counts (and removes) the browser crash dump attempt signals left behind by |
| 138 | // any previous browser processes which generated a crash dump. |
| 139 | void CountBrowserCrashDumpAttempts(); |
| 140 | #endif // OS_WIN |
| 141 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 142 | base::ThreadChecker thread_checker_; |
| 143 | |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 144 | // Weak pointer to the MetricsStateManager. |
| 145 | metrics::MetricsStateManager* metrics_state_manager_; |
| 146 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 147 | // The MetricsService that |this| is a client of. |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 148 | scoped_ptr<metrics::MetricsService> metrics_service_; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 149 | |
| 150 | content::NotificationRegistrar registrar_; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 151 | |
mlamouri | ba00ad1 | 2016-01-16 15:06:08 | [diff] [blame] | 152 | #if defined(OS_CHROMEOS) |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 153 | // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance |
| 154 | // that has been registered with MetricsService. On other platforms, is NULL. |
| 155 | ChromeOSMetricsProvider* chromeos_metrics_provider_; |
mlamouri | ba00ad1 | 2016-01-16 15:06:08 | [diff] [blame] | 156 | #endif |
[email protected] | 51994b2 | 2014-05-30 13:24:21 | [diff] [blame] | 157 | |
isherman | b670568 | 2015-08-29 00:01:00 | [diff] [blame] | 158 | // Saved callback received from CollectFinalMetricsForLog(). |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 159 | base::Closure collect_final_metrics_done_callback_; |
| 160 | |
| 161 | // Indicates that collect final metrics step is running. |
| 162 | bool waiting_for_collect_final_metrics_step_; |
| 163 | |
| 164 | // Number of async histogram fetch requests in progress. |
| 165 | int num_async_histogram_fetches_in_progress_; |
| 166 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 167 | // The ProfilerMetricsProvider instance that was registered with |
| 168 | // MetricsService. Has the same lifetime as |metrics_service_|. |
gunsch | 840bc41 | 2014-09-18 19:38:06 | [diff] [blame] | 169 | metrics::ProfilerMetricsProvider* profiler_metrics_provider_; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 170 | |
| 171 | #if defined(ENABLE_PLUGINS) |
| 172 | // The PluginMetricsProvider instance that was registered with |
| 173 | // MetricsService. Has the same lifetime as |metrics_service_|. |
| 174 | PluginMetricsProvider* plugin_metrics_provider_; |
| 175 | #endif |
| 176 | |
| 177 | #if defined(OS_WIN) |
| 178 | // The GoogleUpdateMetricsProviderWin instance that was registered with |
| 179 | // MetricsService. Has the same lifetime as |metrics_service_|. |
| 180 | GoogleUpdateMetricsProviderWin* google_update_metrics_provider_; |
| 181 | #endif |
| 182 | |
dbeam | 64c3784 | 2015-03-18 02:23:35 | [diff] [blame] | 183 | // The DriveMetricsProvider instance that was registered with MetricsService. |
| 184 | // Has the same lifetime as |metrics_service_|. |
blundell | b5c6b5a | 2015-07-30 20:18:30 | [diff] [blame] | 185 | metrics::DriveMetricsProvider* drive_metrics_provider_; |
dbeam | 64c3784 | 2015-03-18 02:23:35 | [diff] [blame] | 186 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 187 | // Callback that is called when initial metrics gathering is complete. |
isherman | b670568 | 2015-08-29 00:01:00 | [diff] [blame] | 188 | base::Closure finished_init_task_callback_; |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 189 | |
[email protected] | 8a5b2da | 2014-07-07 10:56:51 | [diff] [blame] | 190 | // The MemoryGrowthTracker instance that tracks memory usage growth in |
| 191 | // MemoryDetails. |
| 192 | MemoryGrowthTracker memory_growth_tracker_; |
| 193 | |
gunsch | 7cbdcb2 | 2015-03-13 17:02:05 | [diff] [blame] | 194 | // Callback to determine whether or not a cellular network is currently being |
| 195 | // used. |
| 196 | base::Callback<void(bool*)> cellular_callback_; |
| 197 | |
vadimt | e2de473 | 2015-04-27 21:43:02 | [diff] [blame] | 198 | // Time of this object's creation. |
| 199 | const base::TimeTicks start_time_; |
| 200 | |
blundell | 26b9524 | 2015-08-17 10:29:24 | [diff] [blame] | 201 | // Subscription for receiving callbacks that a URL was opened from the |
| 202 | // omnibox. |
| 203 | scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription> |
| 204 | omnibox_url_opened_subscription_; |
| 205 | |
isherman | 213b47c | 2015-08-28 08:20:46 | [diff] [blame] | 206 | // Whether this client has already uploaded profiler data during this session. |
| 207 | // Profiler data is uploaded at most once per session. |
| 208 | bool has_uploaded_profiler_data_; |
| 209 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 210 | base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_; |
| 211 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 212 | DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient); |
| 213 | }; |
| 214 | |
| 215 | #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_ |