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

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 10830318: Use a different algorithm with the low entropy source for field trials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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 10 // A MetricsService instance is typically created at application startup. It
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 #include "chrome/browser/prefs/pref_service.h" 178 #include "chrome/browser/prefs/pref_service.h"
179 #include "chrome/browser/prefs/scoped_user_pref_update.h" 179 #include "chrome/browser/prefs/scoped_user_pref_update.h"
180 #include "chrome/browser/profiles/profile.h" 180 #include "chrome/browser/profiles/profile.h"
181 #include "chrome/browser/search_engines/template_url_service.h" 181 #include "chrome/browser/search_engines/template_url_service.h"
182 #include "chrome/browser/ui/browser_list.h" 182 #include "chrome/browser/ui/browser_list.h"
183 #include "chrome/browser/ui/browser_otr_state.h" 183 #include "chrome/browser/ui/browser_otr_state.h"
184 #include "chrome/common/child_process_logging.h" 184 #include "chrome/common/child_process_logging.h"
185 #include "chrome/common/chrome_notification_types.h" 185 #include "chrome/common/chrome_notification_types.h"
186 #include "chrome/common/chrome_result_codes.h" 186 #include "chrome/common/chrome_result_codes.h"
187 #include "chrome/common/chrome_switches.h" 187 #include "chrome/common/chrome_switches.h"
188 #include "chrome/common/metrics/entropy_provider.h"
188 #include "chrome/common/metrics/metrics_log_manager.h" 189 #include "chrome/common/metrics/metrics_log_manager.h"
189 #include "chrome/common/net/test_server_locations.h" 190 #include "chrome/common/net/test_server_locations.h"
190 #include "chrome/common/pref_names.h" 191 #include "chrome/common/pref_names.h"
191 #include "chrome/common/render_messages.h" 192 #include "chrome/common/render_messages.h"
192 #include "content/public/browser/child_process_data.h" 193 #include "content/public/browser/child_process_data.h"
193 #include "content/public/browser/histogram_fetcher.h" 194 #include "content/public/browser/histogram_fetcher.h"
194 #include "content/public/browser/load_notification_details.h" 195 #include "content/public/browser/load_notification_details.h"
195 #include "content/public/browser/notification_service.h" 196 #include "content/public/browser/notification_service.h"
196 #include "content/public/browser/plugin_service.h" 197 #include "content/public/browser/plugin_service.h"
197 #include "content/public/browser/render_process_host.h" 198 #include "content/public/browser/render_process_host.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 273 }
273 274
274 // The argument used to generate a non-identifying entropy source. We want no 275 // The argument used to generate a non-identifying entropy source. We want no
275 // more than 13 bits of entropy, so use this max to return a number between 1 276 // more than 13 bits of entropy, so use this max to return a number between 1
276 // and 2^13 = 8192 as the entropy source. 277 // and 2^13 = 8192 as the entropy source.
277 const uint32 kMaxEntropySize = (1 << 13); 278 const uint32 kMaxEntropySize = (1 << 13);
278 279
279 // Generates a new non-identifying entropy source used to seed persistent 280 // Generates a new non-identifying entropy source used to seed persistent
280 // activities. 281 // activities.
281 int GenerateLowEntropySource() { 282 int GenerateLowEntropySource() {
282 return base::RandInt(1, kMaxEntropySize); 283 return base::RandInt(0, kMaxEntropySize - 1);
283 } 284 }
284 285
285 // Converts an exit code into something that can be inserted into our 286 // Converts an exit code into something that can be inserted into our
286 // histograms (which expect non-negative numbers less than MAX_INT). 287 // histograms (which expect non-negative numbers less than MAX_INT).
287 int MapCrashExitCodeForHistogram(int exit_code) { 288 int MapCrashExitCodeForHistogram(int exit_code) {
288 #if defined(OS_WIN) 289 #if defined(OS_WIN)
289 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in 290 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in
290 // histograms.cc. Solve this by remapping it to a smaller value, which 291 // histograms.cc. Solve this by remapping it to a smaller value, which
291 // hopefully doesn't conflict with other codes. 292 // hopefully doesn't conflict with other codes.
292 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) 293 if (exit_code == STATUS_GUARD_PAGE_VIOLATION)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 STATUS_STACK_OVERFLOW, 338 STATUS_STACK_OVERFLOW,
338 }; 339 };
339 340
340 for (size_t i = 0; i < arraysize(kExceptionCodes); ++i) 341 for (size_t i = 0; i < arraysize(kExceptionCodes); ++i)
341 codes.push_back(MapCrashExitCodeForHistogram(kExceptionCodes[i])); 342 codes.push_back(MapCrashExitCodeForHistogram(kExceptionCodes[i]));
342 #endif 343 #endif
343 344
344 return codes; 345 return codes;
345 } 346 }
346 347
347 } 348 } // namespace
348 349
349 // static 350 // static
350 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = 351 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
351 MetricsService::CLEANLY_SHUTDOWN; 352 MetricsService::CLEANLY_SHUTDOWN;
352 353
353 // This is used to quickly log stats from child process related notifications in 354 // This is used to quickly log stats from child process related notifications in
354 // MetricsService::child_stats_buffer_. The buffer's contents are transferred 355 // MetricsService::child_stats_buffer_. The buffer's contents are transferred
355 // out when Local State is periodically saved. The information is then 356 // out when Local State is periodically saved. The information is then
356 // reported to the UMA server on next launch. 357 // reported to the UMA server on next launch.
357 struct MetricsService::ChildProcessStats { 358 struct MetricsService::ChildProcessStats {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 void MetricsService::Stop() { 533 void MetricsService::Stop() {
533 HandleIdleSinceLastTransmission(false); 534 HandleIdleSinceLastTransmission(false);
534 SetReporting(false); 535 SetReporting(false);
535 SetRecording(false); 536 SetRecording(false);
536 } 537 }
537 538
538 std::string MetricsService::GetClientId() { 539 std::string MetricsService::GetClientId() {
539 return client_id_; 540 return client_id_;
540 } 541 }
541 542
542 std::string MetricsService::GetEntropySource(bool reporting_will_be_enabled) { 543 base::FieldTrial::EntropyProvider* MetricsService::GetEntropyProvider(
544 bool reporting_will_be_enabled) {
545 const int low_entropy_source = GetLowEntropySource();
546
543 // For metrics reporting-enabled users, we combine the client ID and low 547 // For metrics reporting-enabled users, we combine the client ID and low
544 // entropy source to get the final entropy source. Otherwise, only use the low 548 // entropy source to get the final entropy source. Otherwise, only use the low
545 // entropy source. 549 // entropy source.
546 // This has two useful properties: 550 // This has two useful properties:
547 // 1) It makes the entropy source less identifiable for parties that do not 551 // 1) It makes the entropy source less identifiable for parties that do not
548 // know the low entropy source. 552 // know the low entropy source.
549 // 2) It makes the final entropy source resettable. 553 // 2) It makes the final entropy source resettable.
550 std::string low_entropy_source = base::IntToString(GetLowEntropySource());
551 if (reporting_will_be_enabled) { 554 if (reporting_will_be_enabled) {
552 entropy_source_returned_ = LAST_ENTROPY_HIGH; 555 entropy_source_returned_ = LAST_ENTROPY_HIGH;
553 return client_id_ + low_entropy_source; 556 const std::string high_entropy_source =
557 client_id_ + base::IntToString(low_entropy_source);
558 return new SHA1EntropyProvider(high_entropy_source);
Ilya Sherman 2012/08/17 07:34:28 I'm not a fan of functions that return heap-alloca
Alexei Svitkine (slow) 2012/08/17 14:08:59 Done.
554 } 559 }
560
555 entropy_source_returned_ = LAST_ENTROPY_LOW; 561 entropy_source_returned_ = LAST_ENTROPY_LOW;
556 return low_entropy_source; 562 return new PermutedEntropyProvider(GetLowEntropySource(), kMaxEntropySize);
557 } 563 }
558 564
559 void MetricsService::ForceClientIdCreation() { 565 void MetricsService::ForceClientIdCreation() {
560 if (!client_id_.empty()) 566 if (!client_id_.empty())
561 return; 567 return;
562 PrefService* pref = g_browser_process->local_state(); 568 PrefService* pref = g_browser_process->local_state();
563 client_id_ = pref->GetString(prefs::kMetricsClientID); 569 client_id_ = pref->GetString(prefs::kMetricsClientID);
564 if (!client_id_.empty()) 570 if (!client_id_.empty())
565 return; 571 return;
566 572
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 if (local_state) { 1915 if (local_state) {
1910 const PrefService::Preference* uma_pref = 1916 const PrefService::Preference* uma_pref =
1911 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1917 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1912 if (uma_pref) { 1918 if (uma_pref) {
1913 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1919 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1914 DCHECK(success); 1920 DCHECK(success);
1915 } 1921 }
1916 } 1922 }
1917 return result; 1923 return result;
1918 } 1924 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698