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

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

Issue 2336863003: Change more base::ListValue methods to use std::unique_ptr. (Closed)
Patch Set: . Created 4 years, 3 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"
11 #include "base/json/json_string_value_serializer.h" 11 #include "base/json/json_string_value_serializer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "rlz/lib/lib_values.h" 18 #include "rlz/lib/lib_values.h"
18 #include "rlz/lib/recursive_cross_process_lock_posix.h" 19 #include "rlz/lib/recursive_cross_process_lock_posix.h"
19 #include "rlz/lib/rlz_lib.h" 20 #include "rlz/lib/rlz_lib.h"
20 21
21 namespace rlz_lib { 22 namespace rlz_lib {
22 23
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bool RlzValueStoreChromeOS::ClearAccessPointRlz(AccessPoint access_point) { 141 bool RlzValueStoreChromeOS::ClearAccessPointRlz(AccessPoint access_point) {
141 DCHECK(CalledOnValidThread()); 142 DCHECK(CalledOnValidThread());
142 rlz_store_->Remove(GetKeyName(kAccessPointKey, access_point), NULL); 143 rlz_store_->Remove(GetKeyName(kAccessPointKey, access_point), NULL);
143 return true; 144 return true;
144 } 145 }
145 146
146 bool RlzValueStoreChromeOS::AddProductEvent(Product product, 147 bool RlzValueStoreChromeOS::AddProductEvent(Product product,
147 const char* event_rlz) { 148 const char* event_rlz) {
148 DCHECK(CalledOnValidThread()); 149 DCHECK(CalledOnValidThread());
149 return AddValueToList(GetKeyName(kProductEventKey, product), 150 return AddValueToList(GetKeyName(kProductEventKey, product),
150 new base::StringValue(event_rlz)); 151 base::MakeUnique<base::StringValue>(event_rlz));
151 } 152 }
152 153
153 bool RlzValueStoreChromeOS::ReadProductEvents( 154 bool RlzValueStoreChromeOS::ReadProductEvents(
154 Product product, 155 Product product,
155 std::vector<std::string>* events) { 156 std::vector<std::string>* events) {
156 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
157 base::ListValue* events_list = NULL; ; 158 base::ListValue* events_list = NULL; ;
158 if (!rlz_store_->GetList(GetKeyName(kProductEventKey, product), &events_list)) 159 if (!rlz_store_->GetList(GetKeyName(kProductEventKey, product), &events_list))
159 return false; 160 return false;
160 events->clear(); 161 events->clear();
(...skipping 16 matching lines...) Expand all
177 bool RlzValueStoreChromeOS::ClearAllProductEvents(Product product) { 178 bool RlzValueStoreChromeOS::ClearAllProductEvents(Product product) {
178 DCHECK(CalledOnValidThread()); 179 DCHECK(CalledOnValidThread());
179 rlz_store_->Remove(GetKeyName(kProductEventKey, product), NULL); 180 rlz_store_->Remove(GetKeyName(kProductEventKey, product), NULL);
180 return true; 181 return true;
181 } 182 }
182 183
183 bool RlzValueStoreChromeOS::AddStatefulEvent(Product product, 184 bool RlzValueStoreChromeOS::AddStatefulEvent(Product product,
184 const char* event_rlz) { 185 const char* event_rlz) {
185 DCHECK(CalledOnValidThread()); 186 DCHECK(CalledOnValidThread());
186 return AddValueToList(GetKeyName(kStatefulEventKey, product), 187 return AddValueToList(GetKeyName(kStatefulEventKey, product),
187 new base::StringValue(event_rlz)); 188 base::MakeUnique<base::StringValue>(event_rlz));
188 } 189 }
189 190
190 bool RlzValueStoreChromeOS::IsStatefulEvent(Product product, 191 bool RlzValueStoreChromeOS::IsStatefulEvent(Product product,
191 const char* event_rlz) { 192 const char* event_rlz) {
192 DCHECK(CalledOnValidThread()); 193 DCHECK(CalledOnValidThread());
193 base::StringValue event_value(event_rlz); 194 base::StringValue event_value(event_rlz);
194 base::ListValue* events_list = NULL; 195 base::ListValue* events_list = NULL;
195 return rlz_store_->GetList(GetKeyName(kStatefulEventKey, product), 196 return rlz_store_->GetList(GetKeyName(kStatefulEventKey, product),
196 &events_list) && 197 &events_list) &&
197 events_list->Find(event_value) != events_list->end(); 198 events_list->Find(event_value) != events_list->end();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (!serializer.Serialize(*copy.get())) { 237 if (!serializer.Serialize(*copy.get())) {
237 LOG(ERROR) << "Failed to serialize RLZ data"; 238 LOG(ERROR) << "Failed to serialize RLZ data";
238 NOTREACHED(); 239 NOTREACHED();
239 return; 240 return;
240 } 241 }
241 if (!base::ImportantFileWriter::WriteFileAtomically(store_path_, json_data)) 242 if (!base::ImportantFileWriter::WriteFileAtomically(store_path_, json_data))
242 LOG(ERROR) << "Error writing RLZ store"; 243 LOG(ERROR) << "Error writing RLZ store";
243 } 244 }
244 245
245 bool RlzValueStoreChromeOS::AddValueToList(const std::string& list_name, 246 bool RlzValueStoreChromeOS::AddValueToList(const std::string& list_name,
246 base::Value* value) { 247 std::unique_ptr<base::Value> value) {
247 base::ListValue* list_value = NULL; 248 base::ListValue* list_value = NULL;
248 if (!rlz_store_->GetList(list_name, &list_value)) { 249 if (!rlz_store_->GetList(list_name, &list_value)) {
249 list_value = new base::ListValue; 250 list_value = new base::ListValue;
250 rlz_store_->Set(list_name, list_value); 251 rlz_store_->Set(list_name, list_value);
251 } 252 }
252 list_value->AppendIfNotPresent(value); 253 list_value->AppendIfNotPresent(std::move(value));
253 return true; 254 return true;
254 } 255 }
255 256
256 bool RlzValueStoreChromeOS::RemoveValueFromList(const std::string& list_name, 257 bool RlzValueStoreChromeOS::RemoveValueFromList(const std::string& list_name,
257 const base::Value& value) { 258 const base::Value& value) {
258 base::ListValue* list_value = NULL; 259 base::ListValue* list_value = NULL;
259 if (!rlz_store_->GetList(list_name, &list_value)) 260 if (!rlz_store_->GetList(list_name, &list_value))
260 return false; 261 return false;
261 size_t index; 262 size_t index;
262 list_value->Remove(value, &index); 263 list_value->Remove(value, &index);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 g_testing_rlz_store_path_ = directory; 334 g_testing_rlz_store_path_ = directory;
334 } 335 }
335 336
336 std::string RlzStoreFilenameStr() { 337 std::string RlzStoreFilenameStr() {
337 return GetRlzStorePath().value(); 338 return GetRlzStorePath().value();
338 } 339 }
339 340
340 } // namespace testing 341 } // namespace testing
341 342
342 } // namespace rlz_lib 343 } // 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