| OLD | NEW |
| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 void RlzValueStoreChromeOS::CollectGarbage() { | 206 void RlzValueStoreChromeOS::CollectGarbage() { |
| 207 DCHECK(CalledOnValidThread()); | 207 DCHECK(CalledOnValidThread()); |
| 208 NOTIMPLEMENTED(); | 208 NOTIMPLEMENTED(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void RlzValueStoreChromeOS::ReadStore() { | 211 void RlzValueStoreChromeOS::ReadStore() { |
| 212 int error_code = 0; | 212 int error_code = 0; |
| 213 std::string error_msg; | 213 std::string error_msg; |
| 214 JSONFileValueDeserializer deserializer(store_path_); | 214 JSONFileValueDeserializer deserializer(store_path_); |
| 215 scoped_ptr<base::Value> value = | 215 std::unique_ptr<base::Value> value = |
| 216 deserializer.Deserialize(&error_code, &error_msg); | 216 deserializer.Deserialize(&error_code, &error_msg); |
| 217 switch (error_code) { | 217 switch (error_code) { |
| 218 case JSONFileValueDeserializer::JSON_NO_SUCH_FILE: | 218 case JSONFileValueDeserializer::JSON_NO_SUCH_FILE: |
| 219 read_only_ = false; | 219 read_only_ = false; |
| 220 break; | 220 break; |
| 221 case JSONFileValueDeserializer::JSON_NO_ERROR: | 221 case JSONFileValueDeserializer::JSON_NO_ERROR: |
| 222 read_only_ = false; | 222 read_only_ = false; |
| 223 rlz_store_.reset(static_cast<base::DictionaryValue*>(value.release())); | 223 rlz_store_.reset(static_cast<base::DictionaryValue*>(value.release())); |
| 224 break; | 224 break; |
| 225 default: | 225 default: |
| 226 LOG(ERROR) << "Error reading RLZ store: " << error_msg; | 226 LOG(ERROR) << "Error reading RLZ store: " << error_msg; |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 void RlzValueStoreChromeOS::WriteStore() { | 230 void RlzValueStoreChromeOS::WriteStore() { |
| 231 std::string json_data; | 231 std::string json_data; |
| 232 JSONStringValueSerializer serializer(&json_data); | 232 JSONStringValueSerializer serializer(&json_data); |
| 233 serializer.set_pretty_print(true); | 233 serializer.set_pretty_print(true); |
| 234 scoped_ptr<base::DictionaryValue> copy = | 234 std::unique_ptr<base::DictionaryValue> copy = |
| 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 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |