| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // entropy source to get the final entropy source. Otherwise, only use the low | 154 // entropy source to get the final entropy source. Otherwise, only use the low |
| 155 // entropy source. | 155 // entropy source. |
| 156 // This has two useful properties: | 156 // This has two useful properties: |
| 157 // 1) It makes the entropy source less identifiable for parties that do not | 157 // 1) It makes the entropy source less identifiable for parties that do not |
| 158 // know the low entropy source. | 158 // know the low entropy source. |
| 159 // 2) It makes the final entropy source resettable. | 159 // 2) It makes the final entropy source resettable. |
| 160 const int low_entropy_source_value = GetLowEntropySource(); | 160 const int low_entropy_source_value = GetLowEntropySource(); |
| 161 UMA_HISTOGRAM_SPARSE_SLOWLY("UMA.LowEntropySourceValue", | 161 UMA_HISTOGRAM_SPARSE_SLOWLY("UMA.LowEntropySourceValue", |
| 162 low_entropy_source_value); | 162 low_entropy_source_value); |
| 163 if (IsMetricsReportingEnabled()) { | 163 if (IsMetricsReportingEnabled()) { |
| 164 if (entropy_source_returned_ == ENTROPY_SOURCE_NONE) | 164 UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_HIGH); |
| 165 entropy_source_returned_ = ENTROPY_SOURCE_HIGH; | |
| 166 const std::string high_entropy_source = | 165 const std::string high_entropy_source = |
| 167 client_id_ + base::IntToString(low_entropy_source_value); | 166 client_id_ + base::IntToString(low_entropy_source_value); |
| 168 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | 167 return scoped_ptr<const base::FieldTrial::EntropyProvider>( |
| 169 new SHA1EntropyProvider(high_entropy_source)); | 168 new SHA1EntropyProvider(high_entropy_source)); |
| 170 } | 169 } |
| 171 | 170 |
| 172 if (entropy_source_returned_ == ENTROPY_SOURCE_NONE) | 171 UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_LOW); |
| 173 entropy_source_returned_ = ENTROPY_SOURCE_LOW; | |
| 174 | |
| 175 #if defined(OS_ANDROID) || defined(OS_IOS) | 172 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 176 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | 173 return scoped_ptr<const base::FieldTrial::EntropyProvider>( |
| 177 new CachingPermutedEntropyProvider(local_state_, | 174 new CachingPermutedEntropyProvider(local_state_, |
| 178 low_entropy_source_value, | 175 low_entropy_source_value, |
| 179 kMaxLowEntropySize)); | 176 kMaxLowEntropySize)); |
| 180 #else | 177 #else |
| 181 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | 178 return scoped_ptr<const base::FieldTrial::EntropyProvider>( |
| 182 new PermutedEntropyProvider(low_entropy_source_value, | 179 new PermutedEntropyProvider(low_entropy_source_value, |
| 183 kMaxLowEntropySize)); | 180 kMaxLowEntropySize)); |
| 184 #endif | 181 #endif |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); | 282 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); |
| 286 low_entropy_source_ = GenerateLowEntropySource(); | 283 low_entropy_source_ = GenerateLowEntropySource(); |
| 287 local_state_->SetInteger(prefs::kMetricsLowEntropySource, | 284 local_state_->SetInteger(prefs::kMetricsLowEntropySource, |
| 288 low_entropy_source_); | 285 low_entropy_source_); |
| 289 local_state_->ClearPref(prefs::kMetricsOldLowEntropySource); | 286 local_state_->ClearPref(prefs::kMetricsOldLowEntropySource); |
| 290 CachingPermutedEntropyProvider::ClearCache(local_state_); | 287 CachingPermutedEntropyProvider::ClearCache(local_state_); |
| 291 | 288 |
| 292 return low_entropy_source_; | 289 return low_entropy_source_; |
| 293 } | 290 } |
| 294 | 291 |
| 292 void MetricsStateManager::UpdateEntropySourceReturnedValue( |
| 293 EntropySourceType type) { |
| 294 if (entropy_source_returned_ != ENTROPY_SOURCE_NONE) |
| 295 return; |
| 296 |
| 297 entropy_source_returned_ = type; |
| 298 UMA_HISTOGRAM_ENUMERATION("UMA.EntropySourceType", type, |
| 299 ENTROPY_SOURCE_ENUM_SIZE); |
| 300 } |
| 301 |
| 295 void MetricsStateManager::ResetMetricsIDsIfNecessary() { | 302 void MetricsStateManager::ResetMetricsIDsIfNecessary() { |
| 296 if (!local_state_->GetBoolean(prefs::kMetricsResetIds)) | 303 if (!local_state_->GetBoolean(prefs::kMetricsResetIds)) |
| 297 return; | 304 return; |
| 298 | 305 |
| 299 UMA_HISTOGRAM_BOOLEAN("UMA.MetricsIDsReset", true); | 306 UMA_HISTOGRAM_BOOLEAN("UMA.MetricsIDsReset", true); |
| 300 | 307 |
| 301 DCHECK(client_id_.empty()); | 308 DCHECK(client_id_.empty()); |
| 302 DCHECK_EQ(kLowEntropySourceNotSet, low_entropy_source_); | 309 DCHECK_EQ(kLowEntropySourceNotSet, low_entropy_source_); |
| 303 | 310 |
| 304 local_state_->ClearPref(prefs::kMetricsClientID); | 311 local_state_->ClearPref(prefs::kMetricsClientID); |
| 305 local_state_->ClearPref(prefs::kMetricsLowEntropySource); | 312 local_state_->ClearPref(prefs::kMetricsLowEntropySource); |
| 306 local_state_->ClearPref(prefs::kMetricsResetIds); | 313 local_state_->ClearPref(prefs::kMetricsResetIds); |
| 307 | 314 |
| 308 // Also clear the backed up client info. | 315 // Also clear the backed up client info. |
| 309 store_client_info_.Run(ClientInfo()); | 316 store_client_info_.Run(ClientInfo()); |
| 310 } | 317 } |
| 311 | 318 |
| 312 } // namespace metrics | 319 } // namespace metrics |
| OLD | NEW |