Chromium Code Reviews| 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::kMetricsClientIDTimestamp, 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 registry->RegisterStringPref(prefs::kMetricsOldClientID, std::string()); | |
| 488 registry->RegisterStringPref(prefs::kMetricsOldLowEntropySource, | |
| 489 std::string()); | |
| 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 // Make a note of when the user opted in to UMA. |
|
rkaplow
2014/03/28 17:20:26
nit: I find "make a note" still a bit informal con
Alexei Svitkine (slow)
2014/03/28 17:39:15
Agreed. Done.
| |
| 645 pref->SetString(prefs::kMetricsClientIDTimestamp, | 650 if (pref->GetString(prefs::kMetricsOldClientID).empty()) |
| 646 base::Int64ToString(Time::Now().ToTimeT())); | 651 pref->SetInt64(prefs::kMetricsClientIDTimestamp, Time::Now().ToTimeT()); |
| 652 pref->ClearPref(prefs::kMetricsOldClientID); | |
|
jwd
2014/03/28 15:47:52
Can you log a boolean histogram when a user migrat
Alexei Svitkine (slow)
2014/03/28 17:39:15
Done.
| |
| 647 } | 653 } |
| 648 | 654 |
| 649 void MetricsService::EnableRecording() { | 655 void MetricsService::EnableRecording() { |
| 650 DCHECK(IsSingleThreaded()); | 656 DCHECK(IsSingleThreaded()); |
| 651 | 657 |
| 652 if (recording_active_) | 658 if (recording_active_) |
| 653 return; | 659 return; |
| 654 recording_active_ = true; | 660 recording_active_ = true; |
| 655 | 661 |
| 656 ForceClientIdCreation(); | 662 ForceClientIdCreation(); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 // value has been set or not. | 1197 // value has been set or not. |
| 1192 if (low_entropy_source_ != kLowEntropySourceNotSet) | 1198 if (low_entropy_source_ != kLowEntropySourceNotSet) |
| 1193 return low_entropy_source_; | 1199 return low_entropy_source_; |
| 1194 | 1200 |
| 1195 PrefService* local_state = g_browser_process->local_state(); | 1201 PrefService* local_state = g_browser_process->local_state(); |
| 1196 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 1202 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
| 1197 // Only try to load the value from prefs if the user did not request a reset. | 1203 // Only try to load the value from prefs if the user did not request a reset. |
| 1198 // Otherwise, skip to generating a new value. | 1204 // Otherwise, skip to generating a new value. |
| 1199 if (!command_line->HasSwitch(switches::kResetVariationState)) { | 1205 if (!command_line->HasSwitch(switches::kResetVariationState)) { |
| 1200 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | 1206 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 | 1207 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate |
| 1208 // it below. | 1208 // it below. |
| 1209 if (value >= 0 && value < kMaxLowEntropySize) { | 1209 if (value >= 0 && value < kMaxLowEntropySize) { |
| 1210 low_entropy_source_ = value; | 1210 low_entropy_source_ = value; |
| 1211 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); | 1211 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); |
| 1212 return low_entropy_source_; | 1212 return low_entropy_source_; |
| 1213 } | 1213 } |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); | 1216 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); |
| 1217 low_entropy_source_ = GenerateLowEntropySource(); | 1217 low_entropy_source_ = GenerateLowEntropySource(); |
| 1218 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); | 1218 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); |
| 1219 local_state->ClearPref(prefs::kMetricsOldLowEntropySource); | |
| 1219 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); | 1220 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); |
| 1220 | 1221 |
| 1221 return low_entropy_source_; | 1222 return low_entropy_source_; |
| 1222 } | 1223 } |
| 1223 | 1224 |
| 1224 // static | 1225 // static |
| 1225 std::string MetricsService::GenerateClientID() { | 1226 std::string MetricsService::GenerateClientID() { |
| 1226 return base::GenerateGUID(); | 1227 return base::GenerateGUID(); |
| 1227 } | 1228 } |
| 1228 | 1229 |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2098 // Android has its own settings for metrics / crash uploading. | 2099 // Android has its own settings for metrics / crash uploading. |
| 2099 const PrefService* prefs = g_browser_process->local_state(); | 2100 const PrefService* prefs = g_browser_process->local_state(); |
| 2100 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2101 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
| 2101 #else | 2102 #else |
| 2102 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2103 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
| 2103 #endif | 2104 #endif |
| 2104 #else | 2105 #else |
| 2105 return false; | 2106 return false; |
| 2106 #endif | 2107 #endif |
| 2107 } | 2108 } |
| OLD | NEW |