OLD | NEW |
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 typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 virtual ~MetricsMemoryDetails() {} | 429 virtual ~MetricsMemoryDetails() {} |
430 | 430 |
431 base::Closure callback_; | 431 base::Closure callback_; |
432 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | 432 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
433 }; | 433 }; |
434 | 434 |
435 // static | 435 // static |
436 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { | 436 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { |
437 DCHECK(IsSingleThreaded()); | 437 DCHECK(IsSingleThreaded()); |
438 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); | 438 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); |
| 439 registry->RegisterInt64Pref(prefs::kMetricsReportingEnabledTimestamp, 0); |
439 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, | 440 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, |
440 kLowEntropySourceNotSet); | 441 kLowEntropySourceNotSet); |
441 registry->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); | |
442 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 442 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
443 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 443 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
444 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); | 444 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); |
445 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); | 445 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
446 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); | 446 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
447 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, | 447 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, |
448 UNINITIALIZED_PHASE); | 448 UNINITIALIZED_PHASE); |
449 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); | 449 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); |
450 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); | 450 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); |
451 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); | 451 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
(...skipping 24 matching lines...) Expand all Loading... |
476 registry->RegisterListPref(prefs::kMetricsInitialLogs); | 476 registry->RegisterListPref(prefs::kMetricsInitialLogs); |
477 registry->RegisterListPref(prefs::kMetricsOngoingLogs); | 477 registry->RegisterListPref(prefs::kMetricsOngoingLogs); |
478 | 478 |
479 registry->RegisterInt64Pref(prefs::kInstallDate, 0); | 479 registry->RegisterInt64Pref(prefs::kInstallDate, 0); |
480 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); | 480 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); |
481 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 481 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
482 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 482 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
483 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 483 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
484 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 484 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
485 | 485 |
| 486 // TODO(asvitkine): Remove these once a couple of releases have passed. |
| 487 // http://crbug.com/357704 |
| 488 registry->RegisterStringPref(prefs::kMetricsOldClientID, std::string()); |
| 489 registry->RegisterIntegerPref(prefs::kMetricsOldLowEntropySource, 0); |
| 490 |
486 #if defined(OS_ANDROID) | 491 #if defined(OS_ANDROID) |
487 RegisterPrefsAndroid(registry); | 492 RegisterPrefsAndroid(registry); |
488 #endif // defined(OS_ANDROID) | 493 #endif // defined(OS_ANDROID) |
489 } | 494 } |
490 | 495 |
491 // static | 496 // static |
492 void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { | 497 void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { |
493 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); | 498 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); |
494 local_state->SetInteger(prefs::kStabilityExecutionPhase, UNINITIALIZED_PHASE); | 499 local_state->SetInteger(prefs::kStabilityExecutionPhase, UNINITIALIZED_PHASE); |
495 local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 500 local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 if (!client_id_.empty()) | 639 if (!client_id_.empty()) |
635 return; | 640 return; |
636 PrefService* pref = g_browser_process->local_state(); | 641 PrefService* pref = g_browser_process->local_state(); |
637 client_id_ = pref->GetString(prefs::kMetricsClientID); | 642 client_id_ = pref->GetString(prefs::kMetricsClientID); |
638 if (!client_id_.empty()) | 643 if (!client_id_.empty()) |
639 return; | 644 return; |
640 | 645 |
641 client_id_ = GenerateClientID(); | 646 client_id_ = GenerateClientID(); |
642 pref->SetString(prefs::kMetricsClientID, client_id_); | 647 pref->SetString(prefs::kMetricsClientID, client_id_); |
643 | 648 |
644 // Might as well make a note of how long this ID has existed | 649 if (pref->GetString(prefs::kMetricsOldClientID).empty()) { |
645 pref->SetString(prefs::kMetricsClientIDTimestamp, | 650 // Record the timestamp of when the user opted in to UMA. |
646 base::Int64ToString(Time::Now().ToTimeT())); | 651 pref->SetInt64(prefs::kMetricsReportingEnabledTimestamp, |
| 652 Time::Now().ToTimeT()); |
| 653 } else { |
| 654 UMA_HISTOGRAM_BOOLEAN("UMA.ClientIdMigrated", true); |
| 655 } |
| 656 pref->ClearPref(prefs::kMetricsOldClientID); |
647 } | 657 } |
648 | 658 |
649 void MetricsService::EnableRecording() { | 659 void MetricsService::EnableRecording() { |
650 DCHECK(IsSingleThreaded()); | 660 DCHECK(IsSingleThreaded()); |
651 | 661 |
652 if (recording_active_) | 662 if (recording_active_) |
653 return; | 663 return; |
654 recording_active_ = true; | 664 recording_active_ = true; |
655 | 665 |
656 ForceClientIdCreation(); | 666 ForceClientIdCreation(); |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 // value has been set or not. | 1201 // value has been set or not. |
1192 if (low_entropy_source_ != kLowEntropySourceNotSet) | 1202 if (low_entropy_source_ != kLowEntropySourceNotSet) |
1193 return low_entropy_source_; | 1203 return low_entropy_source_; |
1194 | 1204 |
1195 PrefService* local_state = g_browser_process->local_state(); | 1205 PrefService* local_state = g_browser_process->local_state(); |
1196 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 1206 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
1197 // Only try to load the value from prefs if the user did not request a reset. | 1207 // Only try to load the value from prefs if the user did not request a reset. |
1198 // Otherwise, skip to generating a new value. | 1208 // Otherwise, skip to generating a new value. |
1199 if (!command_line->HasSwitch(switches::kResetVariationState)) { | 1209 if (!command_line->HasSwitch(switches::kResetVariationState)) { |
1200 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | 1210 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); |
1201 // Old versions of the code would generate values in the range of [1, 8192], | |
1202 // before the range was switched to [0, 8191] and then to [0, 7999]. Map | |
1203 // 8192 to 0, so that the 0th bucket remains uniform, while re-generating | |
1204 // the low entropy source for old values in the [8000, 8191] range. | |
1205 if (value == 8192) | |
1206 value = 0; | |
1207 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate | 1211 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate |
1208 // it below. | 1212 // it below. |
1209 if (value >= 0 && value < kMaxLowEntropySize) { | 1213 if (value >= 0 && value < kMaxLowEntropySize) { |
1210 low_entropy_source_ = value; | 1214 low_entropy_source_ = value; |
1211 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); | 1215 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); |
1212 return low_entropy_source_; | 1216 return low_entropy_source_; |
1213 } | 1217 } |
1214 } | 1218 } |
1215 | 1219 |
1216 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); | 1220 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); |
1217 low_entropy_source_ = GenerateLowEntropySource(); | 1221 low_entropy_source_ = GenerateLowEntropySource(); |
1218 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); | 1222 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); |
| 1223 local_state->ClearPref(prefs::kMetricsOldLowEntropySource); |
1219 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); | 1224 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); |
1220 | 1225 |
1221 return low_entropy_source_; | 1226 return low_entropy_source_; |
1222 } | 1227 } |
1223 | 1228 |
1224 // static | 1229 // static |
1225 std::string MetricsService::GenerateClientID() { | 1230 std::string MetricsService::GenerateClientID() { |
1226 return base::GenerateGUID(); | 1231 return base::GenerateGUID(); |
1227 } | 1232 } |
1228 | 1233 |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 // Android has its own settings for metrics / crash uploading. | 2103 // Android has its own settings for metrics / crash uploading. |
2099 const PrefService* prefs = g_browser_process->local_state(); | 2104 const PrefService* prefs = g_browser_process->local_state(); |
2100 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2105 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
2101 #else | 2106 #else |
2102 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2107 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
2103 #endif | 2108 #endif |
2104 #else | 2109 #else |
2105 return false; | 2110 return false; |
2106 #endif | 2111 #endif |
2107 } | 2112 } |
OLD | NEW |