Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/metrics/metrics_service.h

Issue 6869034: Factor a scheduler object out of MetricsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most review comments Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void StartExternalMetrics(); 123 void StartExternalMetrics();
129 124
130 // Records a Chrome OS crash. 125 // Records a Chrome OS crash.
131 void LogChromeOSCrash(const std::string &crash_type); 126 void LogChromeOSCrash(const std::string &crash_type);
132 #endif 127 #endif
133 128
134 bool recording_active() const; 129 bool recording_active() const;
135 bool reporting_active() const; 130 bool reporting_active() const;
136 131
137 private: 132 private:
133 // The scheduler needs to be able to trigger an upload, but that shouldn't
134 // be part of the API.
135 friend class MetricsReportingScheduler;
136
138 // The MetricsService has a lifecycle that is stored as a state. 137 // The MetricsService has a lifecycle that is stored as a state.
139 // See metrics_service.cc for description of this lifecycle. 138 // See metrics_service.cc for description of this lifecycle.
140 enum State { 139 enum State {
141 INITIALIZED, // Constructor was called. 140 INITIALIZED, // Constructor was called.
142 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. 141 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete.
143 INIT_TASK_DONE, // Waiting for timer to send initial log. 142 INIT_TASK_DONE, // Waiting for timer to send initial log.
144 INITIAL_LOG_READY, // Initial log generated, and waiting for reply. 143 INITIAL_LOG_READY, // Initial log generated, and waiting for reply.
145 SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session. 144 SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session.
146 SENDING_OLD_LOGS, // Sending unsent logs from previous session. 145 SENDING_OLD_LOGS, // Sending unsent logs from previous session.
147 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue. 146 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 void StopRecording(MetricsLogBase** log); 201 void StopRecording(MetricsLogBase** log);
203 202
204 // Deletes pending_log_ and current_log_, and pushes their text into the 203 // Deletes pending_log_ and current_log_, and pushes their text into the
205 // appropriate unsent_log vectors. Called when Chrome shuts down. 204 // appropriate unsent_log vectors. Called when Chrome shuts down.
206 void PushPendingLogsToUnsentLists(); 205 void PushPendingLogsToUnsentLists();
207 206
208 // Save the pending_log_text_ persistently in a pref for transmission when we 207 // 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. 208 // next run. Note that IF this text is "too large," we just dicard it.
210 void PushPendingLogTextToUnsentOngoingLogs(); 209 void PushPendingLogTextToUnsentOngoingLogs();
211 210
212 // Start timer for next log transmission. 211 // Ensures that scheduler is running, assuming the current settings are such
213 void StartLogTransmissionTimer(); 212 // that metrics should be reported. If not, this is a no-op.
213 void StartSchedulerIfNecessary();
214 214
215 // Internal function to collect process memory information. 215 // Starts the process of uploading metrics data.
216 void LogTransmissionTimerDone(); 216 void StartScheduledUpload();
217 217
218 // Do not call OnHistogramSynchronizationDone() directly. 218 // Creates log data to upload, and starts the process of uploading it.
219 // Use StartLogTransmissionTimer() to schedule a call. 219 // Do not call OnHistogramSynchronizationDone() directly; use
220 // StartSchedulerIfNecessary() to schedule a call.
220 void OnHistogramSynchronizationDone(); 221 void OnHistogramSynchronizationDone();
221 222
222 // Takes whatever log should be uploaded next (according to the state_) 223 // Takes whatever log should be uploaded next (according to the state_)
223 // and makes it the pending log. If pending_log_ is not NULL, 224 // and makes it the pending log. If pending_log_ is not NULL,
224 // MakePendingLog does nothing and returns. 225 // MakePendingLog does nothing and returns.
225 void MakePendingLog(); 226 void MakePendingLog();
226 227
227 // Determines from state_ and permissions set out by the server whether the
228 // pending_log_ should be sent or discarded.
229 bool ServerPermitsTransmission() const;
230
231 // Check to see if there are any unsent logs from previous sessions. 228 // Check to see if there are any unsent logs from previous sessions.
232 bool unsent_logs() const { 229 bool unsent_logs() const {
233 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty(); 230 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty();
234 } 231 }
235 // Record stats, client ID, Session ID, etc. in a special "first" log. 232 // Record stats, client ID, Session ID, etc. in a special "first" log.
236 void PrepareInitialLog(); 233 void PrepareInitialLog();
237 // Pull copies of unsent logs from prefs into instance variables. 234 // Pull copies of unsent logs from prefs into instance variables.
238 void RecallUnsentLogs(); 235 void RecallUnsentLogs();
239 // Decode and verify written pref log data. 236 // Decode and verify written pref log data.
240 static MetricsService::LogRecallStatus RecallUnsentLogsHelper( 237 static MetricsService::LogRecallStatus RecallUnsentLogsHelper(
(...skipping 14 matching lines...) Expand all
255 252
256 // Implementation of URLFetcher::Delegate. Called after transmission 253 // Implementation of URLFetcher::Delegate. Called after transmission
257 // completes (either successfully or with failure). 254 // completes (either successfully or with failure).
258 virtual void OnURLFetchComplete(const URLFetcher* source, 255 virtual void OnURLFetchComplete(const URLFetcher* source,
259 const GURL& url, 256 const GURL& url,
260 const net::URLRequestStatus& status, 257 const net::URLRequestStatus& status,
261 int response_code, 258 int response_code,
262 const ResponseCookies& cookies, 259 const ResponseCookies& cookies,
263 const std::string& data); 260 const std::string& data);
264 261
265 // Called by OnURLFetchComplete to handle the case when the server returned 262 // Logs debugging details, for the case where the server returns a response
266 // a response code not equal to 200. 263 // code other than 200.
267 void HandleBadResponseCode(); 264 void LogBadResponseCode();
268 265
269 // Records a window-related notification. 266 // Records a window-related notification.
270 void LogWindowChange(NotificationType type, 267 void LogWindowChange(NotificationType type,
271 const NotificationSource& source, 268 const NotificationSource& source,
272 const NotificationDetails& details); 269 const NotificationDetails& details);
273 270
274 // Reads, increments and then sets the specified integer preference. 271 // Reads, increments and then sets the specified integer preference.
275 void IncrementPrefValue(const char* path); 272 void IncrementPrefValue(const char* path);
276 273
277 // Reads, increments and then sets the specified long preference that is 274 // Reads, increments and then sets the specified long preference that is
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 void RecordBooleanPrefValue(const char* path, bool value); 333 void RecordBooleanPrefValue(const char* path, bool value);
337 334
338 NotificationRegistrar registrar_; 335 NotificationRegistrar registrar_;
339 336
340 // Indicate whether recording and reporting are currently happening. 337 // Indicate whether recording and reporting are currently happening.
341 // These should not be set directly, but by calling SetRecording and 338 // These should not be set directly, but by calling SetRecording and
342 // SetReporting. 339 // SetReporting.
343 bool recording_active_; 340 bool recording_active_;
344 bool reporting_active_; 341 bool reporting_active_;
345 342
346 // The variable server_permits_upload_ is set true when the response
347 // data forbids uploading. This should coinside with the "die roll"
348 // with probability in the upload tag of the response data came out
349 // affirmative.
350 bool server_permits_upload_;
351
352 // The progession of states made by the browser are recorded in the following 343 // The progession of states made by the browser are recorded in the following
353 // state. 344 // state.
354 State state_; 345 State state_;
355 346
356 // Chrome OS hardware class (e.g., hardware qualification ID). This 347 // Chrome OS hardware class (e.g., hardware qualification ID). This
357 // class identifies the configured system components such as CPU, 348 // class identifies the configured system components such as CPU,
358 // WiFi adapter, etc. For non Chrome OS hosts, this will be an 349 // WiFi adapter, etc. For non Chrome OS hosts, this will be an
359 // empty string. 350 // empty string.
360 std::string hardware_class_; 351 std::string hardware_class_;
361 352
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 struct ChildProcessStats; 391 struct ChildProcessStats;
401 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_; 392 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_;
402 393
403 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_; 394 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_;
404 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_; 395 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_;
405 396
406 // Dictionary containing all the profile specific metrics. This is set 397 // Dictionary containing all the profile specific metrics. This is set
407 // at creation time from the prefs. 398 // at creation time from the prefs.
408 scoped_ptr<DictionaryValue> profile_dictionary_; 399 scoped_ptr<DictionaryValue> profile_dictionary_;
409 400
410 // The interval between consecutive log transmissions (to avoid hogging the 401 // The scheduler for determining when uploads should happen.
411 // outbound network link). This is usually also the duration for which we 402 scoped_ptr<MetricsReportingScheduler> scheduler_;
412 // build up a log, but if other unsent-logs from previous sessions exist, we
413 // quickly transmit those unsent logs while we continue to build a log.
414 base::TimeDelta interlog_duration_;
415 403
416 // Indicate that a timer for sending the next log has already been queued. 404 // Indicates that an asynchronous reporting step is running.
417 bool timer_pending_; 405 // This is used only for debugging.
406 bool waiting_for_asynchronus_reporting_step_;
418 407
419 #if defined(OS_CHROMEOS) 408 #if defined(OS_CHROMEOS)
420 // The external metric service is used to log ChromeOS UMA events. 409 // The external metric service is used to log ChromeOS UMA events.
421 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; 410 scoped_refptr<chromeos::ExternalMetrics> external_metrics_;
422 #endif 411 #endif
423 412
424 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, EmptyLogList); 413 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, EmptyLogList);
425 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SingleElementLogList); 414 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SingleElementLogList);
426 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, OverLimitLogList); 415 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, OverLimitLogList);
427 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SmallRecoveredListSize); 416 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SmallRecoveredListSize);
428 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RemoveSizeFromLogList); 417 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RemoveSizeFromLogList);
429 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptSizeOfLogList); 418 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptSizeOfLogList);
430 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptChecksumOfLogList); 419 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptChecksumOfLogList);
431 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes); 420 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes);
432 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly); 421 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly);
433 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); 422 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted);
434 423
435 DISALLOW_COPY_AND_ASSIGN(MetricsService); 424 DISALLOW_COPY_AND_ASSIGN(MetricsService);
436 }; 425 };
437 426
438 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 427 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698