buffet: Add state change queue When device state properties are updated, compile the change notifications in StateChangeQueue object so they can be pulled by Cloud Server adaptor and batch-update the device state on the server. When StateManager receives property updates, it notifies the StateChangeQueue object of the changes via StateChangeQueueInterface. The changes are kept in the queue along with the their time stamps until they are pulled by Cloud Server adaper (using StateChangeQueue method). At this point, the adapter would notify the server of recorded device state changes and the StateChangeQueue is cleared, ready to record new state updates. BUG=chromium:415364 TEST=FEATURES=test emerge-link buffet Change-Id: Ie99e2ada39aaf0164e08699d65153abfc5235a2f Reviewed-on: https://chromium-review.googlesource.com/226014 Tested-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Christopher Wiley <wiley@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/states/state_manager.h b/buffet/states/state_manager.h index 2555ab5..f17e8a6 100644 --- a/buffet/states/state_manager.h +++ b/buffet/states/state_manager.h
@@ -9,11 +9,13 @@ #include <memory> #include <set> #include <string> +#include <vector> #include <base/macros.h> #include <chromeos/errors/error.h> #include <chromeos/variant_dictionary.h> +#include "buffet/states/state_change_queue_interface.h" #include "buffet/states/state_package.h" namespace base { @@ -28,7 +30,7 @@ // to the GCD cloud server and local clients. class StateManager final { public: - StateManager() = default; + explicit StateManager(StateChangeQueueInterface* state_change_queue); // Initializes the state manager and load device state fragments. // Called by Buffet daemon at startup. @@ -57,7 +59,16 @@ return categories_; } + // Returns the recorded state changes since last time this method has been + // called. + std::vector<StateChange> GetAndClearRecordedStateChanges(); + private: + // Helper method to be used with SetPropertyValue() and UpdateProperties() + bool UpdatePropertyValue(const std::string& full_property_name, + const chromeos::Any& value, + chromeos::ErrorPtr* error); + // Loads a device state fragment from a JSON object. |category| represents // a device daemon providing the state fragment or empty string for the // base state fragment. @@ -89,6 +100,7 @@ // Finds a package by its name. If none exists, one will be created. StatePackage* FindOrCreatePackage(const std::string& package_name); + StateChangeQueueInterface* state_change_queue_; // Owned by buffet::Manager. std::map<std::string, std::unique_ptr<StatePackage>> packages_; std::set<std::string> categories_;