Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: components/metrics/metrics_state_manager.cc

Issue 1984003002: Use low entropy for studies that send experiment IDs to Google properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 25 matching lines...) Expand all
36 // Default prefs value for prefs::kMetricsLowEntropySource to indicate that 36 // Default prefs value for prefs::kMetricsLowEntropySource to indicate that
37 // the value has not yet been set. 37 // the value has not yet been set.
38 const int kLowEntropySourceNotSet = -1; 38 const int kLowEntropySourceNotSet = -1;
39 39
40 // Generates a new non-identifying entropy source used to seed persistent 40 // Generates a new non-identifying entropy source used to seed persistent
41 // activities. 41 // activities.
42 int GenerateLowEntropySource() { 42 int GenerateLowEntropySource() {
43 return base::RandInt(0, kMaxLowEntropySize - 1); 43 return base::RandInt(0, kMaxLowEntropySize - 1);
44 } 44 }
45 45
46 // Records the given |low_entorpy_source_value| in a histogram.
47 void LogLowEntropyValue(int low_entropy_source_value) {
48 UMA_HISTOGRAM_SPARSE_SLOWLY("UMA.LowEntropySourceValue",
49 low_entropy_source_value);
50 }
51
46 } // namespace 52 } // namespace
47 53
48 // static 54 // static
49 bool MetricsStateManager::instance_exists_ = false; 55 bool MetricsStateManager::instance_exists_ = false;
50 56
51 MetricsStateManager::MetricsStateManager( 57 MetricsStateManager::MetricsStateManager(
52 PrefService* local_state, 58 PrefService* local_state,
53 EnabledStateProvider* enabled_state_provider, 59 EnabledStateProvider* enabled_state_provider,
54 const StoreClientInfoCallback& store_client_info, 60 const StoreClientInfoCallback& store_client_info,
55 const LoadClientInfoCallback& retrieve_client_info) 61 const LoadClientInfoCallback& retrieve_client_info)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 147
142 MachineIdProvider* provider = MachineIdProvider::CreateInstance(); 148 MachineIdProvider* provider = MachineIdProvider::CreateInstance();
143 if (!provider) 149 if (!provider)
144 return; 150 return;
145 151
146 cloned_install_detector_.reset(new ClonedInstallDetector(provider)); 152 cloned_install_detector_.reset(new ClonedInstallDetector(provider));
147 cloned_install_detector_->CheckForClonedInstall(local_state_, task_runner); 153 cloned_install_detector_->CheckForClonedInstall(local_state_, task_runner);
148 } 154 }
149 155
150 std::unique_ptr<const base::FieldTrial::EntropyProvider> 156 std::unique_ptr<const base::FieldTrial::EntropyProvider>
151 MetricsStateManager::CreateEntropyProvider() { 157 MetricsStateManager::CreateDefaultEntropyProvider() {
152 // For metrics reporting-enabled users, we combine the client ID and low
153 // entropy source to get the final entropy source. Otherwise, only use the low
154 // entropy source.
155 // This has two useful properties:
156 // 1) It makes the entropy source less identifiable for parties that do not
157 // know the low entropy source.
158 // 2) It makes the final entropy source resettable.
159 const int low_entropy_source_value = GetLowEntropySource();
160 UMA_HISTOGRAM_SPARSE_SLOWLY("UMA.LowEntropySourceValue",
161 low_entropy_source_value);
162 if (enabled_state_provider_->IsConsentGiven()) { 158 if (enabled_state_provider_->IsConsentGiven()) {
159 // For metrics reporting-enabled users, we combine the client ID and low
160 // entropy source to get the final entropy source. Otherwise, only use the
161 // low entropy source.
162 // This has two useful properties:
163 // 1) It makes the entropy source less identifiable for parties that do not
164 // know the low entropy source.
165 // 2) It makes the final entropy source resettable.
166 const int low_entropy_source_value = GetLowEntropySource();
167
163 UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_HIGH); 168 UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_HIGH);
164 const std::string high_entropy_source = 169 const std::string high_entropy_source =
165 client_id_ + base::IntToString(low_entropy_source_value); 170 client_id_ + base::IntToString(low_entropy_source_value);
166 return std::unique_ptr<const base::FieldTrial::EntropyProvider>( 171 return std::unique_ptr<const base::FieldTrial::EntropyProvider>(
167 new SHA1EntropyProvider(high_entropy_source)); 172 new SHA1EntropyProvider(high_entropy_source));
168 } 173 }
169 174
170 UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_LOW); 175 UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_LOW);
176 return CreateLowEntropyProvider();
177 }
178
179 std::unique_ptr<const base::FieldTrial::EntropyProvider>
180 MetricsStateManager::CreateLowEntropyProvider() {
181 const int low_entropy_source_value = GetLowEntropySource();
182
171 #if defined(OS_ANDROID) || defined(OS_IOS) 183 #if defined(OS_ANDROID) || defined(OS_IOS)
172 return std::unique_ptr<const base::FieldTrial::EntropyProvider>( 184 return std::unique_ptr<const base::FieldTrial::EntropyProvider>(
173 new CachingPermutedEntropyProvider(local_state_, low_entropy_source_value, 185 new CachingPermutedEntropyProvider(local_state_, low_entropy_source_value,
174 kMaxLowEntropySize)); 186 kMaxLowEntropySize));
175 #else 187 #else
176 return std::unique_ptr<const base::FieldTrial::EntropyProvider>( 188 return std::unique_ptr<const base::FieldTrial::EntropyProvider>(
177 new PermutedEntropyProvider(low_entropy_source_value, 189 new PermutedEntropyProvider(low_entropy_source_value,
178 kMaxLowEntropySize)); 190 kMaxLowEntropySize));
179 #endif 191 #endif
180 } 192 }
(...skipping 10 matching lines...) Expand all
191 result.reset(new MetricsStateManager(local_state, enabled_state_provider, 203 result.reset(new MetricsStateManager(local_state, enabled_state_provider,
192 store_client_info, 204 store_client_info,
193 retrieve_client_info)); 205 retrieve_client_info));
194 } 206 }
195 return result; 207 return result;
196 } 208 }
197 209
198 // static 210 // static
199 void MetricsStateManager::RegisterPrefs(PrefRegistrySimple* registry) { 211 void MetricsStateManager::RegisterPrefs(PrefRegistrySimple* registry) {
200 registry->RegisterBooleanPref(prefs::kMetricsResetIds, false); 212 registry->RegisterBooleanPref(prefs::kMetricsResetIds, false);
201 // registry->RegisterIntegerPref(prefs::kMetricsDefaultOptIn,
202 // DEFAULT_UNKNOWN);
203 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); 213 registry->RegisterStringPref(prefs::kMetricsClientID, std::string());
204 registry->RegisterInt64Pref(prefs::kMetricsReportingEnabledTimestamp, 0); 214 registry->RegisterInt64Pref(prefs::kMetricsReportingEnabledTimestamp, 0);
205 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, 215 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource,
206 kLowEntropySourceNotSet); 216 kLowEntropySourceNotSet);
207 217
208 ClonedInstallDetector::RegisterPrefs(registry); 218 ClonedInstallDetector::RegisterPrefs(registry);
209 CachingPermutedEntropyProvider::RegisterPrefs(registry); 219 CachingPermutedEntropyProvider::RegisterPrefs(registry);
210 } 220 }
211 221
212 void MetricsStateManager::BackUpCurrentClientInfo() { 222 void MetricsStateManager::BackUpCurrentClientInfo() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); 277 const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
268 // Only try to load the value from prefs if the user did not request a 278 // Only try to load the value from prefs if the user did not request a
269 // reset. 279 // reset.
270 // Otherwise, skip to generating a new value. 280 // Otherwise, skip to generating a new value.
271 if (!command_line->HasSwitch(switches::kResetVariationState)) { 281 if (!command_line->HasSwitch(switches::kResetVariationState)) {
272 int value = local_state_->GetInteger(prefs::kMetricsLowEntropySource); 282 int value = local_state_->GetInteger(prefs::kMetricsLowEntropySource);
273 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate 283 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate
274 // it below. 284 // it below.
275 if (value >= 0 && value < kMaxLowEntropySize) { 285 if (value >= 0 && value < kMaxLowEntropySize) {
276 low_entropy_source_ = value; 286 low_entropy_source_ = value;
287 LogLowEntropyValue(low_entropy_source_);
277 return; 288 return;
278 } 289 }
279 } 290 }
280 291
281 low_entropy_source_ = GenerateLowEntropySource(); 292 low_entropy_source_ = GenerateLowEntropySource();
293 LogLowEntropyValue(low_entropy_source_);
282 local_state_->SetInteger(prefs::kMetricsLowEntropySource, 294 local_state_->SetInteger(prefs::kMetricsLowEntropySource,
283 low_entropy_source_); 295 low_entropy_source_);
284 CachingPermutedEntropyProvider::ClearCache(local_state_); 296 CachingPermutedEntropyProvider::ClearCache(local_state_);
285 } 297 }
286 298
287 void MetricsStateManager::UpdateEntropySourceReturnedValue( 299 void MetricsStateManager::UpdateEntropySourceReturnedValue(
288 EntropySourceType type) { 300 EntropySourceType type) {
289 if (entropy_source_returned_ != ENTROPY_SOURCE_NONE) 301 if (entropy_source_returned_ != ENTROPY_SOURCE_NONE)
290 return; 302 return;
291 303
(...skipping 13 matching lines...) Expand all
305 317
306 local_state_->ClearPref(prefs::kMetricsClientID); 318 local_state_->ClearPref(prefs::kMetricsClientID);
307 local_state_->ClearPref(prefs::kMetricsLowEntropySource); 319 local_state_->ClearPref(prefs::kMetricsLowEntropySource);
308 local_state_->ClearPref(prefs::kMetricsResetIds); 320 local_state_->ClearPref(prefs::kMetricsResetIds);
309 321
310 // Also clear the backed up client info. 322 // Also clear the backed up client info.
311 store_client_info_.Run(ClientInfo()); 323 store_client_info_.Run(ClientInfo());
312 } 324 }
313 325
314 } // namespace metrics 326 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_state_manager.h ('k') | components/metrics/metrics_state_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698