Chromium Code Reviews| 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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 if (!is_pref_valid) | 835 if (!is_pref_valid) |
| 836 local_state_->ClearPref(prefs::kVariationsPermanentConsistencyCountry); | 836 local_state_->ClearPref(prefs::kVariationsPermanentConsistencyCountry); |
| 837 // If we've never received a country code from the server, use an empty | 837 // 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 | 838 // 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 | 839 // countries, but so that it will pass any filters that specifically exclude |
| 840 // countries. | 840 // countries. |
| 841 return std::string(); | 841 return std::string(); |
| 842 } | 842 } |
| 843 | 843 |
| 844 // Otherwise, update the pref with the current Chrome version and country. | 844 // Otherwise, update the pref with the current Chrome version and country. |
| 845 base::ListValue new_list_value; | 845 SetStoredPermanentCountry(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; | 846 return latest_country; |
| 851 } | 847 } |
| 852 | 848 |
| 849 void VariationsService::SetStoredPermanentCountry(const base::Version& version, | |
| 850 const std::string& country) { | |
|
Alexei Svitkine (slow)
2016/04/20 21:46:44
Nit: Make this a free-standing function in an anon
hamelphi
2016/04/21 14:25:10
It needs to be a class method since we need access
| |
| 851 base::ListValue new_list_value; | |
| 852 new_list_value.AppendString(version.GetString()); | |
| 853 new_list_value.AppendString(country); | |
| 854 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | |
| 855 new_list_value); | |
| 856 } | |
| 857 | |
| 853 std::string VariationsService::GetStoredPermanentCountry() { | 858 std::string VariationsService::GetStoredPermanentCountry() { |
| 854 const base::ListValue* list_value = | 859 const base::ListValue* list_value = |
| 855 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); | 860 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); |
| 856 std::string stored_country; | 861 std::string stored_country; |
| 857 | 862 |
| 858 if (list_value->GetSize() == 2) { | 863 if (list_value->GetSize() == 2) { |
| 859 list_value->GetString(1, &stored_country); | 864 list_value->GetString(1, &stored_country); |
| 860 } | 865 } |
| 861 | 866 |
| 862 return stored_country; | 867 return stored_country; |
| 863 } | 868 } |
| 864 | 869 |
| 870 bool VariationsService::ForceSetStoredPermanentCountry( | |
| 871 const std::string& country_override) { | |
| 872 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 873 | |
| 874 if (country_override.empty()) | |
| 875 return false; | |
| 876 | |
| 877 const base::ListValue* list_value = | |
| 878 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); | |
| 879 | |
| 880 std::string stored_country; | |
| 881 const bool got_stored_country = | |
| 882 list_value->GetSize() == 2 && list_value->GetString(1, &stored_country); | |
| 883 | |
| 884 const bool needs_update = | |
| 885 !got_stored_country || stored_country != country_override; | |
| 886 | |
| 887 if (!needs_update) | |
| 888 return false; | |
| 889 | |
| 890 base::Version version(version_info::GetVersionNumber()); | |
| 891 SetStoredPermanentCountry(version, country_override); | |
| 892 return true; | |
| 893 } | |
| 894 | |
| 865 } // namespace variations | 895 } // namespace variations |
| OLD | NEW |