buffet: Order device state and command updates on the server

Added strict ordering between command and state updates on the cloud
server interface. Command updates are tied to the current device state
and command update requests to the server are not dispatched until the
corresponding device state request finishes successfully.

BUG=brillo:1202
TEST=`FEATURES=test emerge-link buffet`

Change-Id: I23af95ab66b5bca91f637d9886ae234681b67104
Reviewed-on: https://chromium-review.googlesource.com/282261
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/states/state_manager.h b/buffet/states/state_manager.h
index a34f7c1..914daeb 100644
--- a/buffet/states/state_manager.h
+++ b/buffet/states/state_manager.h
@@ -9,6 +9,7 @@
 #include <memory>
 #include <set>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include <base/callback.h>
@@ -58,7 +59,16 @@
 
   // Returns the recorded state changes since last time this method has been
   // called.
-  std::vector<StateChange> GetAndClearRecordedStateChanges();
+  std::pair<StateChangeQueueInterface::UpdateID, std::vector<StateChange>>
+  GetAndClearRecordedStateChanges();
+
+  // Called to notify that the state patch with |id| has been successfully sent
+  // to the server and processed.
+  void NotifyStateUpdatedOnServer(StateChangeQueueInterface::UpdateID id);
+
+  StateChangeQueueInterface* GetStateChangeQueue() const {
+    return state_change_queue_;
+  }
 
  private:
   friend class BaseApiHandlerTest;