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

Side by Side Diff: rlz/chromeos/lib/rlz_value_store_chromeos.cc

Issue 2914523003: Deprecate NonThreadSafe in rlz in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « rlz/chromeos/lib/rlz_value_store_chromeos.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "rlz/chromeos/lib/rlz_value_store_chromeos.h" 5 #include "rlz/chromeos/lib/rlz_value_store_chromeos.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/important_file_writer.h" 9 #include "base/files/important_file_writer.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } // namespace 82 } // namespace
83 83
84 RlzValueStoreChromeOS::RlzValueStoreChromeOS(const base::FilePath& store_path) 84 RlzValueStoreChromeOS::RlzValueStoreChromeOS(const base::FilePath& store_path)
85 : rlz_store_(new base::DictionaryValue), 85 : rlz_store_(new base::DictionaryValue),
86 store_path_(store_path), 86 store_path_(store_path),
87 read_only_(true) { 87 read_only_(true) {
88 ReadStore(); 88 ReadStore();
89 } 89 }
90 90
91 RlzValueStoreChromeOS::~RlzValueStoreChromeOS() { 91 RlzValueStoreChromeOS::~RlzValueStoreChromeOS() {
92 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
92 WriteStore(); 93 WriteStore();
93 } 94 }
94 95
95 bool RlzValueStoreChromeOS::HasAccess(AccessType type) { 96 bool RlzValueStoreChromeOS::HasAccess(AccessType type) {
96 DCHECK(CalledOnValidThread()); 97 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
97 return type == kReadAccess || !read_only_; 98 return type == kReadAccess || !read_only_;
98 } 99 }
99 100
100 bool RlzValueStoreChromeOS::WritePingTime(Product product, int64_t time) { 101 bool RlzValueStoreChromeOS::WritePingTime(Product product, int64_t time) {
101 DCHECK(CalledOnValidThread()); 102 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
102 rlz_store_->SetString(GetKeyName(kPingTimeKey, product), 103 rlz_store_->SetString(GetKeyName(kPingTimeKey, product),
103 base::Int64ToString(time)); 104 base::Int64ToString(time));
104 return true; 105 return true;
105 } 106 }
106 107
107 bool RlzValueStoreChromeOS::ReadPingTime(Product product, int64_t* time) { 108 bool RlzValueStoreChromeOS::ReadPingTime(Product product, int64_t* time) {
108 DCHECK(CalledOnValidThread()); 109 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
109 std::string ping_time; 110 std::string ping_time;
110 return rlz_store_->GetString(GetKeyName(kPingTimeKey, product), &ping_time) && 111 return rlz_store_->GetString(GetKeyName(kPingTimeKey, product), &ping_time) &&
111 base::StringToInt64(ping_time, time); 112 base::StringToInt64(ping_time, time);
112 } 113 }
113 114
114 bool RlzValueStoreChromeOS::ClearPingTime(Product product) { 115 bool RlzValueStoreChromeOS::ClearPingTime(Product product) {
115 DCHECK(CalledOnValidThread()); 116 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
116 rlz_store_->Remove(GetKeyName(kPingTimeKey, product), NULL); 117 rlz_store_->Remove(GetKeyName(kPingTimeKey, product), NULL);
117 return true; 118 return true;
118 } 119 }
119 120
120 bool RlzValueStoreChromeOS::WriteAccessPointRlz(AccessPoint access_point, 121 bool RlzValueStoreChromeOS::WriteAccessPointRlz(AccessPoint access_point,
121 const char* new_rlz) { 122 const char* new_rlz) {
122 DCHECK(CalledOnValidThread()); 123 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
123 rlz_store_->SetString( 124 rlz_store_->SetString(
124 GetKeyName(kAccessPointKey, access_point), new_rlz); 125 GetKeyName(kAccessPointKey, access_point), new_rlz);
125 return true; 126 return true;
126 } 127 }
127 128
128 bool RlzValueStoreChromeOS::ReadAccessPointRlz(AccessPoint access_point, 129 bool RlzValueStoreChromeOS::ReadAccessPointRlz(AccessPoint access_point,
129 char* rlz, 130 char* rlz,
130 size_t rlz_size) { 131 size_t rlz_size) {
131 DCHECK(CalledOnValidThread()); 132 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
132 std::string rlz_value; 133 std::string rlz_value;
133 rlz_store_->GetString(GetKeyName(kAccessPointKey, access_point), &rlz_value); 134 rlz_store_->GetString(GetKeyName(kAccessPointKey, access_point), &rlz_value);
134 if (rlz_value.size() < rlz_size) { 135 if (rlz_value.size() < rlz_size) {
135 strncpy(rlz, rlz_value.c_str(), rlz_size); 136 strncpy(rlz, rlz_value.c_str(), rlz_size);
136 return true; 137 return true;
137 } 138 }
138 if (rlz_size > 0) 139 if (rlz_size > 0)
139 *rlz = '\0'; 140 *rlz = '\0';
140 return false; 141 return false;
141 } 142 }
142 143
143 bool RlzValueStoreChromeOS::ClearAccessPointRlz(AccessPoint access_point) { 144 bool RlzValueStoreChromeOS::ClearAccessPointRlz(AccessPoint access_point) {
144 DCHECK(CalledOnValidThread()); 145 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
145 rlz_store_->Remove(GetKeyName(kAccessPointKey, access_point), NULL); 146 rlz_store_->Remove(GetKeyName(kAccessPointKey, access_point), NULL);
146 return true; 147 return true;
147 } 148 }
148 149
149 bool RlzValueStoreChromeOS::AddProductEvent(Product product, 150 bool RlzValueStoreChromeOS::AddProductEvent(Product product,
150 const char* event_rlz) { 151 const char* event_rlz) {
151 DCHECK(CalledOnValidThread()); 152 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
152 return AddValueToList(GetKeyName(kProductEventKey, product), 153 return AddValueToList(GetKeyName(kProductEventKey, product),
153 base::MakeUnique<base::Value>(event_rlz)); 154 base::MakeUnique<base::Value>(event_rlz));
154 } 155 }
155 156
156 bool RlzValueStoreChromeOS::ReadProductEvents( 157 bool RlzValueStoreChromeOS::ReadProductEvents(
157 Product product, 158 Product product,
158 std::vector<std::string>* events) { 159 std::vector<std::string>* events) {
159 DCHECK(CalledOnValidThread()); 160 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
160 base::ListValue* events_list = nullptr; 161 base::ListValue* events_list = nullptr;
161 if (!rlz_store_->GetList(GetKeyName(kProductEventKey, product), &events_list)) 162 if (!rlz_store_->GetList(GetKeyName(kProductEventKey, product), &events_list))
162 return false; 163 return false;
163 events->clear(); 164 events->clear();
164 for (size_t i = 0; i < events_list->GetSize(); ++i) { 165 for (size_t i = 0; i < events_list->GetSize(); ++i) {
165 std::string event; 166 std::string event;
166 if (events_list->GetString(i, &event)) 167 if (events_list->GetString(i, &event))
167 events->push_back(event); 168 events->push_back(event);
168 } 169 }
169 return true; 170 return true;
170 } 171 }
171 172
172 bool RlzValueStoreChromeOS::ClearProductEvent(Product product, 173 bool RlzValueStoreChromeOS::ClearProductEvent(Product product,
173 const char* event_rlz) { 174 const char* event_rlz) {
174 DCHECK(CalledOnValidThread()); 175 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
175 base::Value event_value(event_rlz); 176 base::Value event_value(event_rlz);
176 return RemoveValueFromList(GetKeyName(kProductEventKey, product), 177 return RemoveValueFromList(GetKeyName(kProductEventKey, product),
177 event_value); 178 event_value);
178 } 179 }
179 180
180 bool RlzValueStoreChromeOS::ClearAllProductEvents(Product product) { 181 bool RlzValueStoreChromeOS::ClearAllProductEvents(Product product) {
181 DCHECK(CalledOnValidThread()); 182 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
182 rlz_store_->Remove(GetKeyName(kProductEventKey, product), NULL); 183 rlz_store_->Remove(GetKeyName(kProductEventKey, product), NULL);
183 return true; 184 return true;
184 } 185 }
185 186
186 bool RlzValueStoreChromeOS::AddStatefulEvent(Product product, 187 bool RlzValueStoreChromeOS::AddStatefulEvent(Product product,
187 const char* event_rlz) { 188 const char* event_rlz) {
188 DCHECK(CalledOnValidThread()); 189 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
189 return AddValueToList(GetKeyName(kStatefulEventKey, product), 190 return AddValueToList(GetKeyName(kStatefulEventKey, product),
190 base::MakeUnique<base::Value>(event_rlz)); 191 base::MakeUnique<base::Value>(event_rlz));
191 } 192 }
192 193
193 bool RlzValueStoreChromeOS::IsStatefulEvent(Product product, 194 bool RlzValueStoreChromeOS::IsStatefulEvent(Product product,
194 const char* event_rlz) { 195 const char* event_rlz) {
195 DCHECK(CalledOnValidThread()); 196 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
196 base::Value event_value(event_rlz); 197 base::Value event_value(event_rlz);
197 base::ListValue* events_list = NULL; 198 base::ListValue* events_list = NULL;
198 return rlz_store_->GetList(GetKeyName(kStatefulEventKey, product), 199 return rlz_store_->GetList(GetKeyName(kStatefulEventKey, product),
199 &events_list) && 200 &events_list) &&
200 events_list->Find(event_value) != events_list->end(); 201 events_list->Find(event_value) != events_list->end();
201 } 202 }
202 203
203 bool RlzValueStoreChromeOS::ClearAllStatefulEvents(Product product) { 204 bool RlzValueStoreChromeOS::ClearAllStatefulEvents(Product product) {
204 DCHECK(CalledOnValidThread()); 205 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
205 rlz_store_->Remove(GetKeyName(kStatefulEventKey, product), NULL); 206 rlz_store_->Remove(GetKeyName(kStatefulEventKey, product), NULL);
206 return true; 207 return true;
207 } 208 }
208 209
209 void RlzValueStoreChromeOS::CollectGarbage() { 210 void RlzValueStoreChromeOS::CollectGarbage() {
210 DCHECK(CalledOnValidThread()); 211 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
211 NOTIMPLEMENTED(); 212 NOTIMPLEMENTED();
212 } 213 }
213 214
214 void RlzValueStoreChromeOS::ReadStore() { 215 void RlzValueStoreChromeOS::ReadStore() {
215 int error_code = 0; 216 int error_code = 0;
216 std::string error_msg; 217 std::string error_msg;
217 JSONFileValueDeserializer deserializer(store_path_); 218 JSONFileValueDeserializer deserializer(store_path_);
218 std::unique_ptr<base::Value> value = 219 std::unique_ptr<base::Value> value =
219 deserializer.Deserialize(&error_code, &error_msg); 220 deserializer.Deserialize(&error_code, &error_msg);
220 switch (error_code) { 221 switch (error_code) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 g_testing_rlz_store_path.Get() = directory; 337 g_testing_rlz_store_path.Get() = directory;
337 } 338 }
338 339
339 std::string RlzStoreFilenameStr() { 340 std::string RlzStoreFilenameStr() {
340 return GetRlzStorePath().value(); 341 return GetRlzStorePath().value();
341 } 342 }
342 343
343 } // namespace testing 344 } // namespace testing
344 345
345 } // namespace rlz_lib 346 } // namespace rlz_lib
OLDNEW
« no previous file with comments | « rlz/chromeos/lib/rlz_value_store_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698