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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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->RegisterIntegerPref(prefs::kMetricsLowEntropySource, | 439 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, |
440 kLowEntropySourceNotSet); | 440 kLowEntropySourceNotSet); |
441 registry->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); | 441 registry->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); |
442 registry->RegisterBooleanPref(prefs::kMetricsResetIds, false); | |
Alexei Svitkine (slow)
2014/03/28 19:02:50
Nit: Maybe move this at the top of the list, so th
jwd
2014/03/28 19:43:15
Done.
| |
442 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 443 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
443 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 444 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
444 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); | 445 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); |
445 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); | 446 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
446 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); | 447 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
447 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, | 448 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, |
448 UNINITIALIZED_PHASE); | 449 UNINITIALIZED_PHASE); |
449 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); | 450 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); |
450 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); | 451 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); |
451 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); | 452 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 | 515 |
515 local_state->ClearPref(prefs::kMetricsInitialLogs); | 516 local_state->ClearPref(prefs::kMetricsInitialLogs); |
516 local_state->ClearPref(prefs::kMetricsOngoingLogs); | 517 local_state->ClearPref(prefs::kMetricsOngoingLogs); |
517 | 518 |
518 #if defined(OS_ANDROID) | 519 #if defined(OS_ANDROID) |
519 DiscardOldStabilityStatsAndroid(local_state); | 520 DiscardOldStabilityStatsAndroid(local_state); |
520 #endif // defined(OS_ANDROID) | 521 #endif // defined(OS_ANDROID) |
521 } | 522 } |
522 | 523 |
523 MetricsService::MetricsService() | 524 MetricsService::MetricsService() |
524 : recording_active_(false), | 525 : metrics_ids_reset_check_performed_(false), |
526 recording_active_(false), | |
525 reporting_active_(false), | 527 reporting_active_(false), |
526 test_mode_active_(false), | 528 test_mode_active_(false), |
527 state_(INITIALIZED), | 529 state_(INITIALIZED), |
528 has_initial_stability_log_(false), | 530 has_initial_stability_log_(false), |
529 low_entropy_source_(kLowEntropySourceNotSet), | 531 low_entropy_source_(kLowEntropySourceNotSet), |
530 idle_since_last_transmission_(false), | 532 idle_since_last_transmission_(false), |
531 session_id_(-1), | 533 session_id_(-1), |
532 next_window_id_(0), | 534 next_window_id_(0), |
533 self_ptr_factory_(this), | 535 self_ptr_factory_(this), |
534 state_saver_factory_(this), | 536 state_saver_factory_(this), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 #else | 628 #else |
627 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | 629 return scoped_ptr<const base::FieldTrial::EntropyProvider>( |
628 new metrics::PermutedEntropyProvider(low_entropy_source_value, | 630 new metrics::PermutedEntropyProvider(low_entropy_source_value, |
629 kMaxLowEntropySize)); | 631 kMaxLowEntropySize)); |
630 #endif | 632 #endif |
631 } | 633 } |
632 | 634 |
633 void MetricsService::ForceClientIdCreation() { | 635 void MetricsService::ForceClientIdCreation() { |
634 if (!client_id_.empty()) | 636 if (!client_id_.empty()) |
635 return; | 637 return; |
638 | |
639 ResetMetricsIDsIfNecessary(); | |
640 | |
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 // Might as well make a note of how long this ID has existed |
645 pref->SetString(prefs::kMetricsClientIDTimestamp, | 650 pref->SetString(prefs::kMetricsClientIDTimestamp, |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 last_updated_time_ = now; | 1183 last_updated_time_ = now; |
1179 | 1184 |
1180 const int64 incremental_time_secs = incremental_uptime->InSeconds(); | 1185 const int64 incremental_time_secs = incremental_uptime->InSeconds(); |
1181 if (incremental_time_secs > 0) { | 1186 if (incremental_time_secs > 0) { |
1182 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); | 1187 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
1183 metrics_uptime += incremental_time_secs; | 1188 metrics_uptime += incremental_time_secs; |
1184 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); | 1189 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
1185 } | 1190 } |
1186 } | 1191 } |
1187 | 1192 |
1193 void MetricsService::ResetMetricsIDsIfNecessary() { | |
1194 if (metrics_ids_reset_check_performed_) | |
1195 return; | |
1196 | |
1197 metrics_ids_reset_check_performed_ = true; | |
1198 | |
1199 PrefService* local_state = g_browser_process->local_state(); | |
1200 if (!local_state->GetBoolean(prefs::kMetricsResetIds)) | |
1201 return; | |
1202 | |
1203 DCHECK(client_id_.empty()); | |
1204 DCHECK_EQ(kLowEntropySourceNotSet, low_entropy_source_); | |
1205 | |
1206 local_state->ClearPref(prefs::kMetricsClientID); | |
1207 local_state->ClearPref(prefs::kMetricsLowEntropySource); | |
1208 local_state->ClearPref(prefs::kMetricsResetIds); | |
1209 } | |
1210 | |
1188 int MetricsService::GetLowEntropySource() { | 1211 int MetricsService::GetLowEntropySource() { |
1189 // Note that the default value for the low entropy source and the default pref | 1212 // Note that the default value for the low entropy source and the default pref |
1190 // value are both kLowEntropySourceNotSet, which is used to identify if the | 1213 // value are both kLowEntropySourceNotSet, which is used to identify if the |
1191 // value has been set or not. | 1214 // value has been set or not. |
1192 if (low_entropy_source_ != kLowEntropySourceNotSet) | 1215 if (low_entropy_source_ != kLowEntropySourceNotSet) |
1193 return low_entropy_source_; | 1216 return low_entropy_source_; |
1194 | 1217 |
1218 ResetMetricsIDsIfNecessary(); | |
1219 | |
1195 PrefService* local_state = g_browser_process->local_state(); | 1220 PrefService* local_state = g_browser_process->local_state(); |
1196 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 1221 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
1197 // Only try to load the value from prefs if the user did not request a reset. | 1222 // Only try to load the value from prefs if the user did not request a reset. |
1198 // Otherwise, skip to generating a new value. | 1223 // Otherwise, skip to generating a new value. |
1199 if (!command_line->HasSwitch(switches::kResetVariationState)) { | 1224 if (!command_line->HasSwitch(switches::kResetVariationState)) { |
1200 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | 1225 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); |
1201 // Old versions of the code would generate values in the range of [1, 8192], | 1226 // 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 | 1227 // 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 | 1228 // 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. | 1229 // the low entropy source for old values in the [8000, 8191] range. |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2098 // Android has its own settings for metrics / crash uploading. | 2123 // Android has its own settings for metrics / crash uploading. |
2099 const PrefService* prefs = g_browser_process->local_state(); | 2124 const PrefService* prefs = g_browser_process->local_state(); |
2100 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2125 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
2101 #else | 2126 #else |
2102 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2127 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
2103 #endif | 2128 #endif |
2104 #else | 2129 #else |
2105 return false; | 2130 return false; |
2106 #endif | 2131 #endif |
2107 } | 2132 } |
OLD | NEW |