| 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/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram_flattener.h" |
| 22 #include "base/metrics/histogram_snapshot_manager.h" |
| 21 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
| 22 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
| 23 #include "base/process/kill.h" | 25 #include "base/process/kill.h" |
| 24 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
| 25 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 26 #include "chrome/browser/metrics/metrics_log.h" | 28 #include "chrome/browser/metrics/metrics_log.h" |
| 27 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 29 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
| 28 #include "chrome/common/metrics/metrics_service_base.h" | 30 #include "components/metrics/metrics_log_manager.h" |
| 29 #include "components/metrics/metrics_provider.h" | 31 #include "components/metrics/metrics_provider.h" |
| 30 #include "components/metrics/metrics_service_observer.h" | 32 #include "components/metrics/metrics_service_observer.h" |
| 31 #include "components/variations/active_field_trials.h" | 33 #include "components/variations/active_field_trials.h" |
| 32 #include "content/public/browser/browser_child_process_observer.h" | 34 #include "content/public/browser/browser_child_process_observer.h" |
| 33 #include "content/public/browser/notification_observer.h" | 35 #include "content/public/browser/notification_observer.h" |
| 34 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
| 35 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
| 36 #include "net/url_request/url_fetcher_delegate.h" | 38 #include "net/url_request/url_fetcher_delegate.h" |
| 37 | 39 |
| 38 class ChromeBrowserMetricsServiceObserver; | 40 class ChromeBrowserMetricsServiceObserver; |
| 39 class GoogleUpdateMetricsProviderWin; | 41 class GoogleUpdateMetricsProviderWin; |
| 40 class MetricsReportingScheduler; | 42 class MetricsReportingScheduler; |
| 41 class PrefService; | 43 class PrefService; |
| 42 class PrefRegistrySimple; | 44 class PrefRegistrySimple; |
| 43 class Profile; | 45 class Profile; |
| 44 class TemplateURLService; | 46 class TemplateURLService; |
| 45 | 47 |
| 46 namespace { | 48 namespace { |
| 47 class CrashesDOMHandler; | 49 class CrashesDOMHandler; |
| 48 class FlashDOMHandler; | 50 class FlashDOMHandler; |
| 49 } | 51 } |
| 50 | 52 |
| 51 namespace base { | 53 namespace base { |
| 52 class DictionaryValue; | 54 class DictionaryValue; |
| 55 class HistogramSamples; |
| 53 class MessageLoopProxy; | 56 class MessageLoopProxy; |
| 54 } | 57 } |
| 55 | 58 |
| 56 namespace variations { | 59 namespace variations { |
| 57 struct ActiveGroupId; | 60 struct ActiveGroupId; |
| 58 } | 61 } |
| 59 | 62 |
| 60 namespace content { | 63 namespace content { |
| 61 class RenderProcessHost; | 64 class RenderProcessHost; |
| 62 class WebContents; | 65 class WebContents; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 friend class MetricsService; | 107 friend class MetricsService; |
| 105 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 108 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 106 | 109 |
| 107 // This constructor is private specifically so as to control which code is | 110 // This constructor is private specifically so as to control which code is |
| 108 // able to access it. New code that wishes to use it should be added as a | 111 // able to access it. New code that wishes to use it should be added as a |
| 109 // friend class. | 112 // friend class. |
| 110 SyntheticTrialGroup(uint32 trial, uint32 group); | 113 SyntheticTrialGroup(uint32 trial, uint32 group); |
| 111 }; | 114 }; |
| 112 | 115 |
| 113 class MetricsService | 116 class MetricsService |
| 114 : public chrome_browser_metrics::TrackingSynchronizerObserver, | 117 : public base::HistogramFlattener, |
| 118 public chrome_browser_metrics::TrackingSynchronizerObserver, |
| 115 public content::BrowserChildProcessObserver, | 119 public content::BrowserChildProcessObserver, |
| 116 public content::NotificationObserver, | 120 public content::NotificationObserver, |
| 117 public net::URLFetcherDelegate, | 121 public net::URLFetcherDelegate { |
| 118 public MetricsServiceBase { | |
| 119 public: | 122 public: |
| 120 // The execution phase of the browser. | 123 // The execution phase of the browser. |
| 121 enum ExecutionPhase { | 124 enum ExecutionPhase { |
| 122 UNINITIALIZED_PHASE = 0, | 125 UNINITIALIZED_PHASE = 0, |
| 123 START_METRICS_RECORDING = 100, | 126 START_METRICS_RECORDING = 100, |
| 124 CREATE_PROFILE = 200, | 127 CREATE_PROFILE = 200, |
| 125 STARTUP_TIMEBOMB_ARM = 300, | 128 STARTUP_TIMEBOMB_ARM = 300, |
| 126 THREAD_WATCHER_START = 400, | 129 THREAD_WATCHER_START = 400, |
| 127 MAIN_MESSAGE_LOOP_RUN = 500, | 130 MAIN_MESSAGE_LOOP_RUN = 500, |
| 128 SHUTDOWN_TIMEBOMB_ARM = 600, | 131 SHUTDOWN_TIMEBOMB_ARM = 600, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // At startup, prefs needs to be called with a list of all the pref names and | 187 // At startup, prefs needs to be called with a list of all the pref names and |
| 185 // types we'll be using. | 188 // types we'll be using. |
| 186 static void RegisterPrefs(PrefRegistrySimple* registry); | 189 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 187 | 190 |
| 188 // Set up notifications which indicate that a user is performing work. This is | 191 // Set up notifications which indicate that a user is performing work. This is |
| 189 // useful to allow some features to sleep, until the machine becomes active, | 192 // useful to allow some features to sleep, until the machine becomes active, |
| 190 // such as precluding UMA uploads unless there was recent activity. | 193 // such as precluding UMA uploads unless there was recent activity. |
| 191 static void SetUpNotifications(content::NotificationRegistrar* registrar, | 194 static void SetUpNotifications(content::NotificationRegistrar* registrar, |
| 192 content::NotificationObserver* observer); | 195 content::NotificationObserver* observer); |
| 193 | 196 |
| 197 // HistogramFlattener: |
| 198 virtual void RecordDelta(const base::HistogramBase& histogram, |
| 199 const base::HistogramSamples& snapshot) OVERRIDE; |
| 200 virtual void InconsistencyDetected( |
| 201 base::HistogramBase::Inconsistency problem) OVERRIDE; |
| 202 virtual void UniqueInconsistencyDetected( |
| 203 base::HistogramBase::Inconsistency problem) OVERRIDE; |
| 204 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE; |
| 205 |
| 194 // Implementation of content::BrowserChildProcessObserver | 206 // Implementation of content::BrowserChildProcessObserver |
| 195 virtual void BrowserChildProcessHostConnected( | 207 virtual void BrowserChildProcessHostConnected( |
| 196 const content::ChildProcessData& data) OVERRIDE; | 208 const content::ChildProcessData& data) OVERRIDE; |
| 197 virtual void BrowserChildProcessCrashed( | 209 virtual void BrowserChildProcessCrashed( |
| 198 const content::ChildProcessData& data) OVERRIDE; | 210 const content::ChildProcessData& data) OVERRIDE; |
| 199 virtual void BrowserChildProcessInstanceCreated( | 211 virtual void BrowserChildProcessInstanceCreated( |
| 200 const content::ChildProcessData& data) OVERRIDE; | 212 const content::ChildProcessData& data) OVERRIDE; |
| 201 | 213 |
| 202 // Implementation of content::NotificationObserver | 214 // content::NotificationObserver: |
| 203 virtual void Observe(int type, | 215 virtual void Observe(int type, |
| 204 const content::NotificationSource& source, | 216 const content::NotificationSource& source, |
| 205 const content::NotificationDetails& details) OVERRIDE; | 217 const content::NotificationDetails& details) OVERRIDE; |
| 206 | 218 |
| 207 // This should be called when the application is not idle, i.e. the user seems | 219 // This should be called when the application is not idle, i.e. the user seems |
| 208 // to be interacting with the application. | 220 // to be interacting with the application. |
| 209 void OnApplicationNotIdle(); | 221 void OnApplicationNotIdle(); |
| 210 | 222 |
| 211 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is | 223 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is |
| 212 // reset when RecordCompletedSessionEnd is invoked. | 224 // reset when RecordCompletedSessionEnd is invoked. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // Register the specified |provider| to provide additional metrics into the | 282 // Register the specified |provider| to provide additional metrics into the |
| 271 // UMA log. Should be called during MetricsService initialization only. | 283 // UMA log. Should be called during MetricsService initialization only. |
| 272 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); | 284 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); |
| 273 | 285 |
| 274 // Check if this install was cloned or imaged from another machine. If a | 286 // Check if this install was cloned or imaged from another machine. If a |
| 275 // clone is detected, reset the client id and low entropy source. This | 287 // clone is detected, reset the client id and low entropy source. This |
| 276 // should not be called more than once. | 288 // should not be called more than once. |
| 277 void CheckForClonedInstall( | 289 void CheckForClonedInstall( |
| 278 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 290 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 279 | 291 |
| 292 protected: |
| 293 // Exposed for testing. |
| 294 metrics::MetricsLogManager* log_manager() { return &log_manager_; } |
| 295 |
| 280 private: | 296 private: |
| 281 // The MetricsService has a lifecycle that is stored as a state. | 297 // The MetricsService has a lifecycle that is stored as a state. |
| 282 // See metrics_service.cc for description of this lifecycle. | 298 // See metrics_service.cc for description of this lifecycle. |
| 283 enum State { | 299 enum State { |
| 284 INITIALIZED, // Constructor was called. | 300 INITIALIZED, // Constructor was called. |
| 285 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to | 301 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to |
| 286 // complete. | 302 // complete. |
| 287 INIT_TASK_DONE, // Waiting for timer to send initial log. | 303 INIT_TASK_DONE, // Waiting for timer to send initial log. |
| 288 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. | 304 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. |
| 289 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent. | 305 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 static bool IsPluginProcess(int process_type); | 479 static bool IsPluginProcess(int process_type); |
| 464 | 480 |
| 465 // Returns a list of synthetic field trials that were active for the entire | 481 // Returns a list of synthetic field trials that were active for the entire |
| 466 // duration of the current log. | 482 // duration of the current log. |
| 467 void GetCurrentSyntheticFieldTrials( | 483 void GetCurrentSyntheticFieldTrials( |
| 468 std::vector<variations::ActiveGroupId>* synthetic_trials); | 484 std::vector<variations::ActiveGroupId>* synthetic_trials); |
| 469 | 485 |
| 470 // Creates a new MetricsLog instance with the given |log_type|. | 486 // Creates a new MetricsLog instance with the given |log_type|. |
| 471 scoped_ptr<MetricsLog> CreateLog(MetricsLog::LogType log_type); | 487 scoped_ptr<MetricsLog> CreateLog(MetricsLog::LogType log_type); |
| 472 | 488 |
| 489 // Record complete list of histograms into the current log. |
| 490 // Called when we close a log. |
| 491 void RecordCurrentHistograms(); |
| 492 |
| 493 // Record complete list of stability histograms into the current log, |
| 494 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. |
| 495 void RecordCurrentStabilityHistograms(); |
| 496 |
| 497 // Manager for the various in-flight logs. |
| 498 metrics::MetricsLogManager log_manager_; |
| 499 |
| 500 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. |
| 501 base::HistogramSnapshotManager histogram_snapshot_manager_; |
| 502 |
| 473 // Used to manage various metrics reporting state prefs, such as client id, | 503 // Used to manage various metrics reporting state prefs, such as client id, |
| 474 // low entropy source and whether metrics reporting is enabled. Weak pointer. | 504 // low entropy source and whether metrics reporting is enabled. Weak pointer. |
| 475 metrics::MetricsStateManager* const state_manager_; | 505 metrics::MetricsStateManager* const state_manager_; |
| 476 | 506 |
| 477 // Used to interact with the embedder. Weak pointer; must outlive |this| | 507 // Used to interact with the embedder. Weak pointer; must outlive |this| |
| 478 // instance. | 508 // instance. |
| 479 metrics::MetricsServiceClient* const client_; | 509 metrics::MetricsServiceClient* const client_; |
| 480 | 510 |
| 481 // Registered metrics providers. | 511 // Registered metrics providers. |
| 482 ScopedVector<metrics::MetricsProvider> metrics_providers_; | 512 ScopedVector<metrics::MetricsProvider> metrics_providers_; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 | 650 |
| 621 // Registers/unregisters |observer| to receive MetricsLog notifications | 651 // Registers/unregisters |observer| to receive MetricsLog notifications |
| 622 // from metrics service. | 652 // from metrics service. |
| 623 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); | 653 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); |
| 624 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); | 654 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); |
| 625 | 655 |
| 626 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 656 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
| 627 }; | 657 }; |
| 628 | 658 |
| 629 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 659 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |