| 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/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/build_time.h" | 10 #include "base/build_time.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/sha1.h" | 17 #include "base/sha1.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/version.h" | 19 #include "base/version.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/network_time/network_time_tracker.h" | 21 #include "chrome/browser/network_time/network_time_tracker.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/metrics/variations/variations_util.h" | 23 #include "chrome/common/metrics/variations/variations_util.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "components/variations/proto/variations_seed.pb.h" | 25 #include "components/variations/proto/variations_seed.pb.h" |
| 26 #include "components/variations/variations_seed_processor.h" | 26 #include "components/variations/variations_seed_processor.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/common/url_fetcher.h" | |
| 29 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 30 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 31 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
| 32 #include "net/base/url_util.h" | 31 #include "net/base/url_util.h" |
| 33 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 34 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 35 #include "net/http/http_util.h" | 34 #include "net/http/http_util.h" |
| 36 #include "net/url_request/url_fetcher.h" | 35 #include "net/url_request/url_fetcher.h" |
| 37 #include "net/url_request/url_request_status.h" | 36 #include "net/url_request/url_request_status.h" |
| 38 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 latency); | 390 latency); |
| 392 } | 391 } |
| 393 } | 392 } |
| 394 | 393 |
| 395 if (response_code != net::HTTP_OK) { | 394 if (response_code != net::HTTP_OK) { |
| 396 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " | 395 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " |
| 397 << response_code; | 396 << response_code; |
| 398 if (response_code == net::HTTP_NOT_MODIFIED) { | 397 if (response_code == net::HTTP_NOT_MODIFIED) { |
| 399 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); | 398 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); |
| 400 RecordLastFetchTime(); | 399 RecordLastFetchTime(); |
| 400 // Update the seed date value in local state (used for expiry check on |
| 401 // next start up), since 304 is a successful response. |
| 402 local_state_->SetInt64(prefs::kVariationsSeedDate, |
| 403 response_date.ToInternalValue()); |
| 401 } else { | 404 } else { |
| 402 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); | 405 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
| 403 } | 406 } |
| 404 return; | 407 return; |
| 405 } | 408 } |
| 406 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); | 409 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); |
| 407 | 410 |
| 408 std::string seed_data; | 411 std::string seed_data; |
| 409 bool success = request->GetResponseAsString(&seed_data); | 412 bool success = request->GetResponseAsString(&seed_data); |
| 410 DCHECK(success); | 413 DCHECK(success); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 494 |
| 492 void VariationsService::RecordLastFetchTime() { | 495 void VariationsService::RecordLastFetchTime() { |
| 493 // local_state_ is NULL in tests, so check it first. | 496 // local_state_ is NULL in tests, so check it first. |
| 494 if (local_state_) { | 497 if (local_state_) { |
| 495 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 498 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
| 496 base::Time::Now().ToInternalValue()); | 499 base::Time::Now().ToInternalValue()); |
| 497 } | 500 } |
| 498 } | 501 } |
| 499 | 502 |
| 500 } // namespace chrome_variations | 503 } // namespace chrome_variations |
| OLD | NEW |