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..fe72e7d86541e562540f58a8788ee4aa486585eb 100644 |
| --- a/components/variations/service/variations_service.cc |
| +++ b/components/variations/service/variations_service.cc |
| @@ -842,12 +842,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, |
| + 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
|
| 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 +867,29 @@ std::string VariationsService::GetStoredPermanentCountry() { |
| return stored_country; |
| } |
| +bool VariationsService::ForceSetStoredPermanentCountry( |
| + 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 |