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

Side by Side Diff: components/rappor/rappor_service.cc

Issue 264123004: Modify rappor parameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert platform/os part, modify metric names. Created 6 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/rappor/rappor_service.h" 5 #include "components/rappor/rappor_service.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/sys_info.h"
Alexei Svitkine (slow) 2014/05/20 06:59:49 What's this for?
Steven Holte 2014/05/20 22:53:53 Not used in this revision. Removed.
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/metrics/metrics_hashes.h" 15 #include "components/metrics/metrics_hashes.h"
15 #include "components/rappor/log_uploader.h" 16 #include "components/rappor/log_uploader.h"
16 #include "components/rappor/proto/rappor_metric.pb.h" 17 #include "components/rappor/proto/rappor_metric.pb.h"
17 #include "components/rappor/rappor_metric.h" 18 #include "components/rappor/rappor_metric.h"
18 #include "components/rappor/rappor_pref_names.h" 19 #include "components/rappor/rappor_pref_names.h"
19 #include "components/variations/variations_associated_data.h" 20 #include "components/variations/variations_associated_data.h"
20 21
21 namespace rappor { 22 namespace rappor {
22 23
23 namespace { 24 namespace {
24 25
25 // The number of cohorts we divide clients into.
26 const int kNumCohorts = 32;
27
28 // Seconds before the initial log is generated. 26 // Seconds before the initial log is generated.
29 const int kInitialLogIntervalSeconds = 15; 27 const int kInitialLogIntervalSeconds = 15;
30 // Interval between ongoing logs. 28 // Interval between ongoing logs.
31 const int kLogIntervalSeconds = 30 * 60; 29 const int kLogIntervalSeconds = 30 * 60;
32 30
33 const char kMimeType[] = "application/vnd.chrome.rappor"; 31 const char kMimeType[] = "application/vnd.chrome.rappor";
34 32
35 // Constants for the RAPPOR rollout field trial. 33 // Constants for the RAPPOR rollout field trial.
36 const char kRapporRolloutFieldTrialName[] = "RapporRollout"; 34 const char kRapporRolloutFieldTrialName[] = "RapporRollout";
37 35
38 // Constant for the finch parameter name for the server URL 36 // Constant for the finch parameter name for the server URL
39 const char kRapporRolloutServerUrlParam[] = "ServerUrl"; 37 const char kRapporRolloutServerUrlParam[] = "ServerUrl";
40 38
41 GURL GetServerUrl() { 39 GURL GetServerUrl() {
42 return GURL(chrome_variations::GetVariationParamValue( 40 return GURL(chrome_variations::GetVariationParamValue(
43 kRapporRolloutFieldTrialName, 41 kRapporRolloutFieldTrialName,
44 kRapporRolloutServerUrlParam)); 42 kRapporRolloutServerUrlParam));
45 } 43 }
46 44
47 const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = { 45 const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = {
48 // ETLD_PLUS_ONE_RAPPOR_TYPE 46 // ETLD_PLUS_ONE_RAPPOR_TYPE
49 {16 /* Bloom filter size bytes */, 47 {128 /* Num cohorts */,
48 16 /* Bloom filter size bytes */,
50 2 /* Bloom filter hash count */, 49 2 /* Bloom filter hash count */,
51 rappor::PROBABILITY_75 /* Fake data probability */, 50 rappor::PROBABILITY_50 /* Fake data probability */,
52 rappor::PROBABILITY_50 /* Fake one probability */, 51 rappor::PROBABILITY_50 /* Fake one probability */,
53 rappor::PROBABILITY_75 /* One coin probability */, 52 rappor::PROBABILITY_75 /* One coin probability */,
54 rappor::PROBABILITY_50 /* Zero coin probability */}, 53 rappor::PROBABILITY_25 /* Zero coin probability */},
55 }; 54 };
56 55
57 } // namespace 56 } // namespace
58 57
59 RapporService::RapporService() : cohort_(-1) {} 58 RapporService::RapporService() : cohort_(-1) {}
60 59
61 RapporService::~RapporService() { 60 RapporService::~RapporService() {
62 STLDeleteValues(&metrics_map_); 61 STLDeleteValues(&metrics_map_);
63 } 62 }
64 63
(...skipping 24 matching lines...) Expand all
89 } 88 }
90 log_rotation_timer_.Start(FROM_HERE, 89 log_rotation_timer_.Start(FROM_HERE,
91 base::TimeDelta::FromSeconds(kLogIntervalSeconds), 90 base::TimeDelta::FromSeconds(kLogIntervalSeconds),
92 this, 91 this,
93 &RapporService::OnLogInterval); 92 &RapporService::OnLogInterval);
94 } 93 }
95 94
96 // static 95 // static
97 void RapporService::RegisterPrefs(PrefRegistrySimple* registry) { 96 void RapporService::RegisterPrefs(PrefRegistrySimple* registry) {
98 registry->RegisterStringPref(prefs::kRapporSecret, std::string()); 97 registry->RegisterStringPref(prefs::kRapporSecret, std::string());
99 registry->RegisterIntegerPref(prefs::kRapporCohort, -1); 98 registry->RegisterIntegerPref(prefs::kRapporCohortSeed, -1);
100 } 99 }
101 100
102 void RapporService::LoadCohort(PrefService* pref_service) { 101 void RapporService::LoadCohort(PrefService* pref_service) {
103 DCHECK(!IsInitialized()); 102 DCHECK(!IsInitialized());
104 cohort_ = pref_service->GetInteger(prefs::kRapporCohort); 103 cohort_ = pref_service->GetInteger(prefs::kRapporCohortSeed);
105 // If the user is already assigned to a valid cohort, we're done. 104 // If the user is already assigned to a valid cohort, we're done.
106 if (cohort_ >= 0 && cohort_ < kNumCohorts) 105 if (cohort_ >= 0 && cohort_ < RapporParameters::kMaxCohorts)
107 return; 106 return;
108 107
109 // This is the first time the client has started the service (or their 108 // This is the first time the client has started the service (or their
110 // preferences were corrupted). Randomly assign them to a cohort. 109 // preferences were corrupted). Randomly assign them to a cohort.
111 cohort_ = base::RandGenerator(kNumCohorts); 110 cohort_ = base::RandGenerator(RapporParameters::kMaxCohorts);
112 pref_service->SetInteger(prefs::kRapporCohort, cohort_); 111 pref_service->SetInteger(prefs::kRapporCohortSeed, cohort_);
113 } 112 }
114 113
115 void RapporService::LoadSecret(PrefService* pref_service) { 114 void RapporService::LoadSecret(PrefService* pref_service) {
116 DCHECK(secret_.empty()); 115 DCHECK(secret_.empty());
117 std::string secret_base64 = pref_service->GetString(prefs::kRapporSecret); 116 std::string secret_base64 = pref_service->GetString(prefs::kRapporSecret);
118 if (!secret_base64.empty()) { 117 if (!secret_base64.empty()) {
119 bool decoded = base::Base64Decode(secret_base64, &secret_); 118 bool decoded = base::Base64Decode(secret_base64, &secret_);
120 if (decoded && secret_.size() == HmacByteVectorGenerator::kEntropyInputSize) 119 if (decoded && secret_.size() == HmacByteVectorGenerator::kEntropyInputSize)
121 return; 120 return;
122 // If the preference fails to decode, or is the wrong size, it must be 121 // If the preference fails to decode, or is the wrong size, it must be
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); 181 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString());
183 return metric; 182 return metric;
184 } 183 }
185 184
186 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); 185 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_);
187 metrics_map_[metric_name] = new_metric; 186 metrics_map_[metric_name] = new_metric;
188 return new_metric; 187 return new_metric;
189 } 188 }
190 189
191 } // namespace rappor 190 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698