| 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/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 20 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram_flattener.h" | 22 #include "base/metrics/histogram_flattener.h" |
| 22 #include "base/metrics/histogram_snapshot_manager.h" | 23 #include "base/metrics/histogram_snapshot_manager.h" |
| 23 #include "base/metrics/user_metrics.h" | 24 #include "base/metrics/user_metrics.h" |
| 24 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
| 25 #include "base/process/kill.h" | |
| 26 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "chrome/browser/metrics/metrics_log.h" | 28 #include "chrome/browser/metrics/metrics_log.h" |
| 29 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 29 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
| 30 #include "components/metrics/metrics_log_manager.h" | 30 #include "components/metrics/metrics_log_manager.h" |
| 31 #include "components/metrics/metrics_provider.h" | 31 #include "components/metrics/metrics_provider.h" |
| 32 #include "components/metrics/metrics_service_observer.h" | 32 #include "components/metrics/metrics_service_observer.h" |
| 33 #include "components/variations/active_field_trials.h" | 33 #include "components/variations/active_field_trials.h" |
| 34 #include "content/public/browser/browser_child_process_observer.h" | 34 #include "content/public/browser/browser_child_process_observer.h" |
| 35 #include "content/public/browser/notification_observer.h" | |
| 36 #include "content/public/browser/notification_registrar.h" | |
| 37 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
| 38 #include "net/url_request/url_fetcher_delegate.h" | 36 #include "net/url_request/url_fetcher_delegate.h" |
| 39 | 37 |
| 40 class GoogleUpdateMetricsProviderWin; | 38 class GoogleUpdateMetricsProviderWin; |
| 41 class MetricsReportingScheduler; | 39 class MetricsReportingScheduler; |
| 42 class PrefService; | 40 class PrefService; |
| 43 class PrefRegistrySimple; | 41 class PrefRegistrySimple; |
| 44 | 42 |
| 45 namespace base { | 43 namespace base { |
| 46 class DictionaryValue; | 44 class DictionaryValue; |
| 47 class HistogramSamples; | 45 class HistogramSamples; |
| 48 class MessageLoopProxy; | 46 class MessageLoopProxy; |
| 49 } | 47 } |
| 50 | 48 |
| 51 namespace variations { | 49 namespace variations { |
| 52 struct ActiveGroupId; | 50 struct ActiveGroupId; |
| 53 } | 51 } |
| 54 | 52 |
| 55 namespace content { | 53 namespace content { |
| 56 class RenderProcessHost; | |
| 57 class WebContents; | |
| 58 struct WebPluginInfo; | 54 struct WebPluginInfo; |
| 59 } | 55 } |
| 60 | 56 |
| 61 namespace metrics { | 57 namespace metrics { |
| 62 class MetricsServiceClient; | 58 class MetricsServiceClient; |
| 63 class MetricsStateManager; | 59 class MetricsStateManager; |
| 64 } | 60 } |
| 65 | 61 |
| 66 namespace net { | 62 namespace net { |
| 67 class URLFetcher; | 63 class URLFetcher; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 88 // This constructor is private specifically so as to control which code is | 84 // This constructor is private specifically so as to control which code is |
| 89 // able to access it. New code that wishes to use it should be added as a | 85 // able to access it. New code that wishes to use it should be added as a |
| 90 // friend class. | 86 // friend class. |
| 91 SyntheticTrialGroup(uint32 trial, uint32 group); | 87 SyntheticTrialGroup(uint32 trial, uint32 group); |
| 92 }; | 88 }; |
| 93 | 89 |
| 94 class MetricsService | 90 class MetricsService |
| 95 : public base::HistogramFlattener, | 91 : public base::HistogramFlattener, |
| 96 public chrome_browser_metrics::TrackingSynchronizerObserver, | 92 public chrome_browser_metrics::TrackingSynchronizerObserver, |
| 97 public content::BrowserChildProcessObserver, | 93 public content::BrowserChildProcessObserver, |
| 98 public content::NotificationObserver, | |
| 99 public net::URLFetcherDelegate { | 94 public net::URLFetcherDelegate { |
| 100 public: | 95 public: |
| 101 // The execution phase of the browser. | 96 // The execution phase of the browser. |
| 102 enum ExecutionPhase { | 97 enum ExecutionPhase { |
| 103 UNINITIALIZED_PHASE = 0, | 98 UNINITIALIZED_PHASE = 0, |
| 104 START_METRICS_RECORDING = 100, | 99 START_METRICS_RECORDING = 100, |
| 105 CREATE_PROFILE = 200, | 100 CREATE_PROFILE = 200, |
| 106 STARTUP_TIMEBOMB_ARM = 300, | 101 STARTUP_TIMEBOMB_ARM = 300, |
| 107 THREAD_WATCHER_START = 400, | 102 THREAD_WATCHER_START = 400, |
| 108 MAIN_MESSAGE_LOOP_RUN = 500, | 103 MAIN_MESSAGE_LOOP_RUN = 500, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // If metrics reporting is enabled, this method returns an entropy provider | 154 // If metrics reporting is enabled, this method returns an entropy provider |
| 160 // that has a high source of entropy, partially based on the client ID. | 155 // that has a high source of entropy, partially based on the client ID. |
| 161 // Otherwise, it returns an entropy provider that is based on a low entropy | 156 // Otherwise, it returns an entropy provider that is based on a low entropy |
| 162 // source. | 157 // source. |
| 163 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(); | 158 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(); |
| 164 | 159 |
| 165 // At startup, prefs needs to be called with a list of all the pref names and | 160 // At startup, prefs needs to be called with a list of all the pref names and |
| 166 // types we'll be using. | 161 // types we'll be using. |
| 167 static void RegisterPrefs(PrefRegistrySimple* registry); | 162 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 168 | 163 |
| 169 // Set up notifications which indicate that a user is performing work. This is | |
| 170 // useful to allow some features to sleep, until the machine becomes active, | |
| 171 // such as precluding UMA uploads unless there was recent activity. | |
| 172 static void SetUpNotifications(content::NotificationRegistrar* registrar, | |
| 173 content::NotificationObserver* observer); | |
| 174 | |
| 175 // HistogramFlattener: | 164 // HistogramFlattener: |
| 176 virtual void RecordDelta(const base::HistogramBase& histogram, | 165 virtual void RecordDelta(const base::HistogramBase& histogram, |
| 177 const base::HistogramSamples& snapshot) OVERRIDE; | 166 const base::HistogramSamples& snapshot) OVERRIDE; |
| 178 virtual void InconsistencyDetected( | 167 virtual void InconsistencyDetected( |
| 179 base::HistogramBase::Inconsistency problem) OVERRIDE; | 168 base::HistogramBase::Inconsistency problem) OVERRIDE; |
| 180 virtual void UniqueInconsistencyDetected( | 169 virtual void UniqueInconsistencyDetected( |
| 181 base::HistogramBase::Inconsistency problem) OVERRIDE; | 170 base::HistogramBase::Inconsistency problem) OVERRIDE; |
| 182 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE; | 171 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE; |
| 183 | 172 |
| 184 // Implementation of content::BrowserChildProcessObserver | 173 // Implementation of content::BrowserChildProcessObserver |
| 185 virtual void BrowserChildProcessHostConnected( | 174 virtual void BrowserChildProcessHostConnected( |
| 186 const content::ChildProcessData& data) OVERRIDE; | 175 const content::ChildProcessData& data) OVERRIDE; |
| 187 virtual void BrowserChildProcessCrashed( | 176 virtual void BrowserChildProcessCrashed( |
| 188 const content::ChildProcessData& data) OVERRIDE; | 177 const content::ChildProcessData& data) OVERRIDE; |
| 189 virtual void BrowserChildProcessInstanceCreated( | 178 virtual void BrowserChildProcessInstanceCreated( |
| 190 const content::ChildProcessData& data) OVERRIDE; | 179 const content::ChildProcessData& data) OVERRIDE; |
| 191 | 180 |
| 192 // content::NotificationObserver: | |
| 193 virtual void Observe(int type, | |
| 194 const content::NotificationSource& source, | |
| 195 const content::NotificationDetails& details) OVERRIDE; | |
| 196 | |
| 197 // This should be called when the application is not idle, i.e. the user seems | 181 // This should be called when the application is not idle, i.e. the user seems |
| 198 // to be interacting with the application. | 182 // to be interacting with the application. |
| 199 void OnApplicationNotIdle(); | 183 void OnApplicationNotIdle(); |
| 200 | 184 |
| 201 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is | 185 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is |
| 202 // reset when RecordCompletedSessionEnd is invoked. | 186 // reset when RecordCompletedSessionEnd is invoked. |
| 203 void RecordStartOfSessionEnd(); | 187 void RecordStartOfSessionEnd(); |
| 204 | 188 |
| 205 // This should be called when the application is shutting down. It records | 189 // This should be called when the application is shutting down. It records |
| 206 // that session end was successful. | 190 // that session end was successful. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // completes (either successfully or with failure). | 390 // completes (either successfully or with failure). |
| 407 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 391 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 408 | 392 |
| 409 // Reads, increments and then sets the specified integer preference. | 393 // Reads, increments and then sets the specified integer preference. |
| 410 void IncrementPrefValue(const char* path); | 394 void IncrementPrefValue(const char* path); |
| 411 | 395 |
| 412 // Reads, increments and then sets the specified long preference that is | 396 // Reads, increments and then sets the specified long preference that is |
| 413 // stored as a string. | 397 // stored as a string. |
| 414 void IncrementLongPrefsValue(const char* path); | 398 void IncrementLongPrefsValue(const char* path); |
| 415 | 399 |
| 416 // Records a renderer process crash. | |
| 417 void LogRendererCrash(content::RenderProcessHost* host, | |
| 418 base::TerminationStatus status, | |
| 419 int exit_code); | |
| 420 | |
| 421 // Records a renderer process hang. | |
| 422 void LogRendererHang(); | |
| 423 | |
| 424 // Records that the browser was shut down cleanly. | 400 // Records that the browser was shut down cleanly. |
| 425 void LogCleanShutdown(); | 401 void LogCleanShutdown(); |
| 426 | 402 |
| 427 // Returns reference to ChildProcessStats corresponding to |data|. | 403 // Returns reference to ChildProcessStats corresponding to |data|. |
| 428 ChildProcessStats& GetChildProcessStats( | 404 ChildProcessStats& GetChildProcessStats( |
| 429 const content::ChildProcessData& data); | 405 const content::ChildProcessData& data); |
| 430 | 406 |
| 431 // Saves plugin-related updates from the in-object buffer to Local State | 407 // Saves plugin-related updates from the in-object buffer to Local State |
| 432 // for retrieval next time we send a Profile log (generally next launch). | 408 // for retrieval next time we send a Profile log (generally next launch). |
| 433 void RecordPluginChanges(PrefService* pref); | 409 void RecordPluginChanges(PrefService* pref); |
| 434 | 410 |
| 435 // Records state that should be periodically saved, like uptime and | 411 // Records state that should be periodically saved, like uptime and |
| 436 // buffered plugin stability statistics. | 412 // buffered plugin stability statistics. |
| 437 void RecordCurrentState(PrefService* pref); | 413 void RecordCurrentState(PrefService* pref); |
| 438 | 414 |
| 439 // Logs the initiation of a page load and uses |web_contents| to do | |
| 440 // additional logging of the type of page loaded. | |
| 441 void LogLoadStarted(content::WebContents* web_contents); | |
| 442 | |
| 443 // Checks whether events should currently be logged. | 415 // Checks whether events should currently be logged. |
| 444 bool ShouldLogEvents(); | 416 bool ShouldLogEvents(); |
| 445 | 417 |
| 446 // Sets the value of the specified path in prefs and schedules a save. | 418 // Sets the value of the specified path in prefs and schedules a save. |
| 447 void RecordBooleanPrefValue(const char* path, bool value); | 419 void RecordBooleanPrefValue(const char* path, bool value); |
| 448 | 420 |
| 449 // Returns true if process of type |type| should be counted as a plugin | 421 // Returns true if process of type |type| should be counted as a plugin |
| 450 // process, and false otherwise. | 422 // process, and false otherwise. |
| 451 static bool IsPluginProcess(int process_type); | 423 static bool IsPluginProcess(int process_type); |
| 452 | 424 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 478 | 450 |
| 479 // Used to interact with the embedder. Weak pointer; must outlive |this| | 451 // Used to interact with the embedder. Weak pointer; must outlive |this| |
| 480 // instance. | 452 // instance. |
| 481 metrics::MetricsServiceClient* const client_; | 453 metrics::MetricsServiceClient* const client_; |
| 482 | 454 |
| 483 // Registered metrics providers. | 455 // Registered metrics providers. |
| 484 ScopedVector<metrics::MetricsProvider> metrics_providers_; | 456 ScopedVector<metrics::MetricsProvider> metrics_providers_; |
| 485 | 457 |
| 486 base::ActionCallback action_callback_; | 458 base::ActionCallback action_callback_; |
| 487 | 459 |
| 488 content::NotificationRegistrar registrar_; | |
| 489 | |
| 490 // Indicate whether recording and reporting are currently happening. | 460 // Indicate whether recording and reporting are currently happening. |
| 491 // These should not be set directly, but by calling SetRecording and | 461 // These should not be set directly, but by calling SetRecording and |
| 492 // SetReporting. | 462 // SetReporting. |
| 493 bool recording_active_; | 463 bool recording_active_; |
| 494 bool reporting_active_; | 464 bool reporting_active_; |
| 495 | 465 |
| 496 // Indicate whether test mode is enabled, where the initial log should never | 466 // Indicate whether test mode is enabled, where the initial log should never |
| 497 // be cut, and logs are neither persisted nor uploaded. | 467 // be cut, and logs are neither persisted nor uploaded. |
| 498 bool test_mode_active_; | 468 bool test_mode_active_; |
| 499 | 469 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 553 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 584 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); | 554 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); |
| 585 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 555 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
| 586 PermutedEntropyCacheClearedWhenLowEntropyReset); | 556 PermutedEntropyCacheClearedWhenLowEntropyReset); |
| 587 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 557 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 588 | 558 |
| 589 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 559 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 590 }; | 560 }; |
| 591 | 561 |
| 592 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 562 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |