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

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

Powered by Google App Engine
This is Rietveld 408576698