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

Side by Side Diff: chrome_frame/metrics_service.cc

Issue 9396001: Begin to separate the MetricsService logic for creating vs uploading logs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 8 years, 9 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) 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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is created at ChromeFrame startup in 10 // A MetricsService instance is created at ChromeFrame startup in
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 359 }
360 360
361 //------------------------------------------------------------------------------ 361 //------------------------------------------------------------------------------
362 // Recording control methods 362 // Recording control methods
363 363
364 void MetricsService::StartRecording() { 364 void MetricsService::StartRecording() {
365 DCHECK_EQ(thread_, base::PlatformThread::CurrentId()); 365 DCHECK_EQ(thread_, base::PlatformThread::CurrentId());
366 if (log_manager_.current_log()) 366 if (log_manager_.current_log())
367 return; 367 return;
368 368
369 MetricsLogManager::LogType log_type = (state_ == INITIALIZED) ?
370 MetricsLogManager::INITIAL_LOG : MetricsLogManager::ONGOING_LOG;
369 log_manager_.BeginLoggingWithLog(new MetricsLogBase(client_id_, session_id_, 371 log_manager_.BeginLoggingWithLog(new MetricsLogBase(client_id_, session_id_,
370 GetVersionString())); 372 GetVersionString()),
373 log_type);
371 if (state_ == INITIALIZED) 374 if (state_ == INITIALIZED)
372 state_ = ACTIVE; 375 state_ = ACTIVE;
373 } 376 }
374 377
375 void MetricsService::StopRecording(bool save_log) { 378 void MetricsService::StopRecording(bool save_log) {
376 DCHECK_EQ(thread_, base::PlatformThread::CurrentId()); 379 DCHECK_EQ(thread_, base::PlatformThread::CurrentId());
377 if (!log_manager_.current_log()) 380 if (!log_manager_.current_log())
378 return; 381 return;
379 382
380 // Put incremental histogram deltas at the end of all log transmissions. 383 // Put incremental histogram deltas at the end of all log transmissions.
381 // Don't bother if we're going to discard current_log. 384 // Don't bother if we're going to discard current_log.
382 if (save_log) { 385 if (save_log) {
383 CrashMetricsReporter::GetInstance()->RecordCrashMetrics(); 386 CrashMetricsReporter::GetInstance()->RecordCrashMetrics();
384 RecordCurrentHistograms(); 387 RecordCurrentHistograms();
385 } 388 }
386 389
387 if (save_log) 390 if (save_log) {
388 log_manager_.StageCurrentLogForUpload(); 391 log_manager_.FinishCurrentLog();
389 else 392 log_manager_.StageNextLogForUpload();
393 } else {
390 log_manager_.DiscardCurrentLog(); 394 log_manager_.DiscardCurrentLog();
395 }
391 } 396 }
392 397
393 void MetricsService::MakePendingLog() { 398 void MetricsService::MakePendingLog() {
394 DCHECK_EQ(thread_, base::PlatformThread::CurrentId()); 399 DCHECK_EQ(thread_, base::PlatformThread::CurrentId());
395 if (log_manager_.has_staged_log()) 400 if (log_manager_.has_staged_log())
396 return; 401 return;
397 402
398 switch (state_) { 403 switch (state_) {
399 case INITIALIZED: // We should be further along by now. 404 case INITIALIZED: // We should be further along by now.
400 DCHECK(false); 405 DCHECK(false);
401 return; 406 return;
402 407
403 case ACTIVE: 408 case ACTIVE:
404 StopRecording(true); 409 StopRecording(true);
405 StartRecording(); 410 StartRecording();
406 break; 411 break;
407 412
408 default: 413 default:
409 DCHECK(false); 414 DCHECK(false);
410 return; 415 return;
411 } 416 }
412
413 DCHECK(log_manager_.has_staged_log());
414 } 417 }
415 418
416 bool MetricsService::TransmissionPermitted() const { 419 bool MetricsService::TransmissionPermitted() const {
417 // If the user forbids uploading that's their business, and we don't upload 420 // If the user forbids uploading that's their business, and we don't upload
418 // anything. 421 // anything.
419 return user_permits_upload_; 422 return user_permits_upload_;
420 } 423 }
421 424
422 // TODO(isherman): Update this to log to the protobuf server as well... 425 // TODO(isherman): Update this to log to the protobuf server as well...
423 // http://crbug.com/109817 426 // http://crbug.com/109817
424 bool MetricsService::UploadData() { 427 bool MetricsService::UploadData() {
425 DCHECK_EQ(thread_, base::PlatformThread::CurrentId()); 428 DCHECK_EQ(thread_, base::PlatformThread::CurrentId());
426 429
427 if (!GetInstance()->TransmissionPermitted()) 430 if (!GetInstance()->TransmissionPermitted())
428 return false; 431 return false;
429 432
430 static long currently_uploading = 0; 433 static long currently_uploading = 0;
431 if (InterlockedCompareExchange(&currently_uploading, 1, 0)) { 434 if (InterlockedCompareExchange(&currently_uploading, 1, 0)) {
432 DVLOG(1) << "Contention for uploading metrics data. Backing off"; 435 DVLOG(1) << "Contention for uploading metrics data. Backing off";
433 return false; 436 return false;
434 } 437 }
435 438
436 MakePendingLog(); 439 MakePendingLog();
437 DCHECK(log_manager_.has_staged_log());
438 440
439 bool ret = true; 441 bool ret = true;
440 442
441 if (log_manager_.staged_log_text().empty()) { 443 if (log_manager_.has_staged_log()) {
442 NOTREACHED() << "Failed to compress log for transmission.";
443 ret = false;
444 } else {
445 HRESULT hr = ChromeFrameMetricsDataUploader::UploadDataHelper( 444 HRESULT hr = ChromeFrameMetricsDataUploader::UploadDataHelper(
446 log_manager_.staged_log_text().xml); 445 log_manager_.staged_log_text().xml);
447 DCHECK(SUCCEEDED(hr)); 446 DCHECK(SUCCEEDED(hr));
447 log_manager_.DiscardStagedLog();
448 } else {
449 NOTREACHED();
450 ret = false;
448 } 451 }
449 log_manager_.DiscardStagedLog();
450 452
451 currently_uploading = 0; 453 currently_uploading = 0;
452 return ret; 454 return ret;
453 } 455 }
454 456
455 // static 457 // static
456 std::string MetricsService::GetVersionString() { 458 std::string MetricsService::GetVersionString() {
457 chrome::VersionInfo version_info; 459 chrome::VersionInfo version_info;
458 if (version_info.is_valid()) { 460 if (version_info.is_valid()) {
459 std::string version = version_info.Version(); 461 std::string version = version_info.Version();
460 // Add the -F extensions to ensure that UMA data uploaded by ChromeFrame 462 // Add the -F extensions to ensure that UMA data uploaded by ChromeFrame
461 // lands in the ChromeFrame bucket. 463 // lands in the ChromeFrame bucket.
462 version += "-F"; 464 version += "-F";
463 if (!version_info.IsOfficialBuild()) 465 if (!version_info.IsOfficialBuild())
464 version.append("-devel"); 466 version.append("-devel");
465 return version; 467 return version;
466 } else { 468 } else {
467 NOTREACHED() << "Unable to retrieve version string."; 469 NOTREACHED() << "Unable to retrieve version string.";
468 } 470 }
469 471
470 return std::string(); 472 return std::string();
471 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698