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

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: Comment fix 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;
jar (doing other things) 2011/04/16 02:03:13 Making classes friends of each other, outside of t
stuartmorgan 2011/04/18 17:03:00 True; do you have any pointers to how we normally
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Start timer for next log transmission.
213 void StartLogTransmissionTimer(); 212 void StartLogTransmissionTimer();
214 213
215 // Internal function to collect process memory information. 214 // Starts the process of uploading metrics data.
216 void LogTransmissionTimerDone(); 215 void StartScheduledUpload();
217 216
218 // Do not call OnHistogramSynchronizationDone() directly. 217 // Do not call OnHistogramSynchronizationDone() directly.
219 // Use StartLogTransmissionTimer() to schedule a call. 218 // Use StartLogTransmissionTimer() to schedule a call.
220 void OnHistogramSynchronizationDone(); 219 void OnHistogramSynchronizationDone();
221 220
222 // Takes whatever log should be uploaded next (according to the state_) 221 // Takes whatever log should be uploaded next (according to the state_)
223 // and makes it the pending log. If pending_log_ is not NULL, 222 // and makes it the pending log. If pending_log_ is not NULL,
224 // MakePendingLog does nothing and returns. 223 // MakePendingLog does nothing and returns.
225 void MakePendingLog(); 224 void MakePendingLog();
226 225
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. 226 // Check to see if there are any unsent logs from previous sessions.
232 bool unsent_logs() const { 227 bool unsent_logs() const {
233 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty(); 228 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty();
234 } 229 }
235 // Record stats, client ID, Session ID, etc. in a special "first" log. 230 // Record stats, client ID, Session ID, etc. in a special "first" log.
236 void PrepareInitialLog(); 231 void PrepareInitialLog();
237 // Pull copies of unsent logs from prefs into instance variables. 232 // Pull copies of unsent logs from prefs into instance variables.
238 void RecallUnsentLogs(); 233 void RecallUnsentLogs();
239 // Decode and verify written pref log data. 234 // Decode and verify written pref log data.
240 static MetricsService::LogRecallStatus RecallUnsentLogsHelper( 235 static MetricsService::LogRecallStatus RecallUnsentLogsHelper(
(...skipping 14 matching lines...) Expand all
255 250
256 // Implementation of URLFetcher::Delegate. Called after transmission 251 // Implementation of URLFetcher::Delegate. Called after transmission
257 // completes (either successfully or with failure). 252 // completes (either successfully or with failure).
258 virtual void OnURLFetchComplete(const URLFetcher* source, 253 virtual void OnURLFetchComplete(const URLFetcher* source,
259 const GURL& url, 254 const GURL& url,
260 const net::URLRequestStatus& status, 255 const net::URLRequestStatus& status,
261 int response_code, 256 int response_code,
262 const ResponseCookies& cookies, 257 const ResponseCookies& cookies,
263 const std::string& data); 258 const std::string& data);
264 259
265 // Called by OnURLFetchComplete to handle the case when the server returned 260 // Logs debugging details, for the case where the server returns a response
266 // a response code not equal to 200. 261 // code other than 200.
267 void HandleBadResponseCode(); 262 void LogBadResponseCode();
268 263
269 // Records a window-related notification. 264 // Records a window-related notification.
270 void LogWindowChange(NotificationType type, 265 void LogWindowChange(NotificationType type,
271 const NotificationSource& source, 266 const NotificationSource& source,
272 const NotificationDetails& details); 267 const NotificationDetails& details);
273 268
274 // Reads, increments and then sets the specified integer preference. 269 // Reads, increments and then sets the specified integer preference.
275 void IncrementPrefValue(const char* path); 270 void IncrementPrefValue(const char* path);
276 271
277 // Reads, increments and then sets the specified long preference that is 272 // 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); 331 void RecordBooleanPrefValue(const char* path, bool value);
337 332
338 NotificationRegistrar registrar_; 333 NotificationRegistrar registrar_;
339 334
340 // Indicate whether recording and reporting are currently happening. 335 // Indicate whether recording and reporting are currently happening.
341 // These should not be set directly, but by calling SetRecording and 336 // These should not be set directly, but by calling SetRecording and
342 // SetReporting. 337 // SetReporting.
343 bool recording_active_; 338 bool recording_active_;
344 bool reporting_active_; 339 bool reporting_active_;
345 340
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 341 // The progession of states made by the browser are recorded in the following
353 // state. 342 // state.
354 State state_; 343 State state_;
355 344
356 // Chrome OS hardware class (e.g., hardware qualification ID). This 345 // Chrome OS hardware class (e.g., hardware qualification ID). This
357 // class identifies the configured system components such as CPU, 346 // class identifies the configured system components such as CPU,
358 // WiFi adapter, etc. For non Chrome OS hosts, this will be an 347 // WiFi adapter, etc. For non Chrome OS hosts, this will be an
359 // empty string. 348 // empty string.
360 std::string hardware_class_; 349 std::string hardware_class_;
361 350
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 struct ChildProcessStats; 389 struct ChildProcessStats;
401 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_; 390 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_;
402 391
403 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_; 392 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_;
404 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_; 393 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_;
405 394
406 // Dictionary containing all the profile specific metrics. This is set 395 // Dictionary containing all the profile specific metrics. This is set
407 // at creation time from the prefs. 396 // at creation time from the prefs.
408 scoped_ptr<DictionaryValue> profile_dictionary_; 397 scoped_ptr<DictionaryValue> profile_dictionary_;
409 398
410 // The interval between consecutive log transmissions (to avoid hogging the 399 // The scheduler for determining when uploads should happen.
411 // outbound network link). This is usually also the duration for which we 400 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 401
416 // Indicate that a timer for sending the next log has already been queued. 402 // Indicates that an asynchronous reporting step is running.
jar (doing other things) 2011/04/16 02:03:13 If this is only for debugging, you should probably
stuartmorgan 2011/04/18 17:03:00 Done. (This used to be a variable that sometimes w
417 bool timer_pending_; 403 bool waiting_for_asynchronus_reporting_step_;
418 404
419 #if defined(OS_CHROMEOS) 405 #if defined(OS_CHROMEOS)
420 // The external metric service is used to log ChromeOS UMA events. 406 // The external metric service is used to log ChromeOS UMA events.
421 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; 407 scoped_refptr<chromeos::ExternalMetrics> external_metrics_;
422 #endif 408 #endif
423 409
424 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, EmptyLogList); 410 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, EmptyLogList);
425 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SingleElementLogList); 411 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SingleElementLogList);
426 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, OverLimitLogList); 412 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, OverLimitLogList);
427 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SmallRecoveredListSize); 413 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, SmallRecoveredListSize);
428 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RemoveSizeFromLogList); 414 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RemoveSizeFromLogList);
429 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptSizeOfLogList); 415 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptSizeOfLogList);
430 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptChecksumOfLogList); 416 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CorruptChecksumOfLogList);
431 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes); 417 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes);
432 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly); 418 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly);
433 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); 419 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted);
434 420
435 DISALLOW_COPY_AND_ASSIGN(MetricsService); 421 DISALLOW_COPY_AND_ASSIGN(MetricsService);
436 }; 422 };
437 423
438 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 424 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698