Chromium Code Reviews| Index: components/variations/service/variations_service.cc |
| diff --git a/components/variations/service/variations_service.cc b/components/variations/service/variations_service.cc |
| index 9e0c4c75134475d3c52a05a06922c2ff01668938..a510d37bad768bfa11034d174e33e73f8b6585b3 100644 |
| --- a/components/variations/service/variations_service.cc |
| +++ b/components/variations/service/variations_service.cc |
| @@ -31,7 +31,6 @@ |
| #include "components/variations/variations_seed_simulator.h" |
| #include "components/variations/variations_switches.h" |
| #include "components/variations/variations_url_constants.h" |
| -#include "components/version_info/version_info.h" |
| #include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/network_change_notifier.h" |
| @@ -842,12 +841,17 @@ std::string VariationsService::LoadPermanentConsistencyCountry( |
| } |
| // Otherwise, update the pref with the current Chrome version and country. |
| + SetStoredPermanentCountry(version, latest_country); |
| + return latest_country; |
| +} |
| + |
| +void VariationsService::SetStoredPermanentCountry(const base::Version& version, |
|
Alexei Svitkine (slow)
2016/04/21 15:21:21
Nit: SetStored -> Store
hamelphi
2016/04/21 21:14:44
Done.
|
| + const std::string& country) { |
| base::ListValue new_list_value; |
| new_list_value.AppendString(version.GetString()); |
| - new_list_value.AppendString(latest_country); |
| + new_list_value.AppendString(country); |
| local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
| new_list_value); |
| - return latest_country; |
| } |
| std::string VariationsService::GetStoredPermanentCountry() { |
| @@ -862,4 +866,29 @@ std::string VariationsService::GetStoredPermanentCountry() { |
| return stored_country; |
| } |
| +bool VariationsService::ForceSetStoredPermanentCountry( |
|
Alexei Svitkine (slow)
2016/04/21 15:21:21
Nit: How about OverrideStoredPermanentCountry
hamelphi
2016/04/21 21:14:44
Done.
|
| + const std::string& country_override) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + if (country_override.empty()) |
| + return false; |
| + |
| + const base::ListValue* list_value = |
| + local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); |
| + |
| + std::string stored_country; |
| + const bool got_stored_country = |
| + list_value->GetSize() == 2 && list_value->GetString(1, &stored_country); |
| + |
| + const bool needs_update = |
| + !got_stored_country || stored_country != country_override; |
| + |
| + if (!needs_update) |
| + return false; |
| + |
| + base::Version version(version_info::GetVersionNumber()); |
| + SetStoredPermanentCountry(version, country_override); |
| + return true; |
| +} |
| + |
| } // namespace variations |