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

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

Issue 1353323003: Cleanup: Pass std::string as const reference from rlz/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // Returns file path of the RLZ storage lock file. 54 // Returns file path of the RLZ storage lock file.
55 base::FilePath GetRlzStoreLockPath() { 55 base::FilePath GetRlzStoreLockPath() {
56 base::FilePath homedir; 56 base::FilePath homedir;
57 PathService::Get(base::DIR_HOME, &homedir); 57 PathService::Get(base::DIR_HOME, &homedir);
58 return g_testing_rlz_store_path_.empty() ? 58 return g_testing_rlz_store_path_.empty() ?
59 homedir.Append(kRLZLockFileName) : 59 homedir.Append(kRLZLockFileName) :
60 g_testing_rlz_store_path_.Append(kRLZLockFileName); 60 g_testing_rlz_store_path_.Append(kRLZLockFileName);
61 } 61 }
62 62
63 // Returns the dictionary key for storing access point-related prefs. 63 // Returns the dictionary key for storing access point-related prefs.
64 std::string GetKeyName(std::string key, AccessPoint access_point) { 64 std::string GetKeyName(const std::string& key, AccessPoint access_point) {
65 std::string brand = SupplementaryBranding::GetBrand(); 65 std::string brand = SupplementaryBranding::GetBrand();
66 if (brand.empty()) 66 if (brand.empty())
67 brand = kNoSupplementaryBrand; 67 brand = kNoSupplementaryBrand;
68 return key + "." + GetAccessPointName(access_point) + "." + brand; 68 return key + "." + GetAccessPointName(access_point) + "." + brand;
69 } 69 }
70 70
71 // Returns the dictionary key for storing product-related prefs. 71 // Returns the dictionary key for storing product-related prefs.
72 std::string GetKeyName(std::string key, Product product) { 72 std::string GetKeyName(const std::string& key, Product product) {
73 std::string brand = SupplementaryBranding::GetBrand(); 73 std::string brand = SupplementaryBranding::GetBrand();
74 if (brand.empty()) 74 if (brand.empty())
75 brand = kNoSupplementaryBrand; 75 brand = kNoSupplementaryBrand;
76 return key + "." + GetProductName(product) + "." + brand; 76 return key + "." + GetProductName(product) + "." + brand;
77 } 77 }
78 78
79 } // namespace 79 } // namespace
80 80
81 RlzValueStoreChromeOS::RlzValueStoreChromeOS(const base::FilePath& store_path) 81 RlzValueStoreChromeOS::RlzValueStoreChromeOS(const base::FilePath& store_path)
82 : rlz_store_(new base::DictionaryValue), 82 : rlz_store_(new base::DictionaryValue),
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 rlz_store_->DeepCopyWithoutEmptyChildren(); 235 rlz_store_->DeepCopyWithoutEmptyChildren();
236 if (!serializer.Serialize(*copy.get())) { 236 if (!serializer.Serialize(*copy.get())) {
237 LOG(ERROR) << "Failed to serialize RLZ data"; 237 LOG(ERROR) << "Failed to serialize RLZ data";
238 NOTREACHED(); 238 NOTREACHED();
239 return; 239 return;
240 } 240 }
241 if (!base::ImportantFileWriter::WriteFileAtomically(store_path_, json_data)) 241 if (!base::ImportantFileWriter::WriteFileAtomically(store_path_, json_data))
242 LOG(ERROR) << "Error writing RLZ store"; 242 LOG(ERROR) << "Error writing RLZ store";
243 } 243 }
244 244
245 bool RlzValueStoreChromeOS::AddValueToList(std::string list_name, 245 bool RlzValueStoreChromeOS::AddValueToList(const std::string& list_name,
246 base::Value* value) { 246 base::Value* value) {
247 base::ListValue* list_value = NULL; 247 base::ListValue* list_value = NULL;
248 if (!rlz_store_->GetList(list_name, &list_value)) { 248 if (!rlz_store_->GetList(list_name, &list_value)) {
249 list_value = new base::ListValue; 249 list_value = new base::ListValue;
250 rlz_store_->Set(list_name, list_value); 250 rlz_store_->Set(list_name, list_value);
251 } 251 }
252 list_value->AppendIfNotPresent(value); 252 list_value->AppendIfNotPresent(value);
253 return true; 253 return true;
254 } 254 }
255 255
256 bool RlzValueStoreChromeOS::RemoveValueFromList(std::string list_name, 256 bool RlzValueStoreChromeOS::RemoveValueFromList(const std::string& list_name,
257 const base::Value& value) { 257 const base::Value& value) {
258 base::ListValue* list_value = NULL; 258 base::ListValue* list_value = NULL;
259 if (!rlz_store_->GetList(list_name, &list_value)) 259 if (!rlz_store_->GetList(list_name, &list_value))
260 return false; 260 return false;
261 size_t index; 261 size_t index;
262 list_value->Remove(value, &index); 262 list_value->Remove(value, &index);
263 return true; 263 return true;
264 } 264 }
265 265
266 namespace { 266 namespace {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 g_testing_rlz_store_path_ = directory; 333 g_testing_rlz_store_path_ = directory;
334 } 334 }
335 335
336 std::string RlzStoreFilenameStr() { 336 std::string RlzStoreFilenameStr() {
337 return GetRlzStorePath().value(); 337 return GetRlzStorePath().value();
338 } 338 }
339 339
340 } // namespace testing 340 } // namespace testing
341 341
342 } // namespace rlz_lib 342 } // 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