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::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. | |
|
Ilya Sherman
2014/03/28 18:23:06
nit: Please add a specific milestone target to thi
Alexei Svitkine (slow)
2014/03/28 18:40:19
Done. The milestone is on the bug.
| |
| 487 registry->RegisterStringPref(prefs::kMetricsOldClientID, std::string()); | |
| 488 registry->RegisterIntegerPref(prefs::kMetricsOldLowEntropySource, 0); | |
| 489 | |
| 486 #if defined(OS_ANDROID) | 490 #if defined(OS_ANDROID) |
| 487 RegisterPrefsAndroid(registry); | 491 RegisterPrefsAndroid(registry); |
| 488 #endif // defined(OS_ANDROID) | 492 #endif // defined(OS_ANDROID) |
| 489 } | 493 } |
| 490 | 494 |
| 491 // static | 495 // static |
| 492 void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { | 496 void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { |
| 493 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); | 497 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); |
| 494 local_state->SetInteger(prefs::kStabilityExecutionPhase, UNINITIALIZED_PHASE); | 498 local_state->SetInteger(prefs::kStabilityExecutionPhase, UNINITIALIZED_PHASE); |
| 495 local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 499 local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 if (!client_id_.empty()) | 638 if (!client_id_.empty()) |
| 635 return; | 639 return; |
| 636 PrefService* pref = g_browser_process->local_state(); | 640 PrefService* pref = g_browser_process->local_state(); |
| 637 client_id_ = pref->GetString(prefs::kMetricsClientID); | 641 client_id_ = pref->GetString(prefs::kMetricsClientID); |
| 638 if (!client_id_.empty()) | 642 if (!client_id_.empty()) |
| 639 return; | 643 return; |
| 640 | 644 |
| 641 client_id_ = GenerateClientID(); | 645 client_id_ = GenerateClientID(); |
| 642 pref->SetString(prefs::kMetricsClientID, client_id_); | 646 pref->SetString(prefs::kMetricsClientID, client_id_); |
| 643 | 647 |
| 644 // Might as well make a note of how long this ID has existed | 648 // Record the timestamp of when the user opted in to UMA. |
|
Ilya Sherman
2014/03/28 18:23:06
nit: Move this inside the if branch, since it does
Alexei Svitkine (slow)
2014/03/28 18:40:19
Done.
| |
| 645 pref->SetString(prefs::kMetricsClientIDTimestamp, | 649 if (pref->GetString(prefs::kMetricsOldClientID).empty()) { |
| 646 base::Int64ToString(Time::Now().ToTimeT())); | 650 pref->SetInt64(prefs::kMetricsReportingEnabledTimestamp, |
| 651 Time::Now().ToTimeT()); | |
| 652 } else { | |
| 653 UMA_HISTOGRAM_BOOLEAN("UMA.MigratedClientID", true); | |
|
Ilya Sherman
2014/03/28 18:23:06
You don't seem to ever emit a |false| value to thi
Alexei Svitkine (slow)
2014/03/28 18:40:19
This will allow analysis of when users migrated th
Ilya Sherman
2014/03/28 19:22:48
Fair 'nuff.
| |
| 654 } | |
| 655 pref->ClearPref(prefs::kMetricsOldClientID); | |
| 647 } | 656 } |
| 648 | 657 |
| 649 void MetricsService::EnableRecording() { | 658 void MetricsService::EnableRecording() { |
| 650 DCHECK(IsSingleThreaded()); | 659 DCHECK(IsSingleThreaded()); |
| 651 | 660 |
| 652 if (recording_active_) | 661 if (recording_active_) |
| 653 return; | 662 return; |
| 654 recording_active_ = true; | 663 recording_active_ = true; |
| 655 | 664 |
| 656 ForceClientIdCreation(); | 665 ForceClientIdCreation(); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 // value has been set or not. | 1200 // value has been set or not. |
| 1192 if (low_entropy_source_ != kLowEntropySourceNotSet) | 1201 if (low_entropy_source_ != kLowEntropySourceNotSet) |
| 1193 return low_entropy_source_; | 1202 return low_entropy_source_; |
| 1194 | 1203 |
| 1195 PrefService* local_state = g_browser_process->local_state(); | 1204 PrefService* local_state = g_browser_process->local_state(); |
| 1196 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 1205 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
| 1197 // Only try to load the value from prefs if the user did not request a reset. | 1206 // Only try to load the value from prefs if the user did not request a reset. |
| 1198 // Otherwise, skip to generating a new value. | 1207 // Otherwise, skip to generating a new value. |
| 1199 if (!command_line->HasSwitch(switches::kResetVariationState)) { | 1208 if (!command_line->HasSwitch(switches::kResetVariationState)) { |
| 1200 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | 1209 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 | 1210 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate |
| 1208 // it below. | 1211 // it below. |
| 1209 if (value >= 0 && value < kMaxLowEntropySize) { | 1212 if (value >= 0 && value < kMaxLowEntropySize) { |
| 1210 low_entropy_source_ = value; | 1213 low_entropy_source_ = value; |
| 1211 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); | 1214 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); |
| 1212 return low_entropy_source_; | 1215 return low_entropy_source_; |
| 1213 } | 1216 } |
| 1214 } | 1217 } |
| 1215 | 1218 |
| 1216 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); | 1219 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); |
| 1217 low_entropy_source_ = GenerateLowEntropySource(); | 1220 low_entropy_source_ = GenerateLowEntropySource(); |
| 1218 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); | 1221 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); |
| 1222 local_state->ClearPref(prefs::kMetricsOldLowEntropySource); | |
| 1219 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); | 1223 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); |
| 1220 | 1224 |
| 1221 return low_entropy_source_; | 1225 return low_entropy_source_; |
| 1222 } | 1226 } |
| 1223 | 1227 |
| 1224 // static | 1228 // static |
| 1225 std::string MetricsService::GenerateClientID() { | 1229 std::string MetricsService::GenerateClientID() { |
| 1226 return base::GenerateGUID(); | 1230 return base::GenerateGUID(); |
| 1227 } | 1231 } |
| 1228 | 1232 |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2098 // Android has its own settings for metrics / crash uploading. | 2102 // Android has its own settings for metrics / crash uploading. |
| 2099 const PrefService* prefs = g_browser_process->local_state(); | 2103 const PrefService* prefs = g_browser_process->local_state(); |
| 2100 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2104 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
| 2101 #else | 2105 #else |
| 2102 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2106 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
| 2103 #endif | 2107 #endif |
| 2104 #else | 2108 #else |
| 2105 return false; | 2109 return false; |
| 2106 #endif | 2110 #endif |
| 2107 } | 2111 } |
| OLD | NEW |