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 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/cancelable_callback.h" | |
| 17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 20 #include "base/process_util.h" | 21 #include "base/process_util.h" |
| 21 #include "chrome/browser/metrics/metrics_log.h" | 22 #include "chrome/browser/metrics/metrics_log.h" |
| 22 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 23 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
| 23 #include "chrome/common/metrics/metrics_service_base.h" | 24 #include "chrome/common/metrics/metrics_service_base.h" |
| 24 #include "chrome/installer/util/google_update_settings.h" | 25 #include "chrome/installer/util/google_update_settings.h" |
| 25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
| 27 #include "content/public/common/url_fetcher_delegate.h" | 28 #include "content/public/common/url_fetcher_delegate.h" |
| 28 | 29 |
| 29 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 30 #include "chrome/browser/chromeos/external_metrics.h" | 31 #include "chrome/browser/chromeos/external_metrics.h" |
| 32 #include "chrome/browser/chromeos/system/statistics_provider.h" | |
| 31 #endif | 33 #endif |
| 32 | 34 |
| 33 class BookmarkModel; | 35 class BookmarkModel; |
| 34 class BookmarkNode; | 36 class BookmarkNode; |
| 35 class MetricsReportingScheduler; | 37 class MetricsReportingScheduler; |
| 36 class PrefService; | 38 class PrefService; |
| 37 class Profile; | 39 class Profile; |
| 38 class TemplateURLService; | 40 class TemplateURLService; |
| 39 | 41 |
| 40 namespace base { | 42 namespace base { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 59 } | 61 } |
| 60 | 62 |
| 61 namespace webkit { | 63 namespace webkit { |
| 62 struct WebPluginInfo; | 64 struct WebPluginInfo; |
| 63 } | 65 } |
| 64 | 66 |
| 65 class MetricsService | 67 class MetricsService |
| 66 : public chrome_browser_metrics::TrackingSynchronizerObserver, | 68 : public chrome_browser_metrics::TrackingSynchronizerObserver, |
| 67 public content::NotificationObserver, | 69 public content::NotificationObserver, |
| 68 public content::URLFetcherDelegate, | 70 public content::URLFetcherDelegate, |
| 71 #if defined(OS_CHROMEOS) | |
| 72 public chromeos::system::StatisticsProvider::Observer, | |
| 73 #endif | |
| 69 public MetricsServiceBase { | 74 public MetricsServiceBase { |
| 70 public: | 75 public: |
| 71 MetricsService(); | 76 MetricsService(); |
| 72 virtual ~MetricsService(); | 77 virtual ~MetricsService(); |
| 73 | 78 |
| 74 // Start/stop the metrics recording and uploading machine. These should be | 79 // Start/stop the metrics recording and uploading machine. These should be |
| 75 // used on startup and when the user clicks the checkbox in the prefs. | 80 // used on startup and when the user clicks the checkbox in the prefs. |
| 76 // StartRecordingOnly starts the metrics recording but not reporting, for use | 81 // StartRecordingOnly starts the metrics recording but not reporting, for use |
| 77 // in tests only. | 82 // in tests only. |
| 78 void Start(); | 83 void Start(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 INITIAL_LOG_READY, // Initial log generated, and waiting for reply. | 156 INITIAL_LOG_READY, // Initial log generated, and waiting for reply. |
| 152 SENDING_OLD_LOGS, // Sending unsent logs from previous session. | 157 SENDING_OLD_LOGS, // Sending unsent logs from previous session. |
| 153 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue. | 158 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue. |
| 154 }; | 159 }; |
| 155 | 160 |
| 156 enum ShutdownCleanliness { | 161 enum ShutdownCleanliness { |
| 157 CLEANLY_SHUTDOWN = 0xdeadbeef, | 162 CLEANLY_SHUTDOWN = 0xdeadbeef, |
| 158 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN | 163 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN |
| 159 }; | 164 }; |
| 160 | 165 |
| 161 // First part of the init task. Called on the FILE thread to load hardware | 166 // First init task, that starts retrieving the hardware class. It proceeds |
| 162 // class information. | 167 // to InitTaskGetPluginInfo after reading the hardware_class, or after |
| 163 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self, | 168 // timing out waiting for it. |
| 164 base::MessageLoopProxy* target_loop); | 169 void InitTaskGetHardwareClass(); |
| 165 | 170 |
| 166 // Callback from InitTaskGetHardwareClass() that continues the init task by | 171 #if defined(OS_CHROMEOS) |
| 167 // loading plugin information. | 172 // chromeos::system::StatisticsProvider::Observer implementation: |
| 168 void OnInitTaskGotHardwareClass(const std::string& hardware_class); | 173 virtual void OnMachineStatisticsReady() OVERRIDE; |
| 174 | |
| 175 // Handles a timeout while waiting for the StatisticsProvider to become ready | |
| 176 // during initialization. | |
| 177 void OnStatisticsProviderTimeout(); | |
| 178 #endif | |
| 179 | |
| 180 // Second init task, that starts retrieving plugin info. | |
| 181 void InitTaskGetPluginInfo(); | |
| 169 | 182 |
| 170 // Callback from PluginService::GetPlugins() that continues the init task by | 183 // Callback from PluginService::GetPlugins() that continues the init task by |
| 171 // launching a task to gather Google Update statistics. | 184 // launching a task to gather Google Update statistics. |
| 172 void OnInitTaskGotPluginInfo( | 185 void OnInitTaskGotPluginInfo( |
| 173 const std::vector<webkit::WebPluginInfo>& plugins); | 186 const std::vector<webkit::WebPluginInfo>& plugins); |
| 174 | 187 |
| 175 // Task launched by OnInitTaskGotPluginInfo() that continues the init task by | 188 // Task launched by OnInitTaskGotPluginInfo() that continues the init task by |
| 176 // loading Google Update statistics. Called on a blocking pool thread. | 189 // loading Google Update statistics. Called on a blocking pool thread. |
| 177 static void InitTaskGetGoogleUpdateData(base::WeakPtr<MetricsService> self, | 190 static void InitTaskGetGoogleUpdateData(base::WeakPtr<MetricsService> self, |
| 178 base::MessageLoopProxy* target_loop); | 191 base::MessageLoopProxy* target_loop); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 // The scheduler for determining when uploads should happen. | 446 // The scheduler for determining when uploads should happen. |
| 434 scoped_ptr<MetricsReportingScheduler> scheduler_; | 447 scoped_ptr<MetricsReportingScheduler> scheduler_; |
| 435 | 448 |
| 436 // Indicates that an asynchronous reporting step is running. | 449 // Indicates that an asynchronous reporting step is running. |
| 437 // This is used only for debugging. | 450 // This is used only for debugging. |
| 438 bool waiting_for_asynchronus_reporting_step_; | 451 bool waiting_for_asynchronus_reporting_step_; |
| 439 | 452 |
| 440 #if defined(OS_CHROMEOS) | 453 #if defined(OS_CHROMEOS) |
| 441 // The external metric service is used to log ChromeOS UMA events. | 454 // The external metric service is used to log ChromeOS UMA events. |
| 442 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; | 455 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; |
| 456 | |
| 457 // Used to resume initialization of the MetricsService when the | |
| 458 // StatisticsProvider becomes ready, or after timing out while waiting for it. | |
| 459 base::CancelableClosure timeout_callback_; | |
| 460 base::CancelableClosure on_ready_callback_; | |
|
Ilya Sherman
2012/05/16 01:01:17
nit: I'd recommend either prefixing both callbacks
Joao da Silva
2012/05/16 12:53:34
Renamed to on_timeout_callback_.
| |
| 443 #endif | 461 #endif |
| 444 | 462 |
| 445 // Reduntant marker to check that we completed our shutdown, and set the | 463 // Reduntant marker to check that we completed our shutdown, and set the |
| 446 // exited-cleanly bit in the prefs. | 464 // exited-cleanly bit in the prefs. |
| 447 static ShutdownCleanliness clean_shutdown_status_; | 465 static ShutdownCleanliness clean_shutdown_status_; |
| 448 | 466 |
| 449 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); | 467 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); |
| 450 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 468 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 451 | 469 |
| 452 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 470 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 453 }; | 471 }; |
| 454 | 472 |
| 455 // This class limits and documents access to the IsMetricsReportingEnabled() | 473 // This class limits and documents access to the IsMetricsReportingEnabled() |
| 456 // method. Since the method is private, each user has to be explicitly declared | 474 // method. Since the method is private, each user has to be explicitly declared |
| 457 // as a 'friend' below. | 475 // as a 'friend' below. |
| 458 class MetricsServiceHelper { | 476 class MetricsServiceHelper { |
| 459 private: | 477 private: |
| 460 friend class InstantFieldTrial; | 478 friend class InstantFieldTrial; |
| 461 friend bool prerender::IsOmniboxEnabled(Profile* profile); | 479 friend bool prerender::IsOmniboxEnabled(Profile* profile); |
| 462 friend class extensions::ExtensionDownloader; | 480 friend class extensions::ExtensionDownloader; |
| 463 | 481 |
| 464 // Returns true if prefs::kMetricsReportingEnabled is set. | 482 // Returns true if prefs::kMetricsReportingEnabled is set. |
| 465 static bool IsMetricsReportingEnabled(); | 483 static bool IsMetricsReportingEnabled(); |
| 466 | 484 |
| 467 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 485 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
| 468 }; | 486 }; |
| 469 | 487 |
| 470 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 488 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |