| 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/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 21 #include "chrome/browser/metrics/metrics_log.h" | 21 #include "chrome/browser/metrics/metrics_log.h" |
| 22 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 22 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
| 23 #include "chrome/common/metrics/metrics_service_base.h" | 23 #include "chrome/common/metrics/metrics_service_base.h" |
| 24 #include "chrome/installer/util/google_update_settings.h" | 24 #include "chrome/installer/util/google_update_settings.h" |
| 25 #include "content/public/browser/browser_child_process_observer.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/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
| 28 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
| 29 | 30 |
| 30 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 31 #include "chrome/browser/chromeos/external_metrics.h" | 32 #include "chrome/browser/chromeos/external_metrics.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 class MetricsReportingScheduler; | 35 class MetricsReportingScheduler; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 62 namespace tracked_objects { | 63 namespace tracked_objects { |
| 63 struct ProcessDataSnapshot; | 64 struct ProcessDataSnapshot; |
| 64 } | 65 } |
| 65 | 66 |
| 66 namespace webkit { | 67 namespace webkit { |
| 67 struct WebPluginInfo; | 68 struct WebPluginInfo; |
| 68 } | 69 } |
| 69 | 70 |
| 70 class MetricsService | 71 class MetricsService |
| 71 : public chrome_browser_metrics::TrackingSynchronizerObserver, | 72 : public chrome_browser_metrics::TrackingSynchronizerObserver, |
| 73 public content::BrowserChildProcessObserver, |
| 72 public content::NotificationObserver, | 74 public content::NotificationObserver, |
| 73 public net::URLFetcherDelegate, | 75 public net::URLFetcherDelegate, |
| 74 public MetricsServiceBase { | 76 public MetricsServiceBase { |
| 75 public: | 77 public: |
| 76 MetricsService(); | 78 MetricsService(); |
| 77 virtual ~MetricsService(); | 79 virtual ~MetricsService(); |
| 78 | 80 |
| 79 // Starts the metrics system, turning on recording and uploading of metrics. | 81 // Starts the metrics system, turning on recording and uploading of metrics. |
| 80 // Should be called when starting up with metrics enabled, or when metrics | 82 // Should be called when starting up with metrics enabled, or when metrics |
| 81 // are turned on. | 83 // are turned on. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // At startup, prefs needs to be called with a list of all the pref names and | 126 // At startup, prefs needs to be called with a list of all the pref names and |
| 125 // types we'll be using. | 127 // types we'll be using. |
| 126 static void RegisterPrefs(PrefRegistrySimple* registry); | 128 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 127 | 129 |
| 128 // Set up notifications which indicate that a user is performing work. This is | 130 // Set up notifications which indicate that a user is performing work. This is |
| 129 // useful to allow some features to sleep, until the machine becomes active, | 131 // useful to allow some features to sleep, until the machine becomes active, |
| 130 // such as precluding UMA uploads unless there was recent activity. | 132 // such as precluding UMA uploads unless there was recent activity. |
| 131 static void SetUpNotifications(content::NotificationRegistrar* registrar, | 133 static void SetUpNotifications(content::NotificationRegistrar* registrar, |
| 132 content::NotificationObserver* observer); | 134 content::NotificationObserver* observer); |
| 133 | 135 |
| 136 // Implementation of content::BrowserChildProcessObserver |
| 137 virtual void BrowserChildProcessHostConnected( |
| 138 const content::ChildProcessData& data) OVERRIDE; |
| 139 virtual void BrowserChildProcessCrashed( |
| 140 const content::ChildProcessData& data) OVERRIDE; |
| 141 virtual void BrowserChildProcessInstanceCreated( |
| 142 const content::ChildProcessData& data) OVERRIDE; |
| 143 |
| 134 // Implementation of content::NotificationObserver | 144 // Implementation of content::NotificationObserver |
| 135 virtual void Observe(int type, | 145 virtual void Observe(int type, |
| 136 const content::NotificationSource& source, | 146 const content::NotificationSource& source, |
| 137 const content::NotificationDetails& details) OVERRIDE; | 147 const content::NotificationDetails& details) OVERRIDE; |
| 138 | 148 |
| 139 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is | 149 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is |
| 140 // reset when RecordCompletedSessionEnd is invoked. | 150 // reset when RecordCompletedSessionEnd is invoked. |
| 141 void RecordStartOfSessionEnd(); | 151 void RecordStartOfSessionEnd(); |
| 142 | 152 |
| 143 // This should be called when the application is shutting down. It records | 153 // This should be called when the application is shutting down. It records |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 214 |
| 205 // Designates which entropy source was returned from this MetricsService. | 215 // Designates which entropy source was returned from this MetricsService. |
| 206 // This is used for testing to validate that we return the correct source | 216 // This is used for testing to validate that we return the correct source |
| 207 // depending on the state of the service. | 217 // depending on the state of the service. |
| 208 enum EntropySourceReturned { | 218 enum EntropySourceReturned { |
| 209 LAST_ENTROPY_NONE, | 219 LAST_ENTROPY_NONE, |
| 210 LAST_ENTROPY_LOW, | 220 LAST_ENTROPY_LOW, |
| 211 LAST_ENTROPY_HIGH, | 221 LAST_ENTROPY_HIGH, |
| 212 }; | 222 }; |
| 213 | 223 |
| 224 struct ChildProcessStats; |
| 225 |
| 214 // First part of the init task. Called on the FILE thread to load hardware | 226 // First part of the init task. Called on the FILE thread to load hardware |
| 215 // class information. | 227 // class information. |
| 216 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self, | 228 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self, |
| 217 base::MessageLoopProxy* target_loop); | 229 base::MessageLoopProxy* target_loop); |
| 218 | 230 |
| 219 // Callback from InitTaskGetHardwareClass() that continues the init task by | 231 // Callback from InitTaskGetHardwareClass() that continues the init task by |
| 220 // loading plugin information. | 232 // loading plugin information. |
| 221 void OnInitTaskGotHardwareClass(const std::string& hardware_class); | 233 void OnInitTaskGotHardwareClass(const std::string& hardware_class); |
| 222 | 234 |
| 223 // Callback from PluginService::GetPlugins() that continues the init task by | 235 // Callback from PluginService::GetPlugins() that continues the init task by |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 void LogRendererCrash(content::RenderProcessHost* host, | 367 void LogRendererCrash(content::RenderProcessHost* host, |
| 356 base::TerminationStatus status, | 368 base::TerminationStatus status, |
| 357 int exit_code); | 369 int exit_code); |
| 358 | 370 |
| 359 // Records a renderer process hang. | 371 // Records a renderer process hang. |
| 360 void LogRendererHang(); | 372 void LogRendererHang(); |
| 361 | 373 |
| 362 // Records that the browser was shut down cleanly. | 374 // Records that the browser was shut down cleanly. |
| 363 void LogCleanShutdown(); | 375 void LogCleanShutdown(); |
| 364 | 376 |
| 365 // Records a child process related notification. These are recorded to an | 377 // Returns reference to ChildProcessStats corresponding to |data|. |
| 366 // in-object buffer because these notifications are sent on page load, and we | 378 ChildProcessStats& GetChildProcessStats( |
| 367 // don't want to slow that down. | 379 const content::ChildProcessData& data); |
| 368 void LogChildProcessChange(int type, | |
| 369 const content::NotificationSource& source, | |
| 370 const content::NotificationDetails& details); | |
| 371 | 380 |
| 372 // Logs the number of keywords. | 381 // Logs the number of keywords. |
| 373 void LogKeywordCount(size_t keyword_count); | 382 void LogKeywordCount(size_t keyword_count); |
| 374 | 383 |
| 375 // Saves plugin-related updates from the in-object buffer to Local State | 384 // Saves plugin-related updates from the in-object buffer to Local State |
| 376 // for retrieval next time we send a Profile log (generally next launch). | 385 // for retrieval next time we send a Profile log (generally next launch). |
| 377 void RecordPluginChanges(PrefService* pref); | 386 void RecordPluginChanges(PrefService* pref); |
| 378 | 387 |
| 379 // Records state that should be periodically saved, like uptime and | 388 // Records state that should be periodically saved, like uptime and |
| 380 // buffered plugin stability statistics. | 389 // buffered plugin stability statistics. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // A number that identifies the how many times the app has been launched. | 467 // A number that identifies the how many times the app has been launched. |
| 459 int session_id_; | 468 int session_id_; |
| 460 | 469 |
| 461 // Maps WebContentses (corresponding to tabs) or Browsers (corresponding to | 470 // Maps WebContentses (corresponding to tabs) or Browsers (corresponding to |
| 462 // Windows) to a unique integer that we will use to identify them. | 471 // Windows) to a unique integer that we will use to identify them. |
| 463 // |next_window_id_| is used to track which IDs we have used so far. | 472 // |next_window_id_| is used to track which IDs we have used so far. |
| 464 typedef std::map<uintptr_t, int> WindowMap; | 473 typedef std::map<uintptr_t, int> WindowMap; |
| 465 WindowMap window_map_; | 474 WindowMap window_map_; |
| 466 int next_window_id_; | 475 int next_window_id_; |
| 467 | 476 |
| 468 // Buffer of child process notifications for quick access. See | 477 // Buffer of child process notifications for quick access. |
| 469 // ChildProcessStats documentation above for more details. | |
| 470 struct ChildProcessStats; | |
| 471 std::map<string16, ChildProcessStats> child_process_stats_buffer_; | 478 std::map<string16, ChildProcessStats> child_process_stats_buffer_; |
| 472 | 479 |
| 473 // Weak pointers factory used to post task on different threads. All weak | 480 // Weak pointers factory used to post task on different threads. All weak |
| 474 // pointers managed by this factory have the same lifetime as MetricsService. | 481 // pointers managed by this factory have the same lifetime as MetricsService. |
| 475 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 482 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
| 476 | 483 |
| 477 // Weak pointers factory used for saving state. All weak pointers managed by | 484 // Weak pointers factory used for saving state. All weak pointers managed by |
| 478 // this factory are invalidated in ScheduleNextStateSave. | 485 // this factory are invalidated in ScheduleNextStateSave. |
| 479 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 486 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
| 480 | 487 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 friend class extensions::ExtensionDownloader; | 526 friend class extensions::ExtensionDownloader; |
| 520 friend class extensions::ManifestFetchData; | 527 friend class extensions::ManifestFetchData; |
| 521 | 528 |
| 522 // Returns true if prefs::kMetricsReportingEnabled is set. | 529 // Returns true if prefs::kMetricsReportingEnabled is set. |
| 523 static bool IsMetricsReportingEnabled(); | 530 static bool IsMetricsReportingEnabled(); |
| 524 | 531 |
| 525 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 532 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
| 526 }; | 533 }; |
| 527 | 534 |
| 528 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 535 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |