| 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" | |
| 17 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 20 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 21 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
| 22 #include "base/metrics/histogram_flattener.h" | 21 #include "base/metrics/histogram_flattener.h" |
| 23 #include "base/metrics/histogram_snapshot_manager.h" | 22 #include "base/metrics/histogram_snapshot_manager.h" |
| 24 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
| 25 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
| 26 #include "base/strings/string16.h" | 25 #include "base/strings/string16.h" |
| 27 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
| 28 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 29 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | |
| 30 #include "components/metrics/metrics_log.h" | 28 #include "components/metrics/metrics_log.h" |
| 31 #include "components/metrics/metrics_log_manager.h" | 29 #include "components/metrics/metrics_log_manager.h" |
| 32 #include "components/metrics/metrics_provider.h" | 30 #include "components/metrics/metrics_provider.h" |
| 33 #include "components/metrics/metrics_service_observer.h" | 31 #include "components/metrics/metrics_service_observer.h" |
| 34 #include "components/variations/active_field_trials.h" | 32 #include "components/variations/active_field_trials.h" |
| 35 | 33 |
| 36 class GoogleUpdateMetricsProviderWin; | |
| 37 class MetricsReportingScheduler; | 34 class MetricsReportingScheduler; |
| 38 class PrefService; | 35 class PrefService; |
| 39 class PrefRegistrySimple; | 36 class PrefRegistrySimple; |
| 40 class PluginMetricsProvider; | |
| 41 class ProfilerMetricsProvider; | |
| 42 | 37 |
| 43 namespace base { | 38 namespace base { |
| 44 class DictionaryValue; | 39 class DictionaryValue; |
| 45 class HistogramSamples; | 40 class HistogramSamples; |
| 46 class MessageLoopProxy; | 41 class MessageLoopProxy; |
| 47 class PrefService; | 42 class PrefService; |
| 48 } | 43 } |
| 49 | 44 |
| 50 namespace variations { | 45 namespace variations { |
| 51 struct ActiveGroupId; | 46 struct ActiveGroupId; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 81 private: | 76 private: |
| 82 friend class MetricsService; | 77 friend class MetricsService; |
| 83 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 78 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 84 | 79 |
| 85 // This constructor is private specifically so as to control which code is | 80 // This constructor is private specifically so as to control which code is |
| 86 // able to access it. New code that wishes to use it should be added as a | 81 // able to access it. New code that wishes to use it should be added as a |
| 87 // friend class. | 82 // friend class. |
| 88 SyntheticTrialGroup(uint32 trial, uint32 group); | 83 SyntheticTrialGroup(uint32 trial, uint32 group); |
| 89 }; | 84 }; |
| 90 | 85 |
| 91 class MetricsService | 86 class MetricsService : public base::HistogramFlattener { |
| 92 : public base::HistogramFlattener, | |
| 93 public chrome_browser_metrics::TrackingSynchronizerObserver { | |
| 94 public: | 87 public: |
| 95 // The execution phase of the browser. | 88 // The execution phase of the browser. |
| 96 enum ExecutionPhase { | 89 enum ExecutionPhase { |
| 97 UNINITIALIZED_PHASE = 0, | 90 UNINITIALIZED_PHASE = 0, |
| 98 START_METRICS_RECORDING = 100, | 91 START_METRICS_RECORDING = 100, |
| 99 CREATE_PROFILE = 200, | 92 CREATE_PROFILE = 200, |
| 100 STARTUP_TIMEBOMB_ARM = 300, | 93 STARTUP_TIMEBOMB_ARM = 300, |
| 101 THREAD_WATCHER_START = 400, | 94 THREAD_WATCHER_START = 400, |
| 102 MAIN_MESSAGE_LOOP_RUN = 500, | 95 MAIN_MESSAGE_LOOP_RUN = 500, |
| 103 SHUTDOWN_TIMEBOMB_ARM = 600, | 96 SHUTDOWN_TIMEBOMB_ARM = 600, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // This count is eventually send via UMA logs. | 193 // This count is eventually send via UMA logs. |
| 201 void RecordBreakpadRegistration(bool success); | 194 void RecordBreakpadRegistration(bool success); |
| 202 | 195 |
| 203 // Saves in the preferences if the browser is running under a debugger. | 196 // Saves in the preferences if the browser is running under a debugger. |
| 204 // This count is eventually send via UMA logs. | 197 // This count is eventually send via UMA logs. |
| 205 void RecordBreakpadHasDebugger(bool has_debugger); | 198 void RecordBreakpadHasDebugger(bool has_debugger); |
| 206 | 199 |
| 207 bool recording_active() const; | 200 bool recording_active() const; |
| 208 bool reporting_active() const; | 201 bool reporting_active() const; |
| 209 | 202 |
| 210 // TODO(blundell): Move this to ChromeMetricsServiceClient. | |
| 211 void LogPluginLoadingError(const base::FilePath& plugin_path); | |
| 212 | |
| 213 // Redundant test to ensure that we are notified of a clean exit. | 203 // Redundant test to ensure that we are notified of a clean exit. |
| 214 // This value should be true when process has completed shutdown. | 204 // This value should be true when process has completed shutdown. |
| 215 static bool UmaMetricsProperlyShutdown(); | 205 static bool UmaMetricsProperlyShutdown(); |
| 216 | 206 |
| 217 // Registers a field trial name and group to be used to annotate a UMA report | 207 // Registers a field trial name and group to be used to annotate a UMA report |
| 218 // with a particular Chrome configuration state. A UMA report will be | 208 // with a particular Chrome configuration state. A UMA report will be |
| 219 // annotated with this trial group if and only if all events in the report | 209 // annotated with this trial group if and only if all events in the report |
| 220 // were created after the trial is registered. Only one group name may be | 210 // were created after the trial is registered. Only one group name may be |
| 221 // registered at a time for a given trial_name. Only the last group name that | 211 // registered at a time for a given trial_name. Only the last group name that |
| 222 // is registered for a given trial name will be recorded. The values passed | 212 // is registered for a given trial name will be recorded. The values passed |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 enum ShutdownCleanliness { | 245 enum ShutdownCleanliness { |
| 256 CLEANLY_SHUTDOWN = 0xdeadbeef, | 246 CLEANLY_SHUTDOWN = 0xdeadbeef, |
| 257 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN | 247 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN |
| 258 }; | 248 }; |
| 259 | 249 |
| 260 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; | 250 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; |
| 261 | 251 |
| 262 // Calls into the client to start metrics gathering. | 252 // Calls into the client to start metrics gathering. |
| 263 void StartGatheringMetrics(); | 253 void StartGatheringMetrics(); |
| 264 | 254 |
| 265 // Callback that continues the init task by loading plugin information. | 255 // Callback that moves the state to INIT_TASK_DONE. When this is called, the |
| 266 void OnInitTaskGotHardwareClass(); | 256 // state should be INIT_TASK_SCHEDULED. |
| 267 | 257 void FinishedGatheringInitialMetrics(); |
| 268 // Called after the Plugin init task has been completed that continues the | |
| 269 // init task by launching a task to gather Google Update statistics. | |
| 270 void OnInitTaskGotPluginInfo(); | |
| 271 | |
| 272 // Called after GoogleUpdate init task has been completed that continues the | |
| 273 // init task by loading profiler data. | |
| 274 void OnInitTaskGotGoogleUpdateData(); | |
| 275 | 258 |
| 276 void OnUserAction(const std::string& action); | 259 void OnUserAction(const std::string& action); |
| 277 | 260 |
| 278 // TrackingSynchronizerObserver: | |
| 279 virtual void ReceivedProfilerData( | |
| 280 const tracked_objects::ProcessDataSnapshot& process_data, | |
| 281 int process_type) OVERRIDE; | |
| 282 // Callback that moves the state to INIT_TASK_DONE. | |
| 283 virtual void FinishedReceivingProfilerData() OVERRIDE; | |
| 284 | |
| 285 // Get the amount of uptime since this process started and since the last | 261 // Get the amount of uptime since this process started and since the last |
| 286 // call to this function. Also updates the cumulative uptime metric (stored | 262 // call to this function. Also updates the cumulative uptime metric (stored |
| 287 // as a pref) for uninstall. Uptimes are measured using TimeTicks, which | 263 // as a pref) for uninstall. Uptimes are measured using TimeTicks, which |
| 288 // guarantees that it is monotonic and does not jump if the user changes | 264 // guarantees that it is monotonic and does not jump if the user changes |
| 289 // his/her clock. The TimeTicks implementation also makes the clock not | 265 // his/her clock. The TimeTicks implementation also makes the clock not |
| 290 // count time the computer is suspended. | 266 // count time the computer is suspended. |
| 291 void GetUptimes(PrefService* pref, | 267 void GetUptimes(PrefService* pref, |
| 292 base::TimeDelta* incremental_uptime, | 268 base::TimeDelta* incremental_uptime, |
| 293 base::TimeDelta* uptime); | 269 base::TimeDelta* uptime); |
| 294 | 270 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // be cut, and logs are neither persisted nor uploaded. | 404 // be cut, and logs are neither persisted nor uploaded. |
| 429 bool test_mode_active_; | 405 bool test_mode_active_; |
| 430 | 406 |
| 431 // The progression of states made by the browser are recorded in the following | 407 // The progression of states made by the browser are recorded in the following |
| 432 // state. | 408 // state. |
| 433 State state_; | 409 State state_; |
| 434 | 410 |
| 435 // Whether the initial stability log has been recorded during startup. | 411 // Whether the initial stability log has been recorded during startup. |
| 436 bool has_initial_stability_log_; | 412 bool has_initial_stability_log_; |
| 437 | 413 |
| 438 ProfilerMetricsProvider* profiler_metrics_provider_; | |
| 439 | |
| 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 | 414 // 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 | 415 // profiler data). Note that if a crash occurred in the previous session, an |
| 450 // initial stability log may be sent before this. | 416 // initial stability log may be sent before this. |
| 451 scoped_ptr<MetricsLog> initial_metrics_log_; | 417 scoped_ptr<MetricsLog> initial_metrics_log_; |
| 452 | 418 |
| 453 // Instance of the helper class for uploading logs. | 419 // Instance of the helper class for uploading logs. |
| 454 scoped_ptr<metrics::MetricsLogUploader> log_uploader_; | 420 scoped_ptr<metrics::MetricsLogUploader> log_uploader_; |
| 455 | 421 |
| 456 // Whether there is a current log upload in progress. | 422 // Whether there is a current log upload in progress. |
| 457 bool log_upload_in_progress_; | 423 bool log_upload_in_progress_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 466 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 501 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); | 467 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); |
| 502 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 468 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
| 503 PermutedEntropyCacheClearedWhenLowEntropyReset); | 469 PermutedEntropyCacheClearedWhenLowEntropyReset); |
| 504 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 470 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 505 | 471 |
| 506 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 472 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 507 }; | 473 }; |
| 508 | 474 |
| 509 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 475 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |