aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2016-01-15 14:48:54 -0800
committerVitaly Buka <vitalybuka@google.com>2016-01-15 23:08:26 +0000
commit42e508f2559e019d2fcc8f88adfd184b7a6bc3a4 (patch)
tree14f6c595e2f30444a1f18cf862b40aed205735a7 /include
parent7ecdf959f10b62f192be867c280a7885626d6b85 (diff)
downloadlibweave-42e508f2559e019d2fcc8f88adfd184b7a6bc3a4.tar.gz
Add write callback into SaveSettings function
Saving critical settings needs confirmation. When command alters device config, it should be set "Done" only after settings are actually saved. BUG:25776798 Change-Id: Id8f52a2922aa0e58f66eb3e257197a47e21ef3a2 Reviewed-on: https://weave-review.googlesource.com/2199 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/weave/provider/config_store.h11
-rw-r--r--include/weave/provider/test/mock_config_store.h12
2 files changed, 19 insertions, 4 deletions
diff --git a/include/weave/provider/config_store.h b/include/weave/provider/config_store.h
index 991d750..128eccc 100644
--- a/include/weave/provider/config_store.h
+++ b/include/weave/provider/config_store.h
@@ -13,6 +13,7 @@
#include <base/callback.h>
#include <base/time/time.h>
#include <weave/enum_to_string.h>
+#include <weave/error.h>
#include <weave/settings.h>
namespace weave {
@@ -48,9 +49,13 @@ namespace provider {
// persistent storage (file, flash, etc).
// For example:
// void FileConfigStore::SaveSettings(const std::string& name,
-// const std::string& settings) {
+// const std::string& settings,
+// const DoneCallback& callback) {
// std::ofstream str("/var/lib/weave/weave_" + name + ".json");
// str << settings;
+// if (!callback.is_null())
+// task_runner_->PostDelayedTask(FROM_HERE, base::Bind(callback, nullptr),
+// {});
// }
// It is highly recommended to protected data using encryption with
// hardware backed key.
@@ -75,8 +80,10 @@ class ConfigStore {
// modifications. Data stored in settings can be sensitive, so it's highly
// recommended to protect data, e.g. using encryption.
// |name| is the name of settings blob. Could be used as filename.
+ // Implementation must call or post callback
virtual void SaveSettings(const std::string& name,
- const std::string& settings) = 0;
+ const std::string& settings,
+ const DoneCallback& callback) = 0;
// Deprecated: only for migration of old configs to version with |name|.
virtual std::string LoadSettings() = 0;
diff --git a/include/weave/provider/test/mock_config_store.h b/include/weave/provider/test/mock_config_store.h
index cdae693..e6411d6 100644
--- a/include/weave/provider/test/mock_config_store.h
+++ b/include/weave/provider/test/mock_config_store.h
@@ -40,11 +40,19 @@ class MockConfigStore : public ConfigStore {
"device_id": "TEST_DEVICE_ID"
})"));
EXPECT_CALL(*this, LoadSettings("config")).WillRepeatedly(Return(""));
- EXPECT_CALL(*this, SaveSettings("config", _)).WillRepeatedly(Return());
+ EXPECT_CALL(*this, SaveSettings("config", _, _))
+ .WillRepeatedly(testing::WithArgs<1, 2>(testing::Invoke(
+ [](const std::string& json, const DoneCallback& callback) {
+ if (!callback.is_null())
+ callback.Run(nullptr);
+ })));
}
MOCK_METHOD1(LoadDefaults, bool(Settings*));
MOCK_METHOD1(LoadSettings, std::string(const std::string&));
- MOCK_METHOD2(SaveSettings, void(const std::string&, const std::string&));
+ MOCK_METHOD3(SaveSettings,
+ void(const std::string&,
+ const std::string&,
+ const DoneCallback&));
MOCK_METHOD0(LoadSettings, std::string());
};