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 // TODO(rkaplow): Handle this and the similar event in metrics_service by | |
261 // observing an 'OnAppEnterForeground' event instead of requiring the frontend | |
262 // code to notify each service individually. | |
Alexei Svitkine (slow)
2014/02/13 16:13:08
My previous comment meant to emphasize that in the
rkaplow
2014/02/13 16:55:59
Done.
| |
263 void VariationsService::OnAppEnterForeground() { | |
264 request_scheduler_->ScheduleFetch(); | |
265 } | |
266 | |
260 // static | 267 // static |
261 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { | 268 GURL VariationsService::GetVariationsServerURL(PrefService* local_state) { |
262 std::string server_url_string(CommandLine::ForCurrentProcess()-> | 269 std::string server_url_string(CommandLine::ForCurrentProcess()-> |
263 GetSwitchValueASCII(switches::kVariationsServerURL)); | 270 GetSwitchValueASCII(switches::kVariationsServerURL)); |
264 if (server_url_string.empty()) | 271 if (server_url_string.empty()) |
265 server_url_string = kDefaultVariationsServerURL; | 272 server_url_string = kDefaultVariationsServerURL; |
266 GURL server_url = GURL(server_url_string); | 273 GURL server_url = GURL(server_url_string); |
267 | 274 |
268 const std::string restrict_param = GetRestrictParameterPref(local_state); | 275 const std::string restrict_param = GetRestrictParameterPref(local_state); |
269 if (!restrict_param.empty()) { | 276 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) { | 375 if (request_status.status() != net::URLRequestStatus::SUCCESS) { |
369 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.FailedRequestErrorCode", | 376 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.FailedRequestErrorCode", |
370 -request_status.error()); | 377 -request_status.error()); |
371 DVLOG(1) << "Variations server request failed with error: " | 378 DVLOG(1) << "Variations server request failed with error: " |
372 << request_status.error() << ": " | 379 << request_status.error() << ": " |
373 << net::ErrorToString(request_status.error()); | 380 << net::ErrorToString(request_status.error()); |
374 // It's common for the very first fetch attempt to fail (e.g. the network | 381 // 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 | 382 // may not yet be available). In such a case, try again soon, rather than |
376 // waiting the full time interval. | 383 // waiting the full time interval. |
377 if (is_first_request) | 384 if (is_first_request) |
378 request_scheduler_->ScheduleFetchShortly(); | 385 request_scheduler_->ForceFetch(); |
379 return; | 386 return; |
380 } | 387 } |
381 | 388 |
382 // Log the response code. | 389 // Log the response code. |
383 const int response_code = request->GetResponseCode(); | 390 const int response_code = request->GetResponseCode(); |
384 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.SeedFetchResponseCode", | 391 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.SeedFetchResponseCode", |
385 response_code); | 392 response_code); |
386 | 393 |
387 const base::TimeDelta latency = | 394 const base::TimeDelta latency = |
388 base::TimeTicks::Now() - last_request_started_time_; | 395 base::TimeTicks::Now() - last_request_started_time_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 | 455 |
449 void VariationsService::RecordLastFetchTime() { | 456 void VariationsService::RecordLastFetchTime() { |
450 // local_state_ is NULL in tests, so check it first. | 457 // local_state_ is NULL in tests, so check it first. |
451 if (local_state_) { | 458 if (local_state_) { |
452 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 459 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
453 base::Time::Now().ToInternalValue()); | 460 base::Time::Now().ToInternalValue()); |
454 } | 461 } |
455 } | 462 } |
456 | 463 |
457 } // namespace chrome_variations | 464 } // namespace chrome_variations |
OLD | NEW |