| 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 "components/variations/service/variations_service.h" | 5 #include "components/variations/service/variations_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "components/network_time/network_time_tracker.h" | 24 #include "components/network_time/network_time_tracker.h" |
| 25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 26 #include "components/prefs/pref_registry_simple.h" | 26 #include "components/prefs/pref_registry_simple.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "components/variations/pref_names.h" | 28 #include "components/variations/pref_names.h" |
| 29 #include "components/variations/proto/variations_seed.pb.h" | 29 #include "components/variations/proto/variations_seed.pb.h" |
| 30 #include "components/variations/variations_seed_processor.h" | 30 #include "components/variations/variations_seed_processor.h" |
| 31 #include "components/variations/variations_seed_simulator.h" | 31 #include "components/variations/variations_seed_simulator.h" |
| 32 #include "components/variations/variations_switches.h" | 32 #include "components/variations/variations_switches.h" |
| 33 #include "components/variations/variations_url_constants.h" | 33 #include "components/variations/variations_url_constants.h" |
| 34 #include "components/version_info/version_info.h" | |
| 35 #include "net/base/load_flags.h" | 34 #include "net/base/load_flags.h" |
| 36 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 37 #include "net/base/network_change_notifier.h" | 36 #include "net/base/network_change_notifier.h" |
| 38 #include "net/base/url_util.h" | 37 #include "net/base/url_util.h" |
| 39 #include "net/http/http_response_headers.h" | 38 #include "net/http/http_response_headers.h" |
| 40 #include "net/http/http_status_code.h" | 39 #include "net/http/http_status_code.h" |
| 41 #include "net/http/http_util.h" | 40 #include "net/http/http_util.h" |
| 42 #include "net/url_request/url_fetcher.h" | 41 #include "net/url_request/url_fetcher.h" |
| 43 #include "net/url_request/url_request_status.h" | 42 #include "net/url_request/url_request_status.h" |
| 44 #include "ui/base/device_form_factor.h" | 43 #include "ui/base/device_form_factor.h" |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 if (!is_pref_valid) | 834 if (!is_pref_valid) |
| 836 local_state_->ClearPref(prefs::kVariationsPermanentConsistencyCountry); | 835 local_state_->ClearPref(prefs::kVariationsPermanentConsistencyCountry); |
| 837 // If we've never received a country code from the server, use an empty | 836 // If we've never received a country code from the server, use an empty |
| 838 // country so that it won't pass any filters that specifically include | 837 // country so that it won't pass any filters that specifically include |
| 839 // countries, but so that it will pass any filters that specifically exclude | 838 // countries, but so that it will pass any filters that specifically exclude |
| 840 // countries. | 839 // countries. |
| 841 return std::string(); | 840 return std::string(); |
| 842 } | 841 } |
| 843 | 842 |
| 844 // Otherwise, update the pref with the current Chrome version and country. | 843 // Otherwise, update the pref with the current Chrome version and country. |
| 845 base::ListValue new_list_value; | 844 StorePermanentCountry(version, latest_country); |
| 846 new_list_value.AppendString(version.GetString()); | |
| 847 new_list_value.AppendString(latest_country); | |
| 848 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | |
| 849 new_list_value); | |
| 850 return latest_country; | 845 return latest_country; |
| 851 } | 846 } |
| 852 | 847 |
| 848 void VariationsService::StorePermanentCountry(const base::Version& version, |
| 849 const std::string& country) { |
| 850 base::ListValue new_list_value; |
| 851 new_list_value.AppendString(version.GetString()); |
| 852 new_list_value.AppendString(country); |
| 853 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
| 854 new_list_value); |
| 855 } |
| 856 |
| 853 std::string VariationsService::GetStoredPermanentCountry() { | 857 std::string VariationsService::GetStoredPermanentCountry() { |
| 854 const base::ListValue* list_value = | 858 const base::ListValue* list_value = |
| 855 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); | 859 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); |
| 856 std::string stored_country; | 860 std::string stored_country; |
| 857 | 861 |
| 858 if (list_value->GetSize() == 2) { | 862 if (list_value->GetSize() == 2) { |
| 859 list_value->GetString(1, &stored_country); | 863 list_value->GetString(1, &stored_country); |
| 860 } | 864 } |
| 861 | 865 |
| 862 return stored_country; | 866 return stored_country; |
| 863 } | 867 } |
| 864 | 868 |
| 869 bool VariationsService::OverrideStoredPermanentCountry( |
| 870 const std::string& country_override) { |
| 871 DCHECK(thread_checker_.CalledOnValidThread()); |
| 872 |
| 873 if (country_override.empty()) |
| 874 return false; |
| 875 |
| 876 const base::ListValue* list_value = |
| 877 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); |
| 878 |
| 879 std::string stored_country; |
| 880 const bool got_stored_country = |
| 881 list_value->GetSize() == 2 && list_value->GetString(1, &stored_country); |
| 882 |
| 883 if (got_stored_country && stored_country == country_override) |
| 884 return false; |
| 885 |
| 886 base::Version version(version_info::GetVersionNumber()); |
| 887 StorePermanentCountry(version, country_override); |
| 888 return true; |
| 889 } |
| 890 |
| 865 } // namespace variations | 891 } // namespace variations |
| OLD | NEW |