Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file defines a service that collects information about the user | 5 // This file defines a service that collects information about the user |
| 6 // experience in order to help improve future versions of the app. | 6 // experience in order to help improve future versions of the app. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| 9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 22 #include "base/metrics/histogram_flattener.h" | 22 #include "base/metrics/histogram_flattener.h" |
| 23 #include "base/metrics/histogram_snapshot_manager.h" | 23 #include "base/metrics/histogram_snapshot_manager.h" |
| 24 #include "base/metrics/user_metrics.h" | 24 #include "base/metrics/user_metrics.h" |
| 25 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
| 26 #include "base/strings/string16.h" | 26 #include "base/strings/string16.h" |
| 27 #include "base/threading/thread_checker.h" | 27 #include "base/threading/thread_checker.h" |
| 28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 29 #include "chrome/browser/metrics/metrics_log.h" | 29 #include "chrome/browser/metrics/metrics_log.h" |
| 30 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | |
| 31 #include "components/metrics/metrics_log_manager.h" | 30 #include "components/metrics/metrics_log_manager.h" |
| 32 #include "components/metrics/metrics_provider.h" | 31 #include "components/metrics/metrics_provider.h" |
| 33 #include "components/metrics/metrics_service_observer.h" | 32 #include "components/metrics/metrics_service_observer.h" |
| 34 #include "components/variations/active_field_trials.h" | 33 #include "components/variations/active_field_trials.h" |
| 35 #include "net/url_request/url_fetcher_delegate.h" | 34 #include "net/url_request/url_fetcher_delegate.h" |
| 36 | 35 |
| 37 class GoogleUpdateMetricsProviderWin; | |
| 38 class MetricsReportingScheduler; | 36 class MetricsReportingScheduler; |
| 39 class PrefService; | 37 class PrefService; |
| 40 class PrefRegistrySimple; | 38 class PrefRegistrySimple; |
| 41 class PluginMetricsProvider; | |
| 42 | 39 |
| 43 namespace base { | 40 namespace base { |
| 44 class DictionaryValue; | 41 class DictionaryValue; |
| 45 class HistogramSamples; | 42 class HistogramSamples; |
| 46 class MessageLoopProxy; | 43 class MessageLoopProxy; |
| 47 class PrefService; | 44 class PrefService; |
| 48 } | 45 } |
| 49 | 46 |
| 50 namespace variations { | 47 namespace variations { |
| 51 struct ActiveGroupId; | 48 struct ActiveGroupId; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 82 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 79 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 83 | 80 |
| 84 // This constructor is private specifically so as to control which code is | 81 // This constructor is private specifically so as to control which code is |
| 85 // able to access it. New code that wishes to use it should be added as a | 82 // able to access it. New code that wishes to use it should be added as a |
| 86 // friend class. | 83 // friend class. |
| 87 SyntheticTrialGroup(uint32 trial, uint32 group); | 84 SyntheticTrialGroup(uint32 trial, uint32 group); |
| 88 }; | 85 }; |
| 89 | 86 |
| 90 class MetricsService | 87 class MetricsService |
| 91 : public base::HistogramFlattener, | 88 : public base::HistogramFlattener, |
| 92 public chrome_browser_metrics::TrackingSynchronizerObserver, | |
| 93 public net::URLFetcherDelegate { | 89 public net::URLFetcherDelegate { |
| 94 public: | 90 public: |
| 95 // The execution phase of the browser. | 91 // The execution phase of the browser. |
| 96 enum ExecutionPhase { | 92 enum ExecutionPhase { |
| 97 UNINITIALIZED_PHASE = 0, | 93 UNINITIALIZED_PHASE = 0, |
| 98 START_METRICS_RECORDING = 100, | 94 START_METRICS_RECORDING = 100, |
| 99 CREATE_PROFILE = 200, | 95 CREATE_PROFILE = 200, |
| 100 STARTUP_TIMEBOMB_ARM = 300, | 96 STARTUP_TIMEBOMB_ARM = 300, |
| 101 THREAD_WATCHER_START = 400, | 97 THREAD_WATCHER_START = 400, |
| 102 MAIN_MESSAGE_LOOP_RUN = 500, | 98 MAIN_MESSAGE_LOOP_RUN = 500, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 // Register the specified |provider| to provide additional metrics into the | 222 // Register the specified |provider| to provide additional metrics into the |
| 227 // UMA log. Should be called during MetricsService initialization only. | 223 // UMA log. Should be called during MetricsService initialization only. |
| 228 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); | 224 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); |
| 229 | 225 |
| 230 // Check if this install was cloned or imaged from another machine. If a | 226 // Check if this install was cloned or imaged from another machine. If a |
| 231 // clone is detected, reset the client id and low entropy source. This | 227 // clone is detected, reset the client id and low entropy source. This |
| 232 // should not be called more than once. | 228 // should not be called more than once. |
| 233 void CheckForClonedInstall( | 229 void CheckForClonedInstall( |
| 234 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 230 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 235 | 231 |
| 232 // Records the passed profiled data, which should be a snapshot of the | |
| 233 // browser's profiled performance during startup for a single process. | |
| 234 void RecordProfilerData( | |
|
Alexei Svitkine (slow)
2014/05/27 20:50:00
Hmm, I'm not super keen on exposing this like so.
| |
| 235 const tracked_objects::ProcessDataSnapshot& process_data, | |
| 236 int process_type); | |
| 237 | |
| 236 protected: | 238 protected: |
| 237 // Exposed for testing. | 239 // Exposed for testing. |
| 238 metrics::MetricsLogManager* log_manager() { return &log_manager_; } | 240 metrics::MetricsLogManager* log_manager() { return &log_manager_; } |
| 239 | 241 |
| 240 private: | 242 private: |
| 241 // The MetricsService has a lifecycle that is stored as a state. | 243 // The MetricsService has a lifecycle that is stored as a state. |
| 242 // See metrics_service.cc for description of this lifecycle. | 244 // See metrics_service.cc for description of this lifecycle. |
| 243 enum State { | 245 enum State { |
| 244 INITIALIZED, // Constructor was called. | 246 INITIALIZED, // Constructor was called. |
| 245 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to | 247 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to |
| 246 // complete. | 248 // complete. |
| 247 INIT_TASK_DONE, // Waiting for timer to send initial log. | 249 INIT_TASK_DONE, // Waiting for timer to send initial log. |
| 248 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. | 250 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. |
| 249 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent. | 251 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent. |
| 250 SENDING_OLD_LOGS, // Sending unsent logs from last session. | 252 SENDING_OLD_LOGS, // Sending unsent logs from last session. |
| 251 SENDING_CURRENT_LOGS, // Sending ongoing logs as they accrue. | 253 SENDING_CURRENT_LOGS, // Sending ongoing logs as they accrue. |
| 252 }; | 254 }; |
| 253 | 255 |
| 254 enum ShutdownCleanliness { | 256 enum ShutdownCleanliness { |
| 255 CLEANLY_SHUTDOWN = 0xdeadbeef, | 257 CLEANLY_SHUTDOWN = 0xdeadbeef, |
| 256 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN | 258 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN |
| 257 }; | 259 }; |
| 258 | 260 |
| 259 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; | 261 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; |
| 260 | 262 |
| 261 // Callback that continues the init task by loading plugin information. | 263 // Callback that moves the state to INIT_TASK_DONE. When this is called, the |
| 262 void OnInitTaskGotHardwareClass(); | 264 // state should be INIT_TASK_SCHEDULED. |
| 263 | 265 void FinishedGatheringInitialMetrics(); |
| 264 // Called after the Plugin init task has been completed that continues the | |
| 265 // init task by launching a task to gather Google Update statistics. | |
| 266 void OnInitTaskGotPluginInfo(); | |
| 267 | |
| 268 // Called after GoogleUpdate init task has been completed that continues the | |
| 269 // init task by loading profiler data. | |
| 270 void OnInitTaskGotGoogleUpdateData(); | |
| 271 | 266 |
| 272 void OnUserAction(const std::string& action); | 267 void OnUserAction(const std::string& action); |
| 273 | 268 |
| 274 // TrackingSynchronizerObserver: | |
| 275 virtual void ReceivedProfilerData( | |
| 276 const tracked_objects::ProcessDataSnapshot& process_data, | |
| 277 int process_type) OVERRIDE; | |
| 278 // Callback that moves the state to INIT_TASK_DONE. | |
| 279 virtual void FinishedReceivingProfilerData() OVERRIDE; | |
| 280 | |
| 281 // Get the amount of uptime since this process started and since the last | 269 // Get the amount of uptime since this process started and since the last |
| 282 // call to this function. Also updates the cumulative uptime metric (stored | 270 // call to this function. Also updates the cumulative uptime metric (stored |
| 283 // as a pref) for uninstall. Uptimes are measured using TimeTicks, which | 271 // as a pref) for uninstall. Uptimes are measured using TimeTicks, which |
| 284 // guarantees that it is monotonic and does not jump if the user changes | 272 // guarantees that it is monotonic and does not jump if the user changes |
| 285 // his/her clock. The TimeTicks implementation also makes the clock not | 273 // his/her clock. The TimeTicks implementation also makes the clock not |
| 286 // count time the computer is suspended. | 274 // count time the computer is suspended. |
| 287 void GetUptimes(PrefService* pref, | 275 void GetUptimes(PrefService* pref, |
| 288 base::TimeDelta* incremental_uptime, | 276 base::TimeDelta* incremental_uptime, |
| 289 base::TimeDelta* uptime); | 277 base::TimeDelta* uptime); |
| 290 | 278 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 // be cut, and logs are neither persisted nor uploaded. | 418 // be cut, and logs are neither persisted nor uploaded. |
| 431 bool test_mode_active_; | 419 bool test_mode_active_; |
| 432 | 420 |
| 433 // The progression of states made by the browser are recorded in the following | 421 // The progression of states made by the browser are recorded in the following |
| 434 // state. | 422 // state. |
| 435 State state_; | 423 State state_; |
| 436 | 424 |
| 437 // Whether the initial stability log has been recorded during startup. | 425 // Whether the initial stability log has been recorded during startup. |
| 438 bool has_initial_stability_log_; | 426 bool has_initial_stability_log_; |
| 439 | 427 |
| 440 #if defined(ENABLE_PLUGINS) | |
| 441 PluginMetricsProvider* plugin_metrics_provider_; | |
| 442 #endif | |
| 443 | |
| 444 #if defined(OS_WIN) | |
| 445 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_; | |
| 446 #endif | |
| 447 | |
| 448 // The initial metrics log, used to record startup metrics (histograms and | 428 // The initial metrics log, used to record startup metrics (histograms and |
| 449 // profiler data). Note that if a crash occurred in the previous session, an | 429 // profiler data). Note that if a crash occurred in the previous session, an |
| 450 // initial stability log may be sent before this. | 430 // initial stability log may be sent before this. |
| 451 scoped_ptr<MetricsLog> initial_metrics_log_; | 431 scoped_ptr<MetricsLog> initial_metrics_log_; |
| 452 | 432 |
| 453 // The outstanding transmission appears as a URL Fetch operation. | 433 // The outstanding transmission appears as a URL Fetch operation. |
| 454 scoped_ptr<net::URLFetcher> current_fetch_; | 434 scoped_ptr<net::URLFetcher> current_fetch_; |
| 455 | 435 |
| 456 // Whether the MetricsService object has received any notifications since | 436 // Whether the MetricsService object has received any notifications since |
| 457 // the last time a transmission was sent. | 437 // the last time a transmission was sent. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 488 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 509 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); | 489 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); |
| 510 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 490 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
| 511 PermutedEntropyCacheClearedWhenLowEntropyReset); | 491 PermutedEntropyCacheClearedWhenLowEntropyReset); |
| 512 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 492 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 513 | 493 |
| 514 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 494 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 515 }; | 495 }; |
| 516 | 496 |
| 517 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 497 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |