| Index: components/rappor/rappor_service.cc
|
| diff --git a/components/rappor/rappor_service.cc b/components/rappor/rappor_service.cc
|
| index 6ca64b70f94b8b2cf3e8924d5949d64726bacafa..da0f9f0e0924a6ad6fa679f5c35f7136d2b9b40c 100644
|
| --- a/components/rappor/rappor_service.cc
|
| +++ b/components/rappor/rappor_service.cc
|
| @@ -29,6 +29,9 @@ const int kLogIntervalSeconds = 30 * 60;
|
|
|
| const char kMimeType[] = "application/vnd.chrome.rappor";
|
|
|
| +const char kRapporDailyIntervalHistogram[] =
|
| + "Rappor.DailyInterval.IntervalType";
|
| +
|
| // Constants for the RAPPOR rollout field trial.
|
| const char kRapporRolloutFieldTrialName[] = "RapporRollout";
|
|
|
| @@ -69,14 +72,24 @@ const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = {
|
|
|
| } // namespace
|
|
|
| -RapporService::RapporService() : cohort_(-1) {}
|
| +RapporService::RapporService(PrefService* pref_service)
|
| + : pref_service_(pref_service),
|
| + cohort_(-1),
|
| + daily_interval_(pref_service,
|
| + prefs::kRapporLastDailySample,
|
| + kRapporDailyIntervalHistogram) {
|
| +}
|
|
|
| RapporService::~RapporService() {
|
| STLDeleteValues(&metrics_map_);
|
| }
|
|
|
| -void RapporService::Start(PrefService* pref_service,
|
| - net::URLRequestContextGetter* request_context,
|
| +void RapporService::AddDailyObserver(
|
| + scoped_ptr<metrics::DailyInterval::Observer> observer) {
|
| + daily_interval_.AddObserver(observer.Pass());
|
| +}
|
| +
|
| +void RapporService::Start(net::URLRequestContextGetter* request_context,
|
| bool metrics_enabled) {
|
| const GURL server_url = GetServerUrl(metrics_enabled);
|
| if (!server_url.is_valid()) {
|
| @@ -86,8 +99,8 @@ void RapporService::Start(PrefService* pref_service,
|
| }
|
| DVLOG(1) << "RapporService started. Reporting to " << server_url.spec();
|
| DCHECK(!uploader_);
|
| - LoadSecret(pref_service);
|
| - LoadCohort(pref_service);
|
| + LoadSecret();
|
| + LoadCohort();
|
| uploader_.reset(new LogUploader(server_url, kMimeType, request_context));
|
| log_rotation_timer_.Start(
|
| FROM_HERE,
|
| @@ -99,6 +112,7 @@ void RapporService::Start(PrefService* pref_service,
|
| void RapporService::OnLogInterval() {
|
| DCHECK(uploader_);
|
| DVLOG(2) << "RapporService::OnLogInterval";
|
| + daily_interval_.CheckInterval();
|
| RapporReports reports;
|
| if (ExportMetrics(&reports)) {
|
| std::string log_text;
|
| @@ -119,14 +133,16 @@ void RapporService::RegisterPrefs(PrefRegistrySimple* registry) {
|
| registry->RegisterStringPref(prefs::kRapporSecret, std::string());
|
| registry->RegisterIntegerPref(prefs::kRapporCohortDeprecated, -1);
|
| registry->RegisterIntegerPref(prefs::kRapporCohortSeed, -1);
|
| + metrics::DailyInterval::RegisterPref(registry,
|
| + prefs::kRapporLastDailySample);
|
| }
|
|
|
| -void RapporService::LoadCohort(PrefService* pref_service) {
|
| +void RapporService::LoadCohort() {
|
| DCHECK(!IsInitialized());
|
| // Ignore and delete old cohort parameter.
|
| - pref_service->ClearPref(prefs::kRapporCohortDeprecated);
|
| + pref_service_->ClearPref(prefs::kRapporCohortDeprecated);
|
|
|
| - cohort_ = pref_service->GetInteger(prefs::kRapporCohortSeed);
|
| + cohort_ = pref_service_->GetInteger(prefs::kRapporCohortSeed);
|
| // If the user is already assigned to a valid cohort, we're done.
|
| if (cohort_ >= 0 && cohort_ < RapporParameters::kMaxCohorts)
|
| return;
|
| @@ -135,12 +151,12 @@ void RapporService::LoadCohort(PrefService* pref_service) {
|
| // preferences were corrupted). Randomly assign them to a cohort.
|
| cohort_ = base::RandGenerator(RapporParameters::kMaxCohorts);
|
| DVLOG(2) << "Selected a new Rappor cohort: " << cohort_;
|
| - pref_service->SetInteger(prefs::kRapporCohortSeed, cohort_);
|
| + pref_service_->SetInteger(prefs::kRapporCohortSeed, cohort_);
|
| }
|
|
|
| -void RapporService::LoadSecret(PrefService* pref_service) {
|
| +void RapporService::LoadSecret() {
|
| DCHECK(secret_.empty());
|
| - std::string secret_base64 = pref_service->GetString(prefs::kRapporSecret);
|
| + std::string secret_base64 = pref_service_->GetString(prefs::kRapporSecret);
|
| if (!secret_base64.empty()) {
|
| bool decoded = base::Base64Decode(secret_base64, &secret_);
|
| if (decoded && secret_.size() == HmacByteVectorGenerator::kEntropyInputSize)
|
| @@ -153,7 +169,7 @@ void RapporService::LoadSecret(PrefService* pref_service) {
|
| DVLOG(2) << "Generated a new Rappor secret.";
|
| secret_ = HmacByteVectorGenerator::GenerateEntropyInput();
|
| base::Base64Encode(secret_, &secret_base64);
|
| - pref_service->SetString(prefs::kRapporSecret, secret_base64);
|
| + pref_service_->SetString(prefs::kRapporSecret, secret_base64);
|
| }
|
|
|
| bool RapporService::ExportMetrics(RapporReports* reports) {
|
|
|