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

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

Issue 2744003: Preparation CL for adding crash metrics UMA counters to ChromeFrame. Basicall... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <list> 11 #include <list>
12 #include <map> 12 #include <map>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/gtest_prod_util.h" 18 #include "base/gtest_prod_util.h"
19 #include "base/histogram.h" 19 #include "base/histogram.h"
20 #include "base/scoped_ptr.h" 20 #include "base/scoped_ptr.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/metrics/metrics_log.h" 22 #include "chrome/browser/metrics/metrics_log.h"
23 #include "chrome/common/child_process_info.h" 23 #include "chrome/common/child_process_info.h"
24 #include "chrome/common/metrics_helpers.h"
24 #include "chrome/common/net/url_fetcher.h" 25 #include "chrome/common/net/url_fetcher.h"
25 #include "chrome/common/notification_registrar.h" 26 #include "chrome/common/notification_registrar.h"
26 #include "webkit/glue/plugins/webplugininfo.h" 27 #include "webkit/glue/plugins/webplugininfo.h"
27 28
28 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
29 #include "chrome/browser/chromeos/external_metrics.h" 30 #include "chrome/browser/chromeos/external_metrics.h"
30 #endif 31 #endif
31 32
32 class BookmarkModel; 33 class BookmarkModel;
33 class BookmarkNode; 34 class BookmarkNode;
(...skipping 29 matching lines...) Expand all
63 64
64 // The number of instances of this child process that have been created. 65 // The number of instances of this child process that have been created.
65 // An instance is a DOM object rendered by this child process during a page 66 // An instance is a DOM object rendered by this child process during a page
66 // load. 67 // load.
67 int instances; 68 int instances;
68 69
69 ChildProcessInfo::ProcessType process_type; 70 ChildProcessInfo::ProcessType process_type;
70 }; 71 };
71 72
72 class MetricsService : public NotificationObserver, 73 class MetricsService : public NotificationObserver,
73 public URLFetcher::Delegate { 74 public URLFetcher::Delegate,
75 public MetricsServiceBase {
74 public: 76 public:
75 MetricsService(); 77 MetricsService();
76 virtual ~MetricsService(); 78 virtual ~MetricsService();
77 79
78 // Sets whether the user permits uploading. The argument of this function 80 // Sets whether the user permits uploading. The argument of this function
79 // should match the checkbox in Options. 81 // should match the checkbox in Options.
80 void SetUserPermitsUpload(bool enabled); 82 void SetUserPermitsUpload(bool enabled);
81 83
82 // Start/stop the metrics recording and uploading machine. These should be 84 // Start/stop the metrics recording and uploading machine. These should be
83 // used on startup and when the user clicks the checkbox in the prefs. 85 // used on startup and when the user clicks the checkbox in the prefs.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 enum State { 145 enum State {
144 INITIALIZED, // Constructor was called. 146 INITIALIZED, // Constructor was called.
145 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. 147 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete.
146 INIT_TASK_DONE, // Waiting for timer to send initial log. 148 INIT_TASK_DONE, // Waiting for timer to send initial log.
147 INITIAL_LOG_READY, // Initial log generated, and waiting for reply. 149 INITIAL_LOG_READY, // Initial log generated, and waiting for reply.
148 SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session. 150 SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session.
149 SENDING_OLD_LOGS, // Sending unsent logs from previous session. 151 SENDING_OLD_LOGS, // Sending unsent logs from previous session.
150 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue. 152 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue.
151 }; 153 };
152 154
153 // Maintain a map of histogram names to the sample stats we've sent.
154 typedef std::map<std::string, Histogram::SampleSet> LoggedSampleMap;
155
156 class InitTask; 155 class InitTask;
157 class InitTaskComplete; 156 class InitTaskComplete;
158 157
159 // Callback to let us know that the init task is done. 158 // Callback to let us know that the init task is done.
160 void OnInitTaskComplete( 159 void OnInitTaskComplete(
161 const std::string& hardware_class, 160 const std::string& hardware_class,
162 const std::vector<WebPluginInfo>& plugins); 161 const std::vector<WebPluginInfo>& plugins);
163 162
164 // When we start a new version of Chromium (different from our last run), we 163 // When we start a new version of Chromium (different from our last run), we
165 // need to discard the old crash stats so that we don't attribute crashes etc. 164 // need to discard the old crash stats so that we don't attribute crashes etc.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // make a change, call ScheduleNextStateSave() instead. 210 // make a change, call ScheduleNextStateSave() instead.
212 void SaveLocalState(); 211 void SaveLocalState();
213 212
214 // Called to start recording user experience metrics. 213 // Called to start recording user experience metrics.
215 // Constructs a new, empty current_log_. 214 // Constructs a new, empty current_log_.
216 void StartRecording(); 215 void StartRecording();
217 216
218 // Called to stop recording user experience metrics. The caller takes 217 // Called to stop recording user experience metrics. The caller takes
219 // ownership of the resulting MetricsLog object via the log parameter, 218 // ownership of the resulting MetricsLog object via the log parameter,
220 // or passes in NULL to indicate that the log should simply be deleted. 219 // or passes in NULL to indicate that the log should simply be deleted.
221 void StopRecording(MetricsLog** log); 220 void StopRecording(MetricsLogBase** log);
222 221
223 // Deletes pending_log_ and current_log_, and pushes their text into the 222 // Deletes pending_log_ and current_log_, and pushes their text into the
224 // appropriate unsent_log vectors. Called when Chrome shuts down. 223 // appropriate unsent_log vectors. Called when Chrome shuts down.
225 void PushPendingLogsToUnsentLists(); 224 void PushPendingLogsToUnsentLists();
226 225
227 // Save the pending_log_text_ persistently in a pref for transmission when we 226 // Save the pending_log_text_ persistently in a pref for transmission when we
228 // next run. Note that IF this text is "too large," we just dicard it. 227 // next run. Note that IF this text is "too large," we just dicard it.
229 void PushPendingLogTextToUnsentOngoingLogs(); 228 void PushPendingLogTextToUnsentOngoingLogs();
230 229
231 // Start timer for next log transmission. 230 // Start timer for next log transmission.
(...skipping 11 matching lines...) Expand all
243 // Takes whatever log should be uploaded next (according to the state_) 242 // Takes whatever log should be uploaded next (according to the state_)
244 // and makes it the pending log. If pending_log_ is not NULL, 243 // and makes it the pending log. If pending_log_ is not NULL,
245 // MakePendingLog does nothing and returns. 244 // MakePendingLog does nothing and returns.
246 void MakePendingLog(); 245 void MakePendingLog();
247 246
248 // Determines from state_ and permissions set out by the server and by 247 // Determines from state_ and permissions set out by the server and by
249 // the user whether the pending_log_ should be sent or discarded. Called by 248 // the user whether the pending_log_ should be sent or discarded. Called by
250 // TryToStartTransmission. 249 // TryToStartTransmission.
251 bool TransmissionPermitted() const; 250 bool TransmissionPermitted() const;
252 251
253 // Check to see if there is a log that needs to be, or is being, transmitted.
254 bool pending_log() const {
255 return pending_log_ || !pending_log_text_.empty();
256 }
257 // Check to see if there are any unsent logs from previous sessions. 252 // Check to see if there are any unsent logs from previous sessions.
258 bool unsent_logs() const { 253 bool unsent_logs() const {
259 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty(); 254 return !unsent_initial_logs_.empty() || !unsent_ongoing_logs_.empty();
260 } 255 }
261 // Record stats, client ID, Session ID, etc. in a special "first" log. 256 // Record stats, client ID, Session ID, etc. in a special "first" log.
262 void PrepareInitialLog(); 257 void PrepareInitialLog();
263 // Pull copies of unsent logs from prefs into instance variables. 258 // Pull copies of unsent logs from prefs into instance variables.
264 void RecallUnsentLogs(); 259 void RecallUnsentLogs();
265 // Convert pending_log_ to XML in pending_log_text_ for transmission. 260 // Convert pending_log_ to XML in pending_log_text_ for transmission.
266 void PreparePendingLogText(); 261 void PreparePendingLogText();
267 262
268 // Convert pending_log_ to XML, compress it, and prepare to pass to server. 263 // Convert pending_log_ to XML, compress it, and prepare to pass to server.
269 // Upon return, current_fetch_ should be reset with its upload data set to 264 // Upon return, current_fetch_ should be reset with its upload data set to
270 // a compressed copy of the pending log. 265 // a compressed copy of the pending log.
271 void PrepareFetchWithPendingLog(); 266 void PrepareFetchWithPendingLog();
272 267
273 // Discard pending_log_, and clear pending_log_text_. Called after processing
274 // of this log is complete.
275 void DiscardPendingLog();
276 // Compress the report log in input using bzip2, store the result in output.
277 bool Bzip2Compress(const std::string& input, std::string* output);
278 // Implementation of URLFetcher::Delegate. Called after transmission 268 // Implementation of URLFetcher::Delegate. Called after transmission
279 // completes (either successfully or with failure). 269 // completes (either successfully or with failure).
280 virtual void OnURLFetchComplete(const URLFetcher* source, 270 virtual void OnURLFetchComplete(const URLFetcher* source,
281 const GURL& url, 271 const GURL& url,
282 const URLRequestStatus& status, 272 const URLRequestStatus& status,
283 int response_code, 273 int response_code,
284 const ResponseCookies& cookies, 274 const ResponseCookies& cookies,
285 const std::string& data); 275 const std::string& data);
286 276
287 // Called by OnURLFetchComplete to handle the case when the server returned 277 // Called by OnURLFetchComplete to handle the case when the server returned
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 void RecordPluginChanges(PrefService* pref); 370 void RecordPluginChanges(PrefService* pref);
381 371
382 // Records state that should be periodically saved, like uptime and 372 // Records state that should be periodically saved, like uptime and
383 // buffered plugin stability statistics. 373 // buffered plugin stability statistics.
384 void RecordCurrentState(PrefService* pref); 374 void RecordCurrentState(PrefService* pref);
385 375
386 // Requests all renderers to send their histograms back for 376 // Requests all renderers to send their histograms back for
387 // collecting stats from renderers. 377 // collecting stats from renderers.
388 void CollectRendererHistograms(); 378 void CollectRendererHistograms();
389 379
390 // Record complete list of histograms into the current log.
391 // Called when we close a log.
392 void RecordCurrentHistograms();
393
394 // Record a specific histogram .
395 void RecordHistogram(const Histogram& histogram);
396
397 // Logs the initiation of a page load 380 // Logs the initiation of a page load
398 void LogLoadStarted(); 381 void LogLoadStarted();
399 382
400 // Records a page load notification. 383 // Records a page load notification.
401 void LogLoadComplete(NotificationType type, 384 void LogLoadComplete(NotificationType type,
402 const NotificationSource& source, 385 const NotificationSource& source,
403 const NotificationDetails& details); 386 const NotificationDetails& details);
404 387
405 // Checks whether a notification can be logged. 388 // Checks whether a notification can be logged.
406 bool CanLogNotification(NotificationType type, 389 bool CanLogNotification(NotificationType type,
(...skipping 27 matching lines...) Expand all
434 417
435 // Chrome OS hardware class (e.g., hardware qualification ID). This 418 // Chrome OS hardware class (e.g., hardware qualification ID). This
436 // class identifies the configured system components such as CPU, 419 // class identifies the configured system components such as CPU,
437 // WiFi adapter, etc. For non Chrome OS hosts, this will be an 420 // WiFi adapter, etc. For non Chrome OS hosts, this will be an
438 // empty string. 421 // empty string.
439 std::string hardware_class_; 422 std::string hardware_class_;
440 423
441 // The list of plugins which was retrieved on the file thread. 424 // The list of plugins which was retrieved on the file thread.
442 std::vector<WebPluginInfo> plugins_; 425 std::vector<WebPluginInfo> plugins_;
443 426
444 // A log that we are currently transmiting, or about to try to transmit.
445 MetricsLog* pending_log_;
446
447 // An alternate form of pending_log_. We persistently save this text version
448 // into prefs if we can't transmit it. As a result, sometimes all we have is
449 // the text version (recalled from a previous session).
450 std::string pending_log_text_;
451
452 // The outstanding transmission appears as a URL Fetch operation. 427 // The outstanding transmission appears as a URL Fetch operation.
453 scoped_ptr<URLFetcher> current_fetch_; 428 scoped_ptr<URLFetcher> current_fetch_;
454 429
455 // The log that we are still appending to.
456 MetricsLog* current_log_;
457
458 // The URL for the metrics server. 430 // The URL for the metrics server.
459 std::wstring server_url_; 431 std::wstring server_url_;
460 432
461 // The identifier that's sent to the server with the log reports. 433 // The identifier that's sent to the server with the log reports.
462 std::string client_id_; 434 std::string client_id_;
463 435
464 // Whether the MetricsService object has received any notifications since 436 // Whether the MetricsService object has received any notifications since
465 // the last time a transmission was sent. 437 // the last time a transmission was sent.
466 bool idle_since_last_transmission_; 438 bool idle_since_last_transmission_;
467 439
(...skipping 21 matching lines...) Expand all
489 // ChildProcessStats documentation above for more details. 461 // ChildProcessStats documentation above for more details.
490 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_; 462 std::map<std::wstring, ChildProcessStats> child_process_stats_buffer_;
491 463
492 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_; 464 ScopedRunnableMethodFactory<MetricsService> log_sender_factory_;
493 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_; 465 ScopedRunnableMethodFactory<MetricsService> state_saver_factory_;
494 466
495 // Dictionary containing all the profile specific metrics. This is set 467 // Dictionary containing all the profile specific metrics. This is set
496 // at creation time from the prefs. 468 // at creation time from the prefs.
497 scoped_ptr<DictionaryValue> profile_dictionary_; 469 scoped_ptr<DictionaryValue> profile_dictionary_;
498 470
499 // For histograms, record what we've already logged (as a sample for each
500 // histogram) so that we can send only the delta with the next log.
501 MetricsService::LoggedSampleMap logged_samples_;
502
503 // The interval between consecutive log transmissions (to avoid hogging the 471 // The interval between consecutive log transmissions (to avoid hogging the
504 // outbound network link). This is usually also the duration for which we 472 // outbound network link). This is usually also the duration for which we
505 // build up a log, but if other unsent-logs from previous sessions exist, we 473 // build up a log, but if other unsent-logs from previous sessions exist, we
506 // quickly transmit those unsent logs while we continue to build a log. 474 // quickly transmit those unsent logs while we continue to build a log.
507 base::TimeDelta interlog_duration_; 475 base::TimeDelta interlog_duration_;
508 476
509 // The maximum number of events which get transmitted in a log. This defaults 477 // The maximum number of events which get transmitted in a log. This defaults
510 // to a constant and otherwise is provided by the UMA server in the server 478 // to a constant and otherwise is provided by the UMA server in the server
511 // response data. 479 // response data.
512 int log_event_limit_; 480 int log_event_limit_;
(...skipping 14 matching lines...) Expand all
527 #endif 495 #endif
528 496
529 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes); 497 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesAllZeroes);
530 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly); 498 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdGeneratesCorrectly);
531 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); 499 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted);
532 500
533 DISALLOW_COPY_AND_ASSIGN(MetricsService); 501 DISALLOW_COPY_AND_ASSIGN(MetricsService);
534 }; 502 };
535 503
536 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 504 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698