Chromium Code Reviews| Index: components/update_client/persisted_data.cc |
| diff --git a/components/update_client/persisted_data.cc b/components/update_client/persisted_data.cc |
| index 673ba1e6b16254a8bb9005a2141390bd5c4f637a..4d171ef3fef06a41d232d4c59eaf2b8dd724eac4 100644 |
| --- a/components/update_client/persisted_data.cc |
| +++ b/components/update_client/persisted_data.cc |
| @@ -72,6 +72,80 @@ void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids, |
| } |
| } |
| +std::string PersistedData::GetCohort(const std::string& id) const { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!pref_service_) |
| + return std::string(); |
| + std::string cohort; |
| + const base::DictionaryValue* dict = |
| + pref_service_->GetDictionary(kPersistedDataPreference); |
| + // We assume ids do not contain '.' characters. |
| + DCHECK_EQ(std::string::npos, id.find('.')); |
|
Sorin Jianu
2016/08/18 21:15:15
If the dcheck is a pre-condition for the argument
waffles
2016/08/18 22:29:23
Done.
|
| + if (!dict->GetString(base::StringPrintf("apps.%s.cohort", id.c_str()), |
| + &cohort)) |
| + return std::string(); |
| + return cohort; |
| +} |
| + |
| +std::string PersistedData::GetCohortName(const std::string& id) const { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
|
Sorin Jianu
2016/08/18 21:15:15
Is there a way to reduce dublication of code in th
waffles
2016/08/18 22:29:23
Done.
|
| + if (!pref_service_) |
| + return std::string(); |
| + std::string cohort_name; |
| + const base::DictionaryValue* dict = |
| + pref_service_->GetDictionary(kPersistedDataPreference); |
| + // We assume ids do not contain '.' characters. |
| + DCHECK_EQ(std::string::npos, id.find('.')); |
| + if (!dict->GetString(base::StringPrintf("apps.%s.cohortname", id.c_str()), |
| + &cohort_name)) |
| + return std::string(); |
| + return cohort_name; |
| +} |
| + |
| +std::string PersistedData::GetCohortHint(const std::string& id) const { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!pref_service_) |
| + return std::string(); |
| + std::string cohort_hint; |
| + const base::DictionaryValue* dict = |
| + pref_service_->GetDictionary(kPersistedDataPreference); |
| + // We assume ids do not contain '.' characters. |
| + DCHECK_EQ(std::string::npos, id.find('.')); |
| + if (!dict->GetString(base::StringPrintf("apps.%s.cohorthint", id.c_str()), |
| + &cohort_hint)) |
| + return std::string(); |
| + return cohort_hint; |
| +} |
| + |
| +void PersistedData::SetCohort(const std::string& id, |
| + const std::string& cohort) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!pref_service_) |
| + return; |
| + DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); |
| + update->SetString(base::StringPrintf("apps.%s.cohort", id.c_str()), cohort); |
| +} |
| + |
| +void PersistedData::SetCohortName(const std::string& id, |
| + const std::string& cohort_name) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!pref_service_) |
| + return; |
| + DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); |
| + update->SetString(base::StringPrintf("apps.%s.cohortname", id.c_str()), |
| + cohort_name); |
| +} |
| + |
| +void PersistedData::SetCohortHint(const std::string& id, |
| + const std::string& cohort_hint) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!pref_service_) |
| + return; |
| + DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); |
| + update->SetString(base::StringPrintf("apps.%s.cohorthint", id.c_str()), |
| + cohort_hint); |
| +} |
| + |
| void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) { |
| registry->RegisterDictionaryPref(kPersistedDataPreference); |
| } |