Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: components/update_client/persisted_data.cc

Issue 2252093002: Add support for Omaha cohorts to the component updater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/update_client/persisted_data.h ('k') | components/update_client/persisted_data_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4f2c34a46303fd57ae3c707277245a890b6109f4 100644
--- a/components/update_client/persisted_data.cc
+++ b/components/update_client/persisted_data.cc
@@ -28,33 +28,62 @@ PersistedData::~PersistedData() {
DCHECK(thread_checker_.CalledOnValidThread());
}
-int PersistedData::GetDateLastRollCall(const std::string& id) const {
+int PersistedData::GetInt(const std::string& id,
+ const std::string& key,
+ int fallback) const {
DCHECK(thread_checker_.CalledOnValidThread());
+ // We assume ids do not contain '.' characters.
+ DCHECK_EQ(std::string::npos, id.find('.'));
if (!pref_service_)
- return kDateLastRollCallUnknown;
- int dlrc = kDateLastRollCallUnknown;
+ return fallback;
const base::DictionaryValue* dict =
pref_service_->GetDictionary(kPersistedDataPreference);
- // We assume ids do not contain '.' characters.
- DCHECK_EQ(std::string::npos, id.find('.'));
- if (!dict->GetInteger(base::StringPrintf("apps.%s.dlrc", id.c_str()), &dlrc))
- return kDateLastRollCallUnknown;
- return dlrc;
+ if (!dict)
+ return fallback;
+ int result = 0;
+ return dict->GetInteger(
+ base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()), &result)
+ ? result
+ : fallback;
}
-std::string PersistedData::GetPingFreshness(const std::string& id) const {
+std::string PersistedData::GetString(const std::string& id,
+ const std::string& key) const {
DCHECK(thread_checker_.CalledOnValidThread());
+ // We assume ids do not contain '.' characters.
+ DCHECK_EQ(std::string::npos, id.find('.'));
if (!pref_service_)
return std::string();
- std::string freshness;
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.pf", id.c_str()),
- &freshness))
+ if (!dict)
return std::string();
- return base::StringPrintf("{%s}", freshness.c_str());
+ std::string result;
+ return dict->GetString(
+ base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()), &result)
+ ? result
+ : std::string();
+}
+
+int PersistedData::GetDateLastRollCall(const std::string& id) const {
+ return GetInt(id, "dlrc", kDateLastRollCallUnknown);
+}
+
+std::string PersistedData::GetPingFreshness(const std::string& id) const {
+ std::string result = GetString(id, "pf");
+ return !result.empty() ? base::StringPrintf("{%s}", result.c_str()) : result;
+}
+
+std::string PersistedData::GetCohort(const std::string& id) const {
+ return GetString(id, "cohort");
+}
+
+std::string PersistedData::GetCohortName(const std::string& id) const {
+ return GetString(id, "cohortname");
+}
+
+std::string PersistedData::GetCohortHint(const std::string& id) const {
+ return GetString(id, "cohorthint");
}
void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
@@ -72,6 +101,32 @@ void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
}
}
+void PersistedData::SetString(const std::string& id,
+ const std::string& key,
+ const std::string& value) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!pref_service_)
+ return;
+ DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
+ update->SetString(base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()),
+ value);
+}
+
+void PersistedData::SetCohort(const std::string& id,
+ const std::string& cohort) {
+ SetString(id, "cohort", cohort);
+}
+
+void PersistedData::SetCohortName(const std::string& id,
+ const std::string& cohort_name) {
+ SetString(id, "cohortname", cohort_name);
+}
+
+void PersistedData::SetCohortHint(const std::string& id,
+ const std::string& cohort_hint) {
+ SetString(id, "cohorthint", cohort_hint);
+}
+
void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kPersistedDataPreference);
}
« no previous file with comments | « components/update_client/persisted_data.h ('k') | components/update_client/persisted_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698