| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 private: | 428 private: |
| 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->RegisterBooleanPref(prefs::kMetricsResetIds, false); |
| 438 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); | 439 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); |
| 439 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, | 440 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, |
| 440 kLowEntropySourceNotSet); | 441 kLowEntropySourceNotSet); |
| 441 registry->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); | 442 registry->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); |
| 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, |
| (...skipping 66 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 UMA_HISTOGRAM_BOOLEAN("UMA.MetricsIDsReset", true); |
| 1204 |
| 1205 DCHECK(client_id_.empty()); |
| 1206 DCHECK_EQ(kLowEntropySourceNotSet, low_entropy_source_); |
| 1207 |
| 1208 local_state->ClearPref(prefs::kMetricsClientID); |
| 1209 local_state->ClearPref(prefs::kMetricsLowEntropySource); |
| 1210 local_state->ClearPref(prefs::kMetricsResetIds); |
| 1211 } |
| 1212 |
| 1188 int MetricsService::GetLowEntropySource() { | 1213 int MetricsService::GetLowEntropySource() { |
| 1189 // Note that the default value for the low entropy source and the default pref | 1214 // 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 | 1215 // value are both kLowEntropySourceNotSet, which is used to identify if the |
| 1191 // value has been set or not. | 1216 // value has been set or not. |
| 1192 if (low_entropy_source_ != kLowEntropySourceNotSet) | 1217 if (low_entropy_source_ != kLowEntropySourceNotSet) |
| 1193 return low_entropy_source_; | 1218 return low_entropy_source_; |
| 1194 | 1219 |
| 1220 ResetMetricsIDsIfNecessary(); |
| 1221 |
| 1195 PrefService* local_state = g_browser_process->local_state(); | 1222 PrefService* local_state = g_browser_process->local_state(); |
| 1196 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 1223 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
| 1197 // Only try to load the value from prefs if the user did not request a reset. | 1224 // Only try to load the value from prefs if the user did not request a reset. |
| 1198 // Otherwise, skip to generating a new value. | 1225 // Otherwise, skip to generating a new value. |
| 1199 if (!command_line->HasSwitch(switches::kResetVariationState)) { | 1226 if (!command_line->HasSwitch(switches::kResetVariationState)) { |
| 1200 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | 1227 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); |
| 1201 // Old versions of the code would generate values in the range of [1, 8192], | 1228 // 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 | 1229 // 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 | 1230 // 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. | 1231 // 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. | 2125 // Android has its own settings for metrics / crash uploading. |
| 2099 const PrefService* prefs = g_browser_process->local_state(); | 2126 const PrefService* prefs = g_browser_process->local_state(); |
| 2100 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2127 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
| 2101 #else | 2128 #else |
| 2102 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2129 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
| 2103 #endif | 2130 #endif |
| 2104 #else | 2131 #else |
| 2105 return false; | 2132 return false; |
| 2106 #endif | 2133 #endif |
| 2107 } | 2134 } |
| OLD | NEW |