buffet: Use DictionaryValue in StorageInterface
It is used to store dictionaries only.
BUG=none
TEST='FEATURES=test emerge-gizmo buffet'
Change-Id: Ic85f77a3d31853bf8ed244d7f58264e9c809f666
Reviewed-on: https://chromium-review.googlesource.com/271301
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/storage_impls.cc b/buffet/storage_impls.cc
index e45ddbf..ea29d69 100644
--- a/buffet/storage_impls.cc
+++ b/buffet/storage_impls.cc
@@ -10,33 +10,35 @@
#include <base/json/json_reader.h>
#include <base/json/json_writer.h>
+#include "buffet/utils.h"
+
namespace buffet {
FileStorage::FileStorage(const base::FilePath& file_path)
: file_path_(file_path) { }
-std::unique_ptr<base::Value> FileStorage::Load() {
+std::unique_ptr<base::DictionaryValue> FileStorage::Load() {
std::string json;
if (!base::ReadFileToString(file_path_, &json))
- return std::unique_ptr<base::Value>();
+ return std::unique_ptr<base::DictionaryValue>();
- return std::unique_ptr<base::Value>(base::JSONReader::Read(json));
+ return LoadJsonDict(json, nullptr);
}
-bool FileStorage::Save(const base::Value& config) {
+bool FileStorage::Save(const base::DictionaryValue& config) {
std::string json;
base::JSONWriter::WriteWithOptions(
&config, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
return base::ImportantFileWriter::WriteFileAtomically(file_path_, json);
}
-
-std::unique_ptr<base::Value> MemStorage::Load() {
- return std::unique_ptr<base::Value>(cache_->DeepCopy());
+std::unique_ptr<base::DictionaryValue> MemStorage::Load() {
+ return std::unique_ptr<base::DictionaryValue>(cache_.DeepCopy());
}
-bool MemStorage::Save(const base::Value& config) {
- cache_.reset(config.DeepCopy());
+bool MemStorage::Save(const base::DictionaryValue& config) {
+ cache_.Clear();
+ cache_.MergeDictionary(&config);
++save_count_;
return true;
}