| OLD | NEW |
| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 const int kLogIntervalSeconds = 30 * 60; | 28 const int kLogIntervalSeconds = 30 * 60; |
| 29 | 29 |
| 30 const char kMimeType[] = "application/vnd.chrome.rappor"; | 30 const char kMimeType[] = "application/vnd.chrome.rappor"; |
| 31 | 31 |
| 32 // Constants for the RAPPOR rollout field trial. | 32 // Constants for the RAPPOR rollout field trial. |
| 33 const char kRapporRolloutFieldTrialName[] = "RapporRollout"; | 33 const char kRapporRolloutFieldTrialName[] = "RapporRollout"; |
| 34 | 34 |
| 35 // Constant for the finch parameter name for the server URL | 35 // Constant for the finch parameter name for the server URL |
| 36 const char kRapporRolloutServerUrlParam[] = "ServerUrl"; | 36 const char kRapporRolloutServerUrlParam[] = "ServerUrl"; |
| 37 | 37 |
| 38 // Constant for the finch parameter name for the server URL |
| 39 const char kRapporRolloutRequireUmaParam[] = "RequireUma"; |
| 40 |
| 38 // The rappor server's URL. | 41 // The rappor server's URL. |
| 39 const char kDefaultServerUrl[] = "https://clients4.google.com/rappor"; | 42 const char kDefaultServerUrl[] = "https://clients4.google.com/rappor"; |
| 40 | 43 |
| 41 GURL GetServerUrl() { | 44 GURL GetServerUrl(bool metrics_enabled) { |
| 45 bool require_uma = variations::GetVariationParamValue( |
| 46 kRapporRolloutFieldTrialName, |
| 47 kRapporRolloutRequireUmaParam) != "False"; |
| 48 if (!metrics_enabled && require_uma) |
| 49 return GURL(); // Invalid URL disables Rappor. |
| 42 std::string server_url = variations::GetVariationParamValue( | 50 std::string server_url = variations::GetVariationParamValue( |
| 43 kRapporRolloutFieldTrialName, | 51 kRapporRolloutFieldTrialName, |
| 44 kRapporRolloutServerUrlParam); | 52 kRapporRolloutServerUrlParam); |
| 45 if (!server_url.empty()) | 53 if (!server_url.empty()) |
| 46 return GURL(server_url); | 54 return GURL(server_url); |
| 47 else | 55 else |
| 48 return GURL(kDefaultServerUrl); | 56 return GURL(kDefaultServerUrl); |
| 49 } | 57 } |
| 50 | 58 |
| 51 const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = { | 59 const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = { |
| 52 // ETLD_PLUS_ONE_RAPPOR_TYPE | 60 // ETLD_PLUS_ONE_RAPPOR_TYPE |
| 53 {128 /* Num cohorts */, | 61 {128 /* Num cohorts */, |
| 54 16 /* Bloom filter size bytes */, | 62 16 /* Bloom filter size bytes */, |
| 55 2 /* Bloom filter hash count */, | 63 2 /* Bloom filter hash count */, |
| 56 rappor::PROBABILITY_50 /* Fake data probability */, | 64 rappor::PROBABILITY_50 /* Fake data probability */, |
| 57 rappor::PROBABILITY_50 /* Fake one probability */, | 65 rappor::PROBABILITY_50 /* Fake one probability */, |
| 58 rappor::PROBABILITY_75 /* One coin probability */, | 66 rappor::PROBABILITY_75 /* One coin probability */, |
| 59 rappor::PROBABILITY_25 /* Zero coin probability */}, | 67 rappor::PROBABILITY_25 /* Zero coin probability */}, |
| 60 }; | 68 }; |
| 61 | 69 |
| 62 } // namespace | 70 } // namespace |
| 63 | 71 |
| 64 RapporService::RapporService() : cohort_(-1) {} | 72 RapporService::RapporService() : cohort_(-1) {} |
| 65 | 73 |
| 66 RapporService::~RapporService() { | 74 RapporService::~RapporService() { |
| 67 STLDeleteValues(&metrics_map_); | 75 STLDeleteValues(&metrics_map_); |
| 68 } | 76 } |
| 69 | 77 |
| 70 void RapporService::Start(PrefService* pref_service, | 78 void RapporService::Start(PrefService* pref_service, |
| 71 net::URLRequestContextGetter* request_context) { | 79 net::URLRequestContextGetter* request_context, |
| 72 const GURL server_url = GetServerUrl(); | 80 bool metrics_enabled) { |
| 81 const GURL server_url = GetServerUrl(metrics_enabled); |
| 73 if (!server_url.is_valid()) { | 82 if (!server_url.is_valid()) { |
| 74 DVLOG(1) << "RapporService not started: " | 83 DVLOG(1) << server_url.spec() << " is invalid. " |
| 75 << server_url.spec() << " is invalid."; | 84 << "RapporService not started."; |
| 76 return; | 85 return; |
| 77 } | 86 } |
| 78 DVLOG(1) << "RapporService started. Reporting to " << server_url.spec(); | 87 DVLOG(1) << "RapporService started. Reporting to " << server_url.spec(); |
| 79 DCHECK(!uploader_); | 88 DCHECK(!uploader_); |
| 80 LoadSecret(pref_service); | 89 LoadSecret(pref_service); |
| 81 LoadCohort(pref_service); | 90 LoadCohort(pref_service); |
| 82 uploader_.reset(new LogUploader(server_url, kMimeType, request_context)); | 91 uploader_.reset(new LogUploader(server_url, kMimeType, request_context)); |
| 83 log_rotation_timer_.Start( | 92 log_rotation_timer_.Start( |
| 84 FROM_HERE, | 93 FROM_HERE, |
| 85 base::TimeDelta::FromSeconds(kInitialLogIntervalSeconds), | 94 base::TimeDelta::FromSeconds(kInitialLogIntervalSeconds), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); | 212 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); |
| 204 return metric; | 213 return metric; |
| 205 } | 214 } |
| 206 | 215 |
| 207 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); | 216 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); |
| 208 metrics_map_[metric_name] = new_metric; | 217 metrics_map_[metric_name] = new_metric; |
| 209 return new_metric; | 218 return new_metric; |
| 210 } | 219 } |
| 211 | 220 |
| 212 } // namespace rappor | 221 } // namespace rappor |
| OLD | NEW |