| OLD | NEW |
| 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 #include "chrome/browser/metrics/variations/variations_service.h" | 5 #include "chrome/browser/metrics/variations/variations_service.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 base::TimeDelta time_since_last_fetch; | 365 base::TimeDelta time_since_last_fetch; |
| 366 // Record a time delta of 0 (default value) if there was no previous fetch. | 366 // Record a time delta of 0 (default value) if there was no previous fetch. |
| 367 if (!last_request_started_time_.is_null()) | 367 if (!last_request_started_time_.is_null()) |
| 368 time_since_last_fetch = now - last_request_started_time_; | 368 time_since_last_fetch = now - last_request_started_time_; |
| 369 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.TimeSinceLastFetchAttempt", | 369 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.TimeSinceLastFetchAttempt", |
| 370 time_since_last_fetch.InMinutes(), 0, | 370 time_since_last_fetch.InMinutes(), 0, |
| 371 base::TimeDelta::FromDays(7).InMinutes(), 50); | 371 base::TimeDelta::FromDays(7).InMinutes(), 50); |
| 372 last_request_started_time_ = now; | 372 last_request_started_time_ = now; |
| 373 } | 373 } |
| 374 | 374 |
| 375 void VariationsService::StoreSeed(const std::string& seed_data, |
| 376 const std::string& seed_signature, |
| 377 const base::Time& date_fetched) { |
| 378 if (seed_store_.StoreSeedData(seed_data, seed_signature, date_fetched)) |
| 379 RecordLastFetchTime(); |
| 380 } |
| 381 |
| 375 void VariationsService::FetchVariationsSeed() { | 382 void VariationsService::FetchVariationsSeed() { |
| 376 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 377 | 384 |
| 378 const ResourceRequestAllowedNotifier::State state = | 385 const ResourceRequestAllowedNotifier::State state = |
| 379 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); | 386 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); |
| 380 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); | 387 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); |
| 381 if (state != ResourceRequestAllowedNotifier::ALLOWED) { | 388 if (state != ResourceRequestAllowedNotifier::ALLOWED) { |
| 382 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; | 389 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; |
| 383 return; | 390 return; |
| 384 } | 391 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 452 } |
| 446 | 453 |
| 447 std::string seed_data; | 454 std::string seed_data; |
| 448 bool success = request->GetResponseAsString(&seed_data); | 455 bool success = request->GetResponseAsString(&seed_data); |
| 449 DCHECK(success); | 456 DCHECK(success); |
| 450 | 457 |
| 451 std::string seed_signature; | 458 std::string seed_signature; |
| 452 request->GetResponseHeaders()->EnumerateHeader(NULL, | 459 request->GetResponseHeaders()->EnumerateHeader(NULL, |
| 453 "X-Seed-Signature", | 460 "X-Seed-Signature", |
| 454 &seed_signature); | 461 &seed_signature); |
| 455 if (seed_store_.StoreSeedData(seed_data, seed_signature, response_date)) | 462 StoreSeed(seed_data, seed_signature, response_date); |
| 456 RecordLastFetchTime(); | |
| 457 } | 463 } |
| 458 | 464 |
| 459 void VariationsService::OnResourceRequestsAllowed() { | 465 void VariationsService::OnResourceRequestsAllowed() { |
| 460 // Note that this only attempts to fetch the seed at most once per period | 466 // Note that this only attempts to fetch the seed at most once per period |
| 461 // (kSeedFetchPeriodHours). This works because | 467 // (kSeedFetchPeriodHours). This works because |
| 462 // |resource_request_allowed_notifier_| only calls this method if an | 468 // |resource_request_allowed_notifier_| only calls this method if an |
| 463 // attempt was made earlier that fails (which implies that the period had | 469 // attempt was made earlier that fails (which implies that the period had |
| 464 // elapsed). After a successful attempt is made, the notifier will know not | 470 // elapsed). After a successful attempt is made, the notifier will know not |
| 465 // to call this method again until another failed attempt occurs. | 471 // to call this method again until another failed attempt occurs. |
| 466 RecordRequestsAllowedHistogram(RESOURCE_REQUESTS_ALLOWED_NOTIFIED); | 472 RecordRequestsAllowedHistogram(RESOURCE_REQUESTS_ALLOWED_NOTIFIED); |
| 467 DVLOG(1) << "Retrying fetch."; | 473 DVLOG(1) << "Retrying fetch."; |
| 468 DoActualFetch(); | 474 DoActualFetch(); |
| 469 | 475 |
| 470 // This service must have created a scheduler in order for this to be called. | 476 // This service must have created a scheduler in order for this to be called. |
| 471 DCHECK(request_scheduler_.get()); | 477 DCHECK(request_scheduler_.get()); |
| 472 request_scheduler_->Reset(); | 478 request_scheduler_->Reset(); |
| 473 } | 479 } |
| 474 | 480 |
| 475 void VariationsService::RecordLastFetchTime() { | 481 void VariationsService::RecordLastFetchTime() { |
| 476 // local_state_ is NULL in tests, so check it first. | 482 // local_state_ is NULL in tests, so check it first. |
| 477 if (local_state_) { | 483 if (local_state_) { |
| 478 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 484 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
| 479 base::Time::Now().ToInternalValue()); | 485 base::Time::Now().ToInternalValue()); |
| 480 } | 486 } |
| 481 } | 487 } |
| 482 | 488 |
| 483 } // namespace chrome_variations | 489 } // namespace chrome_variations |
| OLD | NEW |