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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 636363004: Make remaining parts of components/metrics use metrics namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 256
257 bool NewInitialMetricsTimingEnabled() { 257 bool NewInitialMetricsTimingEnabled() {
258 return base::FieldTrialList::FindFullName("UMAInitialMetricsTiming") == 258 return base::FieldTrialList::FindFullName("UMAInitialMetricsTiming") ==
259 "Enabled"; 259 "Enabled";
260 } 260 }
261 261
262 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, 262 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon,
263 PrefService* local_state) { 263 PrefService* local_state) {
264 clean_exit_beacon->WriteBeaconValue(true); 264 clean_exit_beacon->WriteBeaconValue(true);
265 local_state->SetInteger(metrics::prefs::kStabilityExecutionPhase, 265 local_state->SetInteger(prefs::kStabilityExecutionPhase,
266 MetricsService::SHUTDOWN_COMPLETE); 266 MetricsService::SHUTDOWN_COMPLETE);
267 // Start writing right away (write happens on a different thread). 267 // Start writing right away (write happens on a different thread).
268 local_state->CommitPendingWrite(); 268 local_state->CommitPendingWrite();
269 } 269 }
270 270
271 } // namespace 271 } // namespace
272 272
273 273
274 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { 274 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) {
275 id.name = trial; 275 id.name = trial;
276 id.group = group; 276 id.group = group;
277 } 277 }
278 278
279 SyntheticTrialGroup::~SyntheticTrialGroup() { 279 SyntheticTrialGroup::~SyntheticTrialGroup() {
280 } 280 }
281 281
282 // static 282 // static
283 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = 283 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
284 MetricsService::CLEANLY_SHUTDOWN; 284 MetricsService::CLEANLY_SHUTDOWN;
285 285
286 MetricsService::ExecutionPhase MetricsService::execution_phase_ = 286 MetricsService::ExecutionPhase MetricsService::execution_phase_ =
287 MetricsService::UNINITIALIZED_PHASE; 287 MetricsService::UNINITIALIZED_PHASE;
288 288
289 // static 289 // static
290 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { 290 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
291 DCHECK(IsSingleThreaded()); 291 DCHECK(IsSingleThreaded());
292 metrics::MetricsStateManager::RegisterPrefs(registry); 292 MetricsStateManager::RegisterPrefs(registry);
293 MetricsLog::RegisterPrefs(registry); 293 MetricsLog::RegisterPrefs(registry);
294 294
295 registry->RegisterInt64Pref(metrics::prefs::kInstallDate, 0); 295 registry->RegisterInt64Pref(prefs::kInstallDate, 0);
296 296
297 registry->RegisterInt64Pref(metrics::prefs::kStabilityLaunchTimeSec, 0); 297 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0);
298 registry->RegisterInt64Pref(metrics::prefs::kStabilityLastTimestampSec, 0); 298 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0);
299 registry->RegisterStringPref(metrics::prefs::kStabilityStatsVersion, 299 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string());
300 std::string()); 300 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0);
301 registry->RegisterInt64Pref(metrics::prefs::kStabilityStatsBuildTime, 0); 301 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
302 registry->RegisterBooleanPref(metrics::prefs::kStabilityExitedCleanly, true); 302 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase,
303 registry->RegisterIntegerPref(metrics::prefs::kStabilityExecutionPhase,
304 UNINITIALIZED_PHASE); 303 UNINITIALIZED_PHASE);
305 registry->RegisterBooleanPref(metrics::prefs::kStabilitySessionEndCompleted, 304 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true);
306 true); 305 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1);
307 registry->RegisterIntegerPref(metrics::prefs::kMetricsSessionID, -1);
308 306
309 registry->RegisterListPref(metrics::prefs::kMetricsInitialLogs); 307 registry->RegisterListPref(prefs::kMetricsInitialLogs);
310 registry->RegisterListPref(metrics::prefs::kMetricsOngoingLogs); 308 registry->RegisterListPref(prefs::kMetricsOngoingLogs);
311 309
312 registry->RegisterInt64Pref(metrics::prefs::kUninstallLaunchCount, 0); 310 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
313 registry->RegisterInt64Pref(metrics::prefs::kUninstallMetricsUptimeSec, 0); 311 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
314 } 312 }
315 313
316 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, 314 MetricsService::MetricsService(MetricsStateManager* state_manager,
317 metrics::MetricsServiceClient* client, 315 MetricsServiceClient* client,
318 PrefService* local_state) 316 PrefService* local_state)
319 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), 317 : log_manager_(local_state, kUploadLogAvoidRetransmitSize),
320 histogram_snapshot_manager_(this), 318 histogram_snapshot_manager_(this),
321 state_manager_(state_manager), 319 state_manager_(state_manager),
322 client_(client), 320 client_(client),
323 local_state_(local_state), 321 local_state_(local_state),
324 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), 322 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state),
325 recording_active_(false), 323 recording_active_(false),
326 reporting_active_(false), 324 reporting_active_(false),
327 test_mode_active_(false), 325 test_mode_active_(false),
328 state_(INITIALIZED), 326 state_(INITIALIZED),
329 has_initial_stability_log_(false), 327 has_initial_stability_log_(false),
330 log_upload_in_progress_(false), 328 log_upload_in_progress_(false),
331 idle_since_last_transmission_(false), 329 idle_since_last_transmission_(false),
332 session_id_(-1), 330 session_id_(-1),
333 self_ptr_factory_(this), 331 self_ptr_factory_(this),
334 state_saver_factory_(this) { 332 state_saver_factory_(this) {
335 DCHECK(IsSingleThreaded()); 333 DCHECK(IsSingleThreaded());
336 DCHECK(state_manager_); 334 DCHECK(state_manager_);
337 DCHECK(client_); 335 DCHECK(client_);
338 DCHECK(local_state_); 336 DCHECK(local_state_);
339 337
340 // Set the install date if this is our first run. 338 // Set the install date if this is our first run.
341 int64 install_date = local_state_->GetInt64(metrics::prefs::kInstallDate); 339 int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
342 if (install_date == 0) { 340 if (install_date == 0)
343 local_state_->SetInt64(metrics::prefs::kInstallDate, 341 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
344 base::Time::Now().ToTimeT());
345 }
346 } 342 }
347 343
348 MetricsService::~MetricsService() { 344 MetricsService::~MetricsService() {
349 DisableRecording(); 345 DisableRecording();
350 } 346 }
351 347
352 void MetricsService::InitializeMetricsRecordingState() { 348 void MetricsService::InitializeMetricsRecordingState() {
353 InitializeMetricsState(); 349 InitializeMetricsState();
354 350
355 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, 351 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 387
392 void MetricsService::DisableReporting() { 388 void MetricsService::DisableReporting() {
393 reporting_active_ = false; 389 reporting_active_ = false;
394 } 390 }
395 391
396 std::string MetricsService::GetClientId() { 392 std::string MetricsService::GetClientId() {
397 return state_manager_->client_id(); 393 return state_manager_->client_id();
398 } 394 }
399 395
400 int64 MetricsService::GetInstallDate() { 396 int64 MetricsService::GetInstallDate() {
401 return local_state_->GetInt64(metrics::prefs::kInstallDate); 397 return local_state_->GetInt64(prefs::kInstallDate);
402 } 398 }
403 399
404 scoped_ptr<const base::FieldTrial::EntropyProvider> 400 scoped_ptr<const base::FieldTrial::EntropyProvider>
405 MetricsService::CreateEntropyProvider() { 401 MetricsService::CreateEntropyProvider() {
406 // TODO(asvitkine): Refactor the code so that MetricsService does not expose 402 // TODO(asvitkine): Refactor the code so that MetricsService does not expose
407 // this method. 403 // this method.
408 return state_manager_->CreateEntropyProvider(); 404 return state_manager_->CreateEntropyProvider();
409 } 405 }
410 406
411 void MetricsService::EnableRecording() { 407 void MetricsService::EnableRecording() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 idle_since_last_transmission_ = in_idle; 482 idle_since_last_transmission_ = in_idle;
487 } 483 }
488 484
489 void MetricsService::OnApplicationNotIdle() { 485 void MetricsService::OnApplicationNotIdle() {
490 if (recording_active_) 486 if (recording_active_)
491 HandleIdleSinceLastTransmission(false); 487 HandleIdleSinceLastTransmission(false);
492 } 488 }
493 489
494 void MetricsService::RecordStartOfSessionEnd() { 490 void MetricsService::RecordStartOfSessionEnd() {
495 LogCleanShutdown(); 491 LogCleanShutdown();
496 RecordBooleanPrefValue(metrics::prefs::kStabilitySessionEndCompleted, false); 492 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false);
497 } 493 }
498 494
499 void MetricsService::RecordCompletedSessionEnd() { 495 void MetricsService::RecordCompletedSessionEnd() {
500 LogCleanShutdown(); 496 LogCleanShutdown();
501 RecordBooleanPrefValue(metrics::prefs::kStabilitySessionEndCompleted, true); 497 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true);
502 } 498 }
503 499
504 #if defined(OS_ANDROID) || defined(OS_IOS) 500 #if defined(OS_ANDROID) || defined(OS_IOS)
505 void MetricsService::OnAppEnterBackground() { 501 void MetricsService::OnAppEnterBackground() {
506 scheduler_->Stop(); 502 scheduler_->Stop();
507 503
508 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); 504 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_);
509 505
510 // At this point, there's no way of knowing when the process will be 506 // At this point, there's no way of knowing when the process will be
511 // killed, so this has to be treated similar to a shutdown, closing and 507 // killed, so this has to be treated similar to a shutdown, closing and
(...skipping 17 matching lines...) Expand all
529 clean_exit_beacon_.WriteBeaconValue(false); 525 clean_exit_beacon_.WriteBeaconValue(false);
530 // Redundant setting to be sure we call for a clean shutdown. 526 // Redundant setting to be sure we call for a clean shutdown.
531 clean_shutdown_status_ = NEED_TO_SHUTDOWN; 527 clean_shutdown_status_ = NEED_TO_SHUTDOWN;
532 } 528 }
533 #endif // defined(OS_ANDROID) || defined(OS_IOS) 529 #endif // defined(OS_ANDROID) || defined(OS_IOS)
534 530
535 // static 531 // static
536 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase, 532 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase,
537 PrefService* local_state) { 533 PrefService* local_state) {
538 execution_phase_ = execution_phase; 534 execution_phase_ = execution_phase;
539 local_state->SetInteger(metrics::prefs::kStabilityExecutionPhase, 535 local_state->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_);
540 execution_phase_);
541 } 536 }
542 537
543 void MetricsService::RecordBreakpadRegistration(bool success) { 538 void MetricsService::RecordBreakpadRegistration(bool success) {
544 if (!success) 539 if (!success)
545 IncrementPrefValue(metrics::prefs::kStabilityBreakpadRegistrationFail); 540 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail);
546 else 541 else
547 IncrementPrefValue(metrics::prefs::kStabilityBreakpadRegistrationSuccess); 542 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess);
548 } 543 }
549 544
550 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { 545 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) {
551 if (!has_debugger) 546 if (!has_debugger)
552 IncrementPrefValue(metrics::prefs::kStabilityDebuggerNotPresent); 547 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent);
553 else 548 else
554 IncrementPrefValue(metrics::prefs::kStabilityDebuggerPresent); 549 IncrementPrefValue(prefs::kStabilityDebuggerPresent);
555 } 550 }
556 551
557 //------------------------------------------------------------------------------ 552 //------------------------------------------------------------------------------
558 // private methods 553 // private methods
559 //------------------------------------------------------------------------------ 554 //------------------------------------------------------------------------------
560 555
561 556
562 //------------------------------------------------------------------------------ 557 //------------------------------------------------------------------------------
563 // Initialization methods 558 // Initialization methods
564 559
565 void MetricsService::InitializeMetricsState() { 560 void MetricsService::InitializeMetricsState() {
566 const int64 buildtime = MetricsLog::GetBuildTime(); 561 const int64 buildtime = MetricsLog::GetBuildTime();
567 const std::string version = client_->GetVersionString(); 562 const std::string version = client_->GetVersionString();
568 bool version_changed = false; 563 bool version_changed = false;
569 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime || 564 if (local_state_->GetInt64(prefs::kStabilityStatsBuildTime) != buildtime ||
570 local_state_->GetString(prefs::kStabilityStatsVersion) != version) { 565 local_state_->GetString(prefs::kStabilityStatsVersion) != version) {
571 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, version); 566 local_state_->SetString(prefs::kStabilityStatsVersion, version);
572 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, buildtime); 567 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime);
573 version_changed = true; 568 version_changed = true;
574 } 569 }
575 570
576 log_manager_.LoadPersistedUnsentLogs(); 571 log_manager_.LoadPersistedUnsentLogs();
577 572
578 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); 573 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID);
579 574
580 if (!clean_exit_beacon_.exited_cleanly()) { 575 if (!clean_exit_beacon_.exited_cleanly()) {
581 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); 576 IncrementPrefValue(prefs::kStabilityCrashCount);
582 // Reset flag, and wait until we call LogNeedForCleanShutdown() before 577 // Reset flag, and wait until we call LogNeedForCleanShutdown() before
583 // monitoring. 578 // monitoring.
584 clean_exit_beacon_.WriteBeaconValue(true); 579 clean_exit_beacon_.WriteBeaconValue(true);
585 } 580 }
586 581
587 if (!clean_exit_beacon_.exited_cleanly() || ProvidersHaveStabilityMetrics()) { 582 if (!clean_exit_beacon_.exited_cleanly() || ProvidersHaveStabilityMetrics()) {
588 // TODO(rtenneti): On windows, consider saving/getting execution_phase from 583 // TODO(rtenneti): On windows, consider saving/getting execution_phase from
589 // the registry. 584 // the registry.
590 int execution_phase = 585 int execution_phase =
591 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); 586 local_state_->GetInteger(prefs::kStabilityExecutionPhase);
592 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", 587 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase",
593 execution_phase); 588 execution_phase);
594 589
595 // If the previous session didn't exit cleanly, or if any provider 590 // If the previous session didn't exit cleanly, or if any provider
596 // explicitly requests it, prepare an initial stability log - 591 // explicitly requests it, prepare an initial stability log -
597 // provided UMA is enabled. 592 // provided UMA is enabled.
598 if (state_manager_->IsMetricsReportingEnabled()) 593 if (state_manager_->IsMetricsReportingEnabled())
599 PrepareInitialStabilityLog(); 594 PrepareInitialStabilityLog();
600 } 595 }
601 596
(...skipping 11 matching lines...) Expand all
613 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); 608 local_state_->SetInteger(prefs::kStabilityCrashCount, 0);
614 local_state_->SetInteger(prefs::kStabilityExecutionPhase, 609 local_state_->SetInteger(prefs::kStabilityExecutionPhase,
615 UNINITIALIZED_PHASE); 610 UNINITIALIZED_PHASE);
616 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 611 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
617 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); 612 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0);
618 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); 613 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
619 } 614 }
620 615
621 // Update session ID. 616 // Update session ID.
622 ++session_id_; 617 ++session_id_;
623 local_state_->SetInteger(metrics::prefs::kMetricsSessionID, session_id_); 618 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_);
624 619
625 // Stability bookkeeping 620 // Stability bookkeeping
626 IncrementPrefValue(metrics::prefs::kStabilityLaunchCount); 621 IncrementPrefValue(prefs::kStabilityLaunchCount);
627 622
628 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); 623 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_);
629 SetExecutionPhase(START_METRICS_RECORDING, local_state_); 624 SetExecutionPhase(START_METRICS_RECORDING, local_state_);
630 625
631 if (!local_state_->GetBoolean( 626 if (!local_state_->GetBoolean(prefs::kStabilitySessionEndCompleted)) {
632 metrics::prefs::kStabilitySessionEndCompleted)) { 627 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount);
633 IncrementPrefValue(metrics::prefs::kStabilityIncompleteSessionEndCount);
634 // This is marked false when we get a WM_ENDSESSION. 628 // This is marked false when we get a WM_ENDSESSION.
635 local_state_->SetBoolean(metrics::prefs::kStabilitySessionEndCompleted, 629 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
636 true);
637 } 630 }
638 631
639 // Call GetUptimes() for the first time, thus allowing all later calls 632 // Call GetUptimes() for the first time, thus allowing all later calls
640 // to record incremental uptimes accurately. 633 // to record incremental uptimes accurately.
641 base::TimeDelta ignored_uptime_parameter; 634 base::TimeDelta ignored_uptime_parameter;
642 base::TimeDelta startup_uptime; 635 base::TimeDelta startup_uptime;
643 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter); 636 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter);
644 DCHECK_EQ(0, startup_uptime.InMicroseconds()); 637 DCHECK_EQ(0, startup_uptime.InMicroseconds());
645 // For backwards compatibility, leave this intact in case Omaha is checking 638 // For backwards compatibility, leave this intact in case Omaha is checking
646 // them. metrics::prefs::kStabilityLastTimestampSec may also be useless now. 639 // them. prefs::kStabilityLastTimestampSec may also be useless now.
647 // TODO(jar): Delete these if they have no uses. 640 // TODO(jar): Delete these if they have no uses.
648 local_state_->SetInt64(metrics::prefs::kStabilityLaunchTimeSec, 641 local_state_->SetInt64(prefs::kStabilityLaunchTimeSec,
649 base::Time::Now().ToTimeT()); 642 base::Time::Now().ToTimeT());
650 643
651 // Bookkeeping for the uninstall metrics. 644 // Bookkeeping for the uninstall metrics.
652 IncrementLongPrefsValue(metrics::prefs::kUninstallLaunchCount); 645 IncrementLongPrefsValue(prefs::kUninstallLaunchCount);
653 646
654 // Kick off the process of saving the state (so the uptime numbers keep 647 // Kick off the process of saving the state (so the uptime numbers keep
655 // getting updated) every n minutes. 648 // getting updated) every n minutes.
656 ScheduleNextStateSave(); 649 ScheduleNextStateSave();
657 } 650 }
658 651
659 void MetricsService::OnUserAction(const std::string& action) { 652 void MetricsService::OnUserAction(const std::string& action) {
660 if (!ShouldLogEvents()) 653 if (!ShouldLogEvents())
661 return; 654 return;
662 655
(...skipping 23 matching lines...) Expand all
686 if (last_updated_time_.is_null()) { 679 if (last_updated_time_.is_null()) {
687 first_updated_time_ = now; 680 first_updated_time_ = now;
688 last_updated_time_ = now; 681 last_updated_time_ = now;
689 } 682 }
690 *incremental_uptime = now - last_updated_time_; 683 *incremental_uptime = now - last_updated_time_;
691 *uptime = now - first_updated_time_; 684 *uptime = now - first_updated_time_;
692 last_updated_time_ = now; 685 last_updated_time_ = now;
693 686
694 const int64 incremental_time_secs = incremental_uptime->InSeconds(); 687 const int64 incremental_time_secs = incremental_uptime->InSeconds();
695 if (incremental_time_secs > 0) { 688 if (incremental_time_secs > 0) {
696 int64 metrics_uptime = 689 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
697 pref->GetInt64(metrics::prefs::kUninstallMetricsUptimeSec);
698 metrics_uptime += incremental_time_secs; 690 metrics_uptime += incremental_time_secs;
699 pref->SetInt64(metrics::prefs::kUninstallMetricsUptimeSec, metrics_uptime); 691 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
700 } 692 }
701 } 693 }
702 694
703 void MetricsService::NotifyOnDidCreateMetricsLog() { 695 void MetricsService::NotifyOnDidCreateMetricsLog() {
704 DCHECK(IsSingleThreaded()); 696 DCHECK(IsSingleThreaded());
705 for (size_t i = 0; i < metrics_providers_.size(); ++i) 697 for (size_t i = 0; i < metrics_providers_.size(); ++i)
706 metrics_providers_[i]->OnDidCreateMetricsLog(); 698 metrics_providers_[i]->OnDidCreateMetricsLog();
707 } 699 }
708 700
709 //------------------------------------------------------------------------------ 701 //------------------------------------------------------------------------------
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 return; 1149 return;
1158 } 1150 }
1159 } 1151 }
1160 1152
1161 SyntheticTrialGroup trial_group = trial; 1153 SyntheticTrialGroup trial_group = trial;
1162 trial_group.start_time = base::TimeTicks::Now(); 1154 trial_group.start_time = base::TimeTicks::Now();
1163 synthetic_trial_groups_.push_back(trial_group); 1155 synthetic_trial_groups_.push_back(trial_group);
1164 } 1156 }
1165 1157
1166 void MetricsService::RegisterMetricsProvider( 1158 void MetricsService::RegisterMetricsProvider(
1167 scoped_ptr<metrics::MetricsProvider> provider) { 1159 scoped_ptr<MetricsProvider> provider) {
1168 DCHECK_EQ(INITIALIZED, state_); 1160 DCHECK_EQ(INITIALIZED, state_);
1169 metrics_providers_.push_back(provider.release()); 1161 metrics_providers_.push_back(provider.release());
1170 } 1162 }
1171 1163
1172 void MetricsService::CheckForClonedInstall( 1164 void MetricsService::CheckForClonedInstall(
1173 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 1165 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
1174 state_manager_->CheckForClonedInstall(task_runner); 1166 state_manager_->CheckForClonedInstall(task_runner);
1175 } 1167 }
1176 1168
1177 void MetricsService::GetCurrentSyntheticFieldTrials( 1169 void MetricsService::GetCurrentSyntheticFieldTrials(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 void MetricsService::LogCleanShutdown() { 1209 void MetricsService::LogCleanShutdown() {
1218 // Redundant hack to write pref ASAP. 1210 // Redundant hack to write pref ASAP.
1219 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); 1211 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_);
1220 1212
1221 // Redundant setting to assure that we always reset this value at shutdown 1213 // Redundant setting to assure that we always reset this value at shutdown
1222 // (and that we don't use some alternate path, and not call LogCleanShutdown). 1214 // (and that we don't use some alternate path, and not call LogCleanShutdown).
1223 clean_shutdown_status_ = CLEANLY_SHUTDOWN; 1215 clean_shutdown_status_ = CLEANLY_SHUTDOWN;
1224 1216
1225 clean_exit_beacon_.WriteBeaconValue(true); 1217 clean_exit_beacon_.WriteBeaconValue(true);
1226 RecordCurrentState(local_state_); 1218 RecordCurrentState(local_state_);
1227 local_state_->SetInteger(metrics::prefs::kStabilityExecutionPhase, 1219 local_state_->SetInteger(prefs::kStabilityExecutionPhase,
1228 MetricsService::SHUTDOWN_COMPLETE); 1220 MetricsService::SHUTDOWN_COMPLETE);
1229 } 1221 }
1230 1222
1231 bool MetricsService::ShouldLogEvents() { 1223 bool MetricsService::ShouldLogEvents() {
1232 // We simply don't log events to UMA if there is a single incognito 1224 // We simply don't log events to UMA if there is a single incognito
1233 // session visible. The problem is that we always notify using the orginal 1225 // session visible. The problem is that we always notify using the orginal
1234 // profile in order to simplify notification processing. 1226 // profile in order to simplify notification processing.
1235 return !client_->IsOffTheRecordSessionActive(); 1227 return !client_->IsOffTheRecordSessionActive();
1236 } 1228 }
1237 1229
1238 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { 1230 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) {
1239 DCHECK(IsSingleThreaded()); 1231 DCHECK(IsSingleThreaded());
1240 local_state_->SetBoolean(path, value); 1232 local_state_->SetBoolean(path, value);
1241 RecordCurrentState(local_state_); 1233 RecordCurrentState(local_state_);
1242 } 1234 }
1243 1235
1244 void MetricsService::RecordCurrentState(PrefService* pref) { 1236 void MetricsService::RecordCurrentState(PrefService* pref) {
1245 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, 1237 pref->SetInt64(prefs::kStabilityLastTimestampSec,
1246 base::Time::Now().ToTimeT()); 1238 base::Time::Now().ToTimeT());
1247 } 1239 }
1248 1240
1249 } // namespace metrics 1241 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698