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

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: Created 8 years, 10 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 bool MetricsService::UploadData() { 425 bool MetricsService::UploadData() {
423 DCHECK_EQ(thread_, base::PlatformThread::CurrentId()); 426 DCHECK_EQ(thread_, base::PlatformThread::CurrentId());
424 427
425 if (!GetInstance()->TransmissionPermitted()) 428 if (!GetInstance()->TransmissionPermitted())
426 return false; 429 return false;
427 430
428 static long currently_uploading = 0; 431 static long currently_uploading = 0;
429 if (InterlockedCompareExchange(&currently_uploading, 1, 0)) { 432 if (InterlockedCompareExchange(&currently_uploading, 1, 0)) {
430 DVLOG(1) << "Contention for uploading metrics data. Backing off"; 433 DVLOG(1) << "Contention for uploading metrics data. Backing off";
431 return false; 434 return false;
432 } 435 }
433 436
434 MakePendingLog(); 437 MakePendingLog();
435 DCHECK(log_manager_.has_staged_log());
436 438
437 bool ret = true; 439 bool ret = true;
438 440
439 if (log_manager_.staged_log_text().empty()) { 441 if (log_manager_.has_staged_log()) {
440 NOTREACHED() << "Failed to compress log for transmission.";
441 ret = false;
442 } else {
443 HRESULT hr = ChromeFrameMetricsDataUploader::UploadDataHelper( 442 HRESULT hr = ChromeFrameMetricsDataUploader::UploadDataHelper(
444 log_manager_.staged_log_text()); 443 log_manager_.staged_log_text());
445 DCHECK(SUCCEEDED(hr)); 444 DCHECK(SUCCEEDED(hr));
445 log_manager_.DiscardStagedLog();
446 } else {
447 NOTREACHED() << "Failed to prepare log for transmission.";
Ilya Sherman 2012/02/29 01:25:41 nit: There was a thread recently about not printin
stuartmorgan 2012/02/29 13:26:15 Yep, should have noticed that while I was moving t
448 ret = false;
446 } 449 }
447 log_manager_.DiscardStagedLog();
448 450
449 currently_uploading = 0; 451 currently_uploading = 0;
450 return ret; 452 return ret;
451 } 453 }
452 454
453 // static 455 // static
454 std::string MetricsService::GetVersionString() { 456 std::string MetricsService::GetVersionString() {
455 chrome::VersionInfo version_info; 457 chrome::VersionInfo version_info;
456 if (version_info.is_valid()) { 458 if (version_info.is_valid()) {
457 std::string version = version_info.Version(); 459 std::string version = version_info.Version();
458 // Add the -F extensions to ensure that UMA data uploaded by ChromeFrame 460 // Add the -F extensions to ensure that UMA data uploaded by ChromeFrame
459 // lands in the ChromeFrame bucket. 461 // lands in the ChromeFrame bucket.
460 version += "-F"; 462 version += "-F";
461 if (!version_info.IsOfficialBuild()) 463 if (!version_info.IsOfficialBuild())
462 version.append("-devel"); 464 version.append("-devel");
463 return version; 465 return version;
464 } else { 466 } else {
465 NOTREACHED() << "Unable to retrieve version string."; 467 NOTREACHED() << "Unable to retrieve version string.";
466 } 468 }
467 469
468 return std::string(); 470 return std::string();
469 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698