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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Note that the act of instantiating the scheduler will start the fetch, if | 250 // Note that the act of instantiating the scheduler will start the fetch, if |
251 // the scheduler deems appropriate. Using Unretained is fine here since the | 251 // the scheduler deems appropriate. Using Unretained is fine here since the |
252 // lifespan of request_scheduler_ is guaranteed to be shorter than that of | 252 // lifespan of request_scheduler_ is guaranteed to be shorter than that of |
253 // this service. | 253 // this service. |
254 request_scheduler_.reset(VariationsRequestScheduler::Create( | 254 request_scheduler_.reset(VariationsRequestScheduler::Create( |
255 base::Bind(&VariationsService::FetchVariationsSeed, | 255 base::Bind(&VariationsService::FetchVariationsSeed, |
256 base::Unretained(this)), local_state_)); | 256 base::Unretained(this)), local_state_)); |
257 request_scheduler_->Start(); | 257 request_scheduler_->Start(); |
258 } | 258 } |
259 | 259 |
| 260 void VariationsService::ScheduleFetch() { |
| 261 request_scheduler_->ScheduleFetch(); |
| 262 } |
| 263 |
260 // static | 264 // static |
261 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { | 265 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { |
262 std::string server_url_string(CommandLine::ForCurrentProcess()-> | 266 std::string server_url_string(CommandLine::ForCurrentProcess()-> |
263 GetSwitchValueASCII(switches::kVariationsServerURL)); | 267 GetSwitchValueASCII(switches::kVariationsServerURL)); |
264 if (server_url_string.empty()) | 268 if (server_url_string.empty()) |
265 server_url_string = kDefaultVariationsServerURL; | 269 server_url_string = kDefaultVariationsServerURL; |
266 GURL server_url = GURL(server_url_string); | 270 GURL server_url = GURL(server_url_string); |
267 | 271 |
268 const std::string restrict_param = GetRestrictParameterPref(local_state); | 272 const std::string restrict_param = GetRestrictParameterPref(local_state); |
269 if (!restrict_param.empty()) { | 273 if (!restrict_param.empty()) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 if (request_status.status() != net::URLRequestStatus::SUCCESS) { | 372 if (request_status.status() != net::URLRequestStatus::SUCCESS) { |
369 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.FailedRequestErrorCode", | 373 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.FailedRequestErrorCode", |
370 -request_status.error()); | 374 -request_status.error()); |
371 DVLOG(1) << "Variations server request failed with error: " | 375 DVLOG(1) << "Variations server request failed with error: " |
372 << request_status.error() << ": " | 376 << request_status.error() << ": " |
373 << net::ErrorToString(request_status.error()); | 377 << net::ErrorToString(request_status.error()); |
374 // It's common for the very first fetch attempt to fail (e.g. the network | 378 // It's common for the very first fetch attempt to fail (e.g. the network |
375 // may not yet be available). In such a case, try again soon, rather than | 379 // may not yet be available). In such a case, try again soon, rather than |
376 // waiting the full time interval. | 380 // waiting the full time interval. |
377 if (is_first_request) | 381 if (is_first_request) |
378 request_scheduler_->ScheduleFetchShortly(); | 382 request_scheduler_->ForceFetch(); |
379 return; | 383 return; |
380 } | 384 } |
381 | 385 |
382 // Log the response code. | 386 // Log the response code. |
383 const int response_code = request->GetResponseCode(); | 387 const int response_code = request->GetResponseCode(); |
384 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.SeedFetchResponseCode", | 388 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.SeedFetchResponseCode", |
385 response_code); | 389 response_code); |
386 | 390 |
387 const base::TimeDelta latency = | 391 const base::TimeDelta latency = |
388 base::TimeTicks::Now() - last_request_started_time_; | 392 base::TimeTicks::Now() - last_request_started_time_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 452 |
449 void VariationsService::RecordLastFetchTime() { | 453 void VariationsService::RecordLastFetchTime() { |
450 // local_state_ is NULL in tests, so check it first. | 454 // local_state_ is NULL in tests, so check it first. |
451 if (local_state_) { | 455 if (local_state_) { |
452 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 456 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
453 base::Time::Now().ToInternalValue()); | 457 base::Time::Now().ToInternalValue()); |
454 } | 458 } |
455 } | 459 } |
456 | 460 |
457 } // namespace chrome_variations | 461 } // namespace chrome_variations |
OLD | NEW |