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

Side by Side 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: Don't serialize the attrs when they are empty. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/update_client/persisted_data.h" 5 #include "components/update_client/persisted_data.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); 65 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
66 for (auto id : ids) { 66 for (auto id : ids) {
67 // We assume ids do not contain '.' characters. 67 // We assume ids do not contain '.' characters.
68 DCHECK_EQ(std::string::npos, id.find('.')); 68 DCHECK_EQ(std::string::npos, id.find('.'));
69 update->SetInteger(base::StringPrintf("apps.%s.dlrc", id.c_str()), datenum); 69 update->SetInteger(base::StringPrintf("apps.%s.dlrc", id.c_str()), datenum);
70 update->SetString(base::StringPrintf("apps.%s.pf", id.c_str()), 70 update->SetString(base::StringPrintf("apps.%s.pf", id.c_str()),
71 base::GenerateGUID()); 71 base::GenerateGUID());
72 } 72 }
73 } 73 }
74 74
75 std::string PersistedData::GetCohort(const std::string& id) const {
76 DCHECK(thread_checker_.CalledOnValidThread());
77 if (!pref_service_)
78 return std::string();
79 std::string cohort;
80 const base::DictionaryValue* dict =
81 pref_service_->GetDictionary(kPersistedDataPreference);
82 // We assume ids do not contain '.' characters.
83 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.
84 if (!dict->GetString(base::StringPrintf("apps.%s.cohort", id.c_str()),
85 &cohort))
86 return std::string();
87 return cohort;
88 }
89
90 std::string PersistedData::GetCohortName(const std::string& id) const {
91 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.
92 if (!pref_service_)
93 return std::string();
94 std::string cohort_name;
95 const base::DictionaryValue* dict =
96 pref_service_->GetDictionary(kPersistedDataPreference);
97 // We assume ids do not contain '.' characters.
98 DCHECK_EQ(std::string::npos, id.find('.'));
99 if (!dict->GetString(base::StringPrintf("apps.%s.cohortname", id.c_str()),
100 &cohort_name))
101 return std::string();
102 return cohort_name;
103 }
104
105 std::string PersistedData::GetCohortHint(const std::string& id) const {
106 DCHECK(thread_checker_.CalledOnValidThread());
107 if (!pref_service_)
108 return std::string();
109 std::string cohort_hint;
110 const base::DictionaryValue* dict =
111 pref_service_->GetDictionary(kPersistedDataPreference);
112 // We assume ids do not contain '.' characters.
113 DCHECK_EQ(std::string::npos, id.find('.'));
114 if (!dict->GetString(base::StringPrintf("apps.%s.cohorthint", id.c_str()),
115 &cohort_hint))
116 return std::string();
117 return cohort_hint;
118 }
119
120 void PersistedData::SetCohort(const std::string& id,
121 const std::string& cohort) {
122 DCHECK(thread_checker_.CalledOnValidThread());
123 if (!pref_service_)
124 return;
125 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
126 update->SetString(base::StringPrintf("apps.%s.cohort", id.c_str()), cohort);
127 }
128
129 void PersistedData::SetCohortName(const std::string& id,
130 const std::string& cohort_name) {
131 DCHECK(thread_checker_.CalledOnValidThread());
132 if (!pref_service_)
133 return;
134 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
135 update->SetString(base::StringPrintf("apps.%s.cohortname", id.c_str()),
136 cohort_name);
137 }
138
139 void PersistedData::SetCohortHint(const std::string& id,
140 const std::string& cohort_hint) {
141 DCHECK(thread_checker_.CalledOnValidThread());
142 if (!pref_service_)
143 return;
144 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
145 update->SetString(base::StringPrintf("apps.%s.cohorthint", id.c_str()),
146 cohort_hint);
147 }
148
75 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) { 149 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) {
76 registry->RegisterDictionaryPref(kPersistedDataPreference); 150 registry->RegisterDictionaryPref(kPersistedDataPreference);
77 } 151 }
78 152
79 } // namespace update_client 153 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698