OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/metrics/metrics_state_manager.h" | 5 #include "components/metrics/metrics_state_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 // Flush the backup back to persistent storage in case we re-generated | 117 // Flush the backup back to persistent storage in case we re-generated |
118 // missing data above. | 118 // missing data above. |
119 BackUpCurrentClientInfo(); | 119 BackUpCurrentClientInfo(); |
120 return; | 120 return; |
121 } | 121 } |
122 | 122 |
123 // Failing attempts at getting an existing client ID, generate a new one. | 123 // Failing attempts at getting an existing client ID, generate a new one. |
124 client_id_ = base::GenerateGUID(); | 124 client_id_ = base::GenerateGUID(); |
125 local_state_->SetString(prefs::kMetricsClientID, client_id_); | 125 local_state_->SetString(prefs::kMetricsClientID, client_id_); |
126 | 126 |
127 if (local_state_->GetString(prefs::kMetricsOldClientID).empty()) { | 127 if (local_state_->GetString(prefs::kMetricsOldClientID).empty()) { |
jwd
2015/05/29 18:46:22
What about this migration code, and obsoleting the
Alexei Svitkine (slow)
2015/05/29 18:59:17
Err, you're right. Done.
| |
128 // Record the timestamp of when the user opted in to UMA. | 128 // Record the timestamp of when the user opted in to UMA. |
129 local_state_->SetInt64(prefs::kMetricsReportingEnabledTimestamp, | 129 local_state_->SetInt64(prefs::kMetricsReportingEnabledTimestamp, |
130 base::Time::Now().ToTimeT()); | 130 base::Time::Now().ToTimeT()); |
131 } else { | 131 } else { |
132 UMA_HISTOGRAM_BOOLEAN("UMA.ClientIdMigrated", true); | 132 UMA_HISTOGRAM_BOOLEAN("UMA.ClientIdMigrated", true); |
133 } | 133 } |
134 local_state_->ClearPref(prefs::kMetricsOldClientID); | 134 local_state_->ClearPref(prefs::kMetricsOldClientID); |
135 | 135 |
136 BackUpCurrentClientInfo(); | 136 BackUpCurrentClientInfo(); |
137 } | 137 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 // static | 201 // static |
202 void MetricsStateManager::RegisterPrefs(PrefRegistrySimple* registry) { | 202 void MetricsStateManager::RegisterPrefs(PrefRegistrySimple* registry) { |
203 registry->RegisterBooleanPref(prefs::kMetricsResetIds, false); | 203 registry->RegisterBooleanPref(prefs::kMetricsResetIds, false); |
204 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); | 204 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); |
205 registry->RegisterInt64Pref(prefs::kMetricsReportingEnabledTimestamp, 0); | 205 registry->RegisterInt64Pref(prefs::kMetricsReportingEnabledTimestamp, 0); |
206 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, | 206 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, |
207 kLowEntropySourceNotSet); | 207 kLowEntropySourceNotSet); |
208 | 208 |
209 ClonedInstallDetector::RegisterPrefs(registry); | 209 ClonedInstallDetector::RegisterPrefs(registry); |
210 CachingPermutedEntropyProvider::RegisterPrefs(registry); | 210 CachingPermutedEntropyProvider::RegisterPrefs(registry); |
211 | |
212 // TODO(asvitkine): Remove these once a couple of releases have passed. | |
213 // http://crbug.com/357704 | |
214 registry->RegisterStringPref(prefs::kMetricsOldClientID, std::string()); | |
215 registry->RegisterIntegerPref(prefs::kMetricsOldLowEntropySource, 0); | |
216 } | 211 } |
217 | 212 |
218 void MetricsStateManager::BackUpCurrentClientInfo() { | 213 void MetricsStateManager::BackUpCurrentClientInfo() { |
219 ClientInfo client_info; | 214 ClientInfo client_info; |
220 client_info.client_id = client_id_; | 215 client_info.client_id = client_id_; |
221 client_info.installation_date = local_state_->GetInt64(prefs::kInstallDate); | 216 client_info.installation_date = local_state_->GetInt64(prefs::kInstallDate); |
222 client_info.reporting_enabled_date = | 217 client_info.reporting_enabled_date = |
223 local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp); | 218 local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp); |
224 store_client_info_.Run(client_info); | 219 store_client_info_.Run(client_info); |
225 } | 220 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 305 |
311 local_state_->ClearPref(prefs::kMetricsClientID); | 306 local_state_->ClearPref(prefs::kMetricsClientID); |
312 local_state_->ClearPref(prefs::kMetricsLowEntropySource); | 307 local_state_->ClearPref(prefs::kMetricsLowEntropySource); |
313 local_state_->ClearPref(prefs::kMetricsResetIds); | 308 local_state_->ClearPref(prefs::kMetricsResetIds); |
314 | 309 |
315 // Also clear the backed up client info. | 310 // Also clear the backed up client info. |
316 store_client_info_.Run(ClientInfo()); | 311 store_client_info_.Run(ClientInfo()); |
317 } | 312 } |
318 | 313 |
319 } // namespace metrics | 314 } // namespace metrics |
OLD | NEW |