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

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
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 case net::URLFetcher::RESPONSE_CODE_INVALID: 268 case net::URLFetcher::RESPONSE_CODE_INVALID:
268 return NO_RESPONSE; 269 return NO_RESPONSE;
269 default: 270 default:
270 return UNKNOWN_FAILURE; 271 return UNKNOWN_FAILURE;
271 } 272 }
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 kMaxLowEntropySize = (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, kMaxLowEntropySize - 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 scoped_ptr<const base::FieldTrial::EntropyProvider>
544 MetricsService::CreateEntropyProvider(bool reporting_will_be_enabled) {
543 // For metrics reporting-enabled users, we combine the client ID and low 545 // 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 546 // entropy source to get the final entropy source. Otherwise, only use the low
545 // entropy source. 547 // entropy source.
546 // This has two useful properties: 548 // This has two useful properties:
547 // 1) It makes the entropy source less identifiable for parties that do not 549 // 1) It makes the entropy source less identifiable for parties that do not
548 // know the low entropy source. 550 // know the low entropy source.
549 // 2) It makes the final entropy source resettable. 551 // 2) It makes the final entropy source resettable.
550 std::string low_entropy_source = base::IntToString(GetLowEntropySource());
551 if (reporting_will_be_enabled) { 552 if (reporting_will_be_enabled) {
552 if (entropy_source_returned_ == LAST_ENTROPY_NONE) 553 if (entropy_source_returned_ == LAST_ENTROPY_NONE)
553 entropy_source_returned_ = LAST_ENTROPY_HIGH; 554 entropy_source_returned_ = LAST_ENTROPY_HIGH;
554 DCHECK_EQ(LAST_ENTROPY_HIGH, entropy_source_returned_); 555 DCHECK_EQ(LAST_ENTROPY_HIGH, entropy_source_returned_);
555 return client_id_ + low_entropy_source; 556 const std::string high_entropy_source =
557 client_id_ + base::IntToString(GetLowEntropySource());
558 return scoped_ptr<const base::FieldTrial::EntropyProvider>(
559 new metrics::SHA1EntropyProvider(high_entropy_source));
556 } 560 }
561
557 if (entropy_source_returned_ == LAST_ENTROPY_NONE) 562 if (entropy_source_returned_ == LAST_ENTROPY_NONE)
558 entropy_source_returned_ = LAST_ENTROPY_LOW; 563 entropy_source_returned_ = LAST_ENTROPY_LOW;
559 DCHECK_EQ(LAST_ENTROPY_LOW, entropy_source_returned_); 564 DCHECK_EQ(LAST_ENTROPY_LOW, entropy_source_returned_);
560 return low_entropy_source; 565 return scoped_ptr<const base::FieldTrial::EntropyProvider>(
566 new metrics::PermutedEntropyProvider(GetLowEntropySource(),
567 kMaxLowEntropySize));
561 } 568 }
562 569
563 void MetricsService::ForceClientIdCreation() { 570 void MetricsService::ForceClientIdCreation() {
564 if (!client_id_.empty()) 571 if (!client_id_.empty())
565 return; 572 return;
566 PrefService* pref = g_browser_process->local_state(); 573 PrefService* pref = g_browser_process->local_state();
567 client_id_ = pref->GetString(prefs::kMetricsClientID); 574 client_id_ = pref->GetString(prefs::kMetricsClientID);
568 if (!client_id_.empty()) 575 if (!client_id_.empty())
569 return; 576 return;
570 577
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 if (local_state) { 1920 if (local_state) {
1914 const PrefService::Preference* uma_pref = 1921 const PrefService::Preference* uma_pref =
1915 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1922 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1916 if (uma_pref) { 1923 if (uma_pref) {
1917 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1924 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1918 DCHECK(success); 1925 DCHECK(success);
1919 } 1926 }
1920 } 1927 }
1921 return result; 1928 return result;
1922 } 1929 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698