| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 25 #include "chrome/browser/chromeos/external_metrics.h" | 25 #include "chrome/browser/chromeos/external_metrics.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 class BookmarkModel; | 28 class BookmarkModel; |
| 29 class BookmarkNode; | 29 class BookmarkNode; |
| 30 class DictionaryValue; | 30 class DictionaryValue; |
| 31 class ListValue; | 31 class ListValue; |
| 32 class HistogramSynchronizer; | 32 class HistogramSynchronizer; |
| 33 class MetricsLogBase; | 33 class MetricsLogBase; |
| 34 class MetricsReportingScheduler; |
| 34 class PrefService; | 35 class PrefService; |
| 35 class TemplateURLModel; | 36 class TemplateURLModel; |
| 36 | 37 |
| 37 namespace webkit { | 38 namespace webkit { |
| 38 namespace npapi { | 39 namespace npapi { |
| 39 struct WebPluginInfo; | 40 struct WebPluginInfo; |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 | 43 |
| 43 // Forward declaration of the xmlNode to avoid having tons of gyp files | |
| 44 // needing to depend on the libxml third party lib. | |
| 45 struct _xmlNode; | |
| 46 typedef struct _xmlNode xmlNode; | |
| 47 typedef xmlNode* xmlNodePtr; | |
| 48 | |
| 49 | 44 |
| 50 class MetricsService : public NotificationObserver, | 45 class MetricsService : public NotificationObserver, |
| 51 public URLFetcher::Delegate, | 46 public URLFetcher::Delegate, |
| 52 public MetricsServiceBase { | 47 public MetricsServiceBase { |
| 53 public: | 48 public: |
| 54 // Used to produce a historgram that keeps track of the status of recalling | 49 // Used to produce a historgram that keeps track of the status of recalling |
| 55 // persisted per logs. | 50 // persisted per logs. |
| 56 enum LogRecallStatus { | 51 enum LogRecallStatus { |
| 57 RECALL_SUCCESS, // We were able to correctly recall a persisted log. | 52 RECALL_SUCCESS, // We were able to correctly recall a persisted log. |
| 58 LIST_EMPTY, // Attempting to recall from an empty list. | 53 LIST_EMPTY, // Attempting to recall from an empty list. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 void StopRecording(MetricsLogBase** log); | 197 void StopRecording(MetricsLogBase** log); |
| 203 | 198 |
| 204 // Deletes pending_log_ and current_log_, and pushes their text into the | 199 // Deletes pending_log_ and current_log_, and pushes their text into the |
| 205 // appropriate unsent_log vectors. Called when Chrome shuts down. | 200 // appropriate unsent_log vectors. Called when Chrome shuts down. |
| 206 void PushPendingLogsToUnsentLists(); | 201 void PushPendingLogsToUnsentLists(); |
| 207 | 202 |
| 208 // Save the pending_log_text_ persistently in a pref for transmission when we | 203 // Save the pending_log_text_ persistently in a pref for transmission when we |
| 209 // next run. Note that IF this text is "too large," we just dicard it. | 204 // next run. Note that IF this text is "too large," we just dicard it. |
| 210 void PushPendingLogTextToUnsentOngoingLogs(); | 205 void PushPendingLogTextToUnsentOngoingLogs(); |
| 211 | 206 |
| 212 // Start timer for next log transmission. | 207 // Ensures that scheduler is running, assuming the current settings are such |
| 213 void StartLogTransmissionTimer(); | 208 // that metrics should be reported. If not, this is a no-op. |
| 209 void StartSchedulerIfNecessary(); |
| 214 | 210 |
| 215 // Internal function to collect process memory information. | 211 // Starts the process of uploading metrics data. |
| 216 void LogTransmissionTimerDone(); | 212 void StartScheduledUpload(); |
| 217 | 213 |
| 218 // Do not call OnMemoryDetailCollectionDone() or | 214 // Do not call OnMemoryDetailCollectionDone() or |
| 219 // OnHistogramSynchronizationDone() directly. | 215 // OnHistogramSynchronizationDone() directly; use |
| 220 // Use StartLogTransmissionTimer() to schedule a call. | 216 // StartSchedulerIfNecessary() to schedule a call. |
| 221 void OnMemoryDetailCollectionDone(); | 217 void OnMemoryDetailCollectionDone(); |
| 222 void OnHistogramSynchronizationDone(); | 218 void OnHistogramSynchronizationDone(); |
| 223 | 219 |
| 224 // Takes whatever log should be uploaded next (according to the state_) | 220 // Takes whatever log should be uploaded next (according to the state_) |
| 225 // and makes it the pending log. If pending_log_ is not NULL, | 221 // and makes it the pending log. If pending_log_ is not NULL, |
| 226 // MakePendingLog does nothing and returns. | 222 // MakePendingLog does nothing and returns. |
| 227 void MakePendingLog(); | 223 void MakePendingLog(); |
| 228 | 224 |
| 229 // Determines from state_ and permissions set out by the server whether the | |
| 230 // pending_log_ should be sent or discarded. | |
| 231 bool ServerPermitsTransmission() const; | |
| 232 | |
| 233 // Check to see if there are any unsent logs from previous sessions. | 225 // Check to see if there are any unsent logs from previous sessions. |
| 234 bool unsent_logs() const { | 226 bool unsent_logs() const { |
| 235 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty(); | 227 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty(); |
| 236 } | 228 } |
| 237 // Record stats, client ID, Session ID, etc. in a special "first" log. | 229 // Record stats, client ID, Session ID, etc. in a special "first" log. |
| 238 void PrepareInitialLog(); | 230 void PrepareInitialLog(); |
| 239 // Pull copies of unsent logs from prefs into instance variables. | 231 // Pull copies of unsent logs from prefs into instance variables. |
| 240 void RecallUnsentLogs(); | 232 void RecallUnsentLogs(); |
| 241 // Decode and verify written pref log data. | 233 // Decode and verify written pref log data. |
| 242 static MetricsService::LogRecallStatus RecallUnsentLogsHelper( | 234 static MetricsService::LogRecallStatus RecallUnsentLogsHelper( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 257 | 249 |
| 258 // Implementation of URLFetcher::Delegate. Called after transmission | 250 // Implementation of URLFetcher::Delegate. Called after transmission |
| 259 // completes (either successfully or with failure). | 251 // completes (either successfully or with failure). |
| 260 virtual void OnURLFetchComplete(const URLFetcher* source, | 252 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 261 const GURL& url, | 253 const GURL& url, |
| 262 const net::URLRequestStatus& status, | 254 const net::URLRequestStatus& status, |
| 263 int response_code, | 255 int response_code, |
| 264 const ResponseCookies& cookies, | 256 const ResponseCookies& cookies, |
| 265 const std::string& data); | 257 const std::string& data); |
| 266 | 258 |
| 267 // Called by OnURLFetchComplete to handle the case when the server returned | 259 // Logs debugging details, for the case where the server returns a response |
| 268 // a response code not equal to 200. | 260 // code other than 200. |
| 269 void HandleBadResponseCode(); | 261 void LogBadResponseCode(); |
| 270 | 262 |
| 271 // Records a window-related notification. | 263 // Records a window-related notification. |
| 272 void LogWindowChange(NotificationType type, | 264 void LogWindowChange(NotificationType type, |
| 273 const NotificationSource& source, | 265 const NotificationSource& source, |
| 274 const NotificationDetails& details); | 266 const NotificationDetails& details); |
| 275 | 267 |
| 276 // Reads, increments and then sets the specified integer preference. | 268 // Reads, increments and then sets the specified integer preference. |
| 277 void IncrementPrefValue(const char* path); | 269 void IncrementPrefValue(const char* path); |
| 278 | 270 |
| 279 // Reads, increments and then sets the specified long preference that is | 271 // Reads, increments and then sets the specified long preference that is |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 void RecordBooleanPrefValue(const char* path, bool value); | 330 void RecordBooleanPrefValue(const char* path, bool value); |
| 339 | 331 |
| 340 NotificationRegistrar registrar_; | 332 NotificationRegistrar registrar_; |
| 341 | 333 |
| 342 // Indicate whether recording and reporting are currently happening. | 334 // Indicate whether recording and reporting are currently happening. |
| 343 // These should not be set directly, but by calling SetRecording and | 335 // These should not be set directly, but by calling SetRecording and |
| 344 // SetReporting. | 336 // SetReporting. |
| 345 bool recording_active_; | 337 bool recording_active_; |
| 346 bool reporting_active_; | 338 bool reporting_active_; |
| 347 | 339 |
| 348 // The variable server_permits_upload_ is set true when the response | |
| 349 // data forbids uploading. This should coinside with the "die roll" | |
| 350 // with probability in the upload tag of the response data came out | |
| 351 // affirmative. | |
| 352 bool server_permits_upload_; | |
| 353 | |
| 354 // The progession of states made by the browser are recorded in the following | 340 // The progession of states made by the browser are recorded in the following |
| 355 // state. | 341 // state. |
| 356 State state_; | 342 State state_; |
| 357 | 343 |
| 358 // Chrome OS hardware class (e.g., hardware qualification ID). This | 344 // Chrome OS hardware class (e.g., hardware qualification ID). This |
| 359 // class identifies the configured system components such as CPU, | 345 // class identifies the configured system components such as CPU, |
| 360 // WiFi adapter, etc. For non Chrome OS hosts, this will be an | 346 // WiFi adapter, etc. For non Chrome OS hosts, this will be an |
| 361 // empty string. | 347 // empty string. |
| 362 std::string hardware_class_; | 348 std::string hardware_class_; |
| 363 | 349 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 struct ChildProcessStats; | 388 struct ChildProcessStats; |
| 403 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_; | 389 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_; |
| 404 | 390 |
| 405 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_; | 391 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_; |
| 406 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_; | 392 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_; |
| 407 | 393 |
| 408 // Dictionary containing all the profile specific metrics. This is set | 394 // Dictionary containing all the profile specific metrics. This is set |
| 409 // at creation time from the prefs. | 395 // at creation time from the prefs. |
| 410 scoped_ptr<DictionaryValue> profile_dictionary_; | 396 scoped_ptr<DictionaryValue> profile_dictionary_; |
| 411 | 397 |
| 412 // The interval between consecutive log transmissions (to avoid hogging the | 398 // The scheduler for determining when uploads should happen. |
| 413 // outbound network link). This is usually also the duration for which we | 399 scoped_ptr<MetricsReportingScheduler> scheduler_; |
| 414 // build up a log, but if other unsent-logs from previous sessions exist, we | |
| 415 // quickly transmit those unsent logs while we continue to build a log. | |
| 416 base::TimeDelta interlog_duration_; | |
| 417 | 400 |
| 418 // Indicate that a timer for sending the next log has already been queued. | 401 // Indicates that an asynchronous reporting step is running. |
| 419 bool timer_pending_; | 402 // This is used only for debugging. |
| 403 bool waiting_for_asynchronus_reporting_step_; |
| 420 | 404 |
| 421 #if defined(OS_CHROMEOS) | 405 #if defined(OS_CHROMEOS) |
| 422 // The external metric service is used to log ChromeOS UMA events. | 406 // The external metric service is used to log ChromeOS UMA events. |
| 423 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; | 407 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; |
| 424 #endif | 408 #endif |
| 425 | 409 |
| 426 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, EmptyLogList); | 410 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, EmptyLogList); |
| 427 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SingleElementLogList); | 411 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SingleElementLogList); |
| 428 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, OverLimitLogList); | 412 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, OverLimitLogList); |
| 429 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SmallRecoveredListSize); | 413 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SmallRecoveredListSize); |
| 430 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RemoveSizeFromLogList); | 414 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RemoveSizeFromLogList); |
| 431 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptSizeOfLogList); | 415 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptSizeOfLogList); |
| 432 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptChecksumOfLogList); | 416 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptChecksumOfLogList); |
| 433 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes); | 417 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes); |
| 434 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly); | 418 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly); |
| 435 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); | 419 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); |
| 436 | 420 |
| 437 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 421 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 438 }; | 422 }; |
| 439 | 423 |
| 440 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 424 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |