| 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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" | 30 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
| 31 #include "components/metrics/metrics_log_manager.h" | 31 #include "components/metrics/metrics_log_manager.h" |
| 32 #include "components/metrics/metrics_provider.h" | 32 #include "components/metrics/metrics_provider.h" |
| 33 #include "components/metrics/metrics_service_observer.h" | 33 #include "components/metrics/metrics_service_observer.h" |
| 34 #include "components/variations/active_field_trials.h" | 34 #include "components/variations/active_field_trials.h" |
| 35 #include "net/url_request/url_fetcher_delegate.h" | |
| 36 | 35 |
| 37 class GoogleUpdateMetricsProviderWin; | 36 class GoogleUpdateMetricsProviderWin; |
| 38 class MetricsReportingScheduler; | 37 class MetricsReportingScheduler; |
| 39 class PrefService; | 38 class PrefService; |
| 40 class PrefRegistrySimple; | 39 class PrefRegistrySimple; |
| 41 class PluginMetricsProvider; | 40 class PluginMetricsProvider; |
| 42 | 41 |
| 43 namespace base { | 42 namespace base { |
| 44 class DictionaryValue; | 43 class DictionaryValue; |
| 45 class HistogramSamples; | 44 class HistogramSamples; |
| 46 class MessageLoopProxy; | 45 class MessageLoopProxy; |
| 47 class PrefService; | 46 class PrefService; |
| 48 } | 47 } |
| 49 | 48 |
| 50 namespace variations { | 49 namespace variations { |
| 51 struct ActiveGroupId; | 50 struct ActiveGroupId; |
| 52 } | 51 } |
| 53 | 52 |
| 54 namespace content { | 53 namespace content { |
| 55 } | 54 } |
| 56 | 55 |
| 57 namespace metrics { | 56 namespace metrics { |
| 57 class MetricsLogUploader; |
| 58 class MetricsServiceClient; | 58 class MetricsServiceClient; |
| 59 class MetricsStateManager; | 59 class MetricsStateManager; |
| 60 } | 60 } |
| 61 | 61 |
| 62 namespace net { | 62 namespace net { |
| 63 class URLFetcher; | 63 class URLFetcher; |
| 64 } | 64 } |
| 65 | 65 |
| 66 namespace tracked_objects { | 66 namespace tracked_objects { |
| 67 struct ProcessDataSnapshot; | 67 struct ProcessDataSnapshot; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 82 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 82 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 83 | 83 |
| 84 // 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 |
| 85 // 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 |
| 86 // friend class. | 86 // friend class. |
| 87 SyntheticTrialGroup(uint32 trial, uint32 group); | 87 SyntheticTrialGroup(uint32 trial, uint32 group); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 class MetricsService | 90 class MetricsService |
| 91 : public base::HistogramFlattener, | 91 : public base::HistogramFlattener, |
| 92 public chrome_browser_metrics::TrackingSynchronizerObserver, | 92 public chrome_browser_metrics::TrackingSynchronizerObserver { |
| 93 public net::URLFetcherDelegate { | |
| 94 public: | 93 public: |
| 95 // The execution phase of the browser. | 94 // The execution phase of the browser. |
| 96 enum ExecutionPhase { | 95 enum ExecutionPhase { |
| 97 UNINITIALIZED_PHASE = 0, | 96 UNINITIALIZED_PHASE = 0, |
| 98 START_METRICS_RECORDING = 100, | 97 START_METRICS_RECORDING = 100, |
| 99 CREATE_PROFILE = 200, | 98 CREATE_PROFILE = 200, |
| 100 STARTUP_TIMEBOMB_ARM = 300, | 99 STARTUP_TIMEBOMB_ARM = 300, |
| 101 THREAD_WATCHER_START = 400, | 100 THREAD_WATCHER_START = 400, |
| 102 MAIN_MESSAGE_LOOP_RUN = 500, | 101 MAIN_MESSAGE_LOOP_RUN = 500, |
| 103 SHUTDOWN_TIMEBOMB_ARM = 600, | 102 SHUTDOWN_TIMEBOMB_ARM = 600, |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 // system profile from the previous session. | 349 // system profile from the previous session. |
| 351 void PrepareInitialStabilityLog(); | 350 void PrepareInitialStabilityLog(); |
| 352 | 351 |
| 353 // Prepares the initial metrics log, which includes startup histograms and | 352 // Prepares the initial metrics log, which includes startup histograms and |
| 354 // profiler data, as well as incremental stability-related metrics. | 353 // profiler data, as well as incremental stability-related metrics. |
| 355 void PrepareInitialMetricsLog(); | 354 void PrepareInitialMetricsLog(); |
| 356 | 355 |
| 357 // Uploads the currently staged log (which must be non-null). | 356 // Uploads the currently staged log (which must be non-null). |
| 358 void SendStagedLog(); | 357 void SendStagedLog(); |
| 359 | 358 |
| 360 // Prepared the staged log to be passed to the server. Upon return, | 359 // Called after transmission completes (either successfully or with failure). |
| 361 // current_fetch_ should be reset with its upload data set to a compressed | 360 void OnLogUploadComplete(int response_code); |
| 362 // copy of the staged log. | |
| 363 void PrepareFetchWithStagedLog(); | |
| 364 | |
| 365 // Implementation of net::URLFetcherDelegate. Called after transmission | |
| 366 // completes (either successfully or with failure). | |
| 367 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 368 | 361 |
| 369 // Reads, increments and then sets the specified integer preference. | 362 // Reads, increments and then sets the specified integer preference. |
| 370 void IncrementPrefValue(const char* path); | 363 void IncrementPrefValue(const char* path); |
| 371 | 364 |
| 372 // Reads, increments and then sets the specified long preference that is | 365 // Reads, increments and then sets the specified long preference that is |
| 373 // stored as a string. | 366 // stored as a string. |
| 374 void IncrementLongPrefsValue(const char* path); | 367 void IncrementLongPrefsValue(const char* path); |
| 375 | 368 |
| 376 // Records that the browser was shut down cleanly. | 369 // Records that the browser was shut down cleanly. |
| 377 void LogCleanShutdown(); | 370 void LogCleanShutdown(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 439 |
| 447 #if defined(OS_WIN) | 440 #if defined(OS_WIN) |
| 448 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_; | 441 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_; |
| 449 #endif | 442 #endif |
| 450 | 443 |
| 451 // The initial metrics log, used to record startup metrics (histograms and | 444 // The initial metrics log, used to record startup metrics (histograms and |
| 452 // profiler data). Note that if a crash occurred in the previous session, an | 445 // profiler data). Note that if a crash occurred in the previous session, an |
| 453 // initial stability log may be sent before this. | 446 // initial stability log may be sent before this. |
| 454 scoped_ptr<MetricsLog> initial_metrics_log_; | 447 scoped_ptr<MetricsLog> initial_metrics_log_; |
| 455 | 448 |
| 456 // The outstanding transmission appears as a URL Fetch operation. | 449 // Instance of the helper class for uploading logs. |
| 457 scoped_ptr<net::URLFetcher> current_fetch_; | 450 scoped_ptr<metrics::MetricsLogUploader> log_uploader_; |
| 451 |
| 452 // Whether there is a current log upload in progress. |
| 453 bool log_upload_in_progress_; |
| 458 | 454 |
| 459 // Whether the MetricsService object has received any notifications since | 455 // Whether the MetricsService object has received any notifications since |
| 460 // the last time a transmission was sent. | 456 // the last time a transmission was sent. |
| 461 bool idle_since_last_transmission_; | 457 bool idle_since_last_transmission_; |
| 462 | 458 |
| 463 // A number that identifies the how many times the app has been launched. | 459 // A number that identifies the how many times the app has been launched. |
| 464 int session_id_; | 460 int session_id_; |
| 465 | 461 |
| 466 // Weak pointers factory used to post task on different threads. All weak | 462 // Weak pointers factory used to post task on different threads. All weak |
| 467 // pointers managed by this factory have the same lifetime as MetricsService. | 463 // pointers managed by this factory have the same lifetime as MetricsService. |
| 468 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 464 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
| 469 | 465 |
| 470 // Weak pointers factory used for saving state. All weak pointers managed by | 466 // Weak pointers factory used for saving state. All weak pointers managed by |
| 471 // this factory are invalidated in ScheduleNextStateSave. | 467 // this factory are invalidated in ScheduleNextStateSave. |
| 472 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 468 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
| 473 | 469 |
| 474 // The scheduler for determining when uploads should happen. | 470 // The scheduler for determining when uploads should happen. |
| 475 scoped_ptr<MetricsReportingScheduler> scheduler_; | 471 scoped_ptr<MetricsReportingScheduler> scheduler_; |
| 476 | 472 |
| 477 // Indicates that an asynchronous reporting step is running. | |
| 478 // This is used only for debugging. | |
| 479 bool waiting_for_asynchronous_reporting_step_; | |
| 480 | |
| 481 // Stores the time of the first call to |GetUptimes()|. | 473 // Stores the time of the first call to |GetUptimes()|. |
| 482 base::TimeTicks first_updated_time_; | 474 base::TimeTicks first_updated_time_; |
| 483 | 475 |
| 484 // Stores the time of the last call to |GetUptimes()|. | 476 // Stores the time of the last call to |GetUptimes()|. |
| 485 base::TimeTicks last_updated_time_; | 477 base::TimeTicks last_updated_time_; |
| 486 | 478 |
| 487 // Execution phase the browser is in. | 479 // Execution phase the browser is in. |
| 488 static ExecutionPhase execution_phase_; | 480 static ExecutionPhase execution_phase_; |
| 489 | 481 |
| 490 // Reduntant marker to check that we completed our shutdown, and set the | 482 // Reduntant marker to check that we completed our shutdown, and set the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 504 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 496 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 505 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); | 497 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); |
| 506 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 498 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
| 507 PermutedEntropyCacheClearedWhenLowEntropyReset); | 499 PermutedEntropyCacheClearedWhenLowEntropyReset); |
| 508 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 500 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 509 | 501 |
| 510 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 502 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 511 }; | 503 }; |
| 512 | 504 |
| 513 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 505 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |