buffet: Queue device resource updates to prevent parallel requests
As with command and device status updates, device resource updates must
be gated to prevent multiple simultaneous requests sent out the server
at the same time, or else they might overwrite each other's data and be
processed out of order.
BUG=brillo:1230
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I5d74a76d513d64fd6edd4b641ab54c9edef2f536
Reviewed-on: https://chromium-review.googlesource.com/282828
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/device_registration_info.h b/buffet/device_registration_info.h
index b41b55a..dcf54c0 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -241,6 +241,10 @@
void UpdateDeviceResource(const base::Closure& on_success,
const CloudRequestErrorCallback& on_failure);
+ void StartQueuedUpdateDeviceResource();
+ // Success/failure callbacks for UpdateDeviceResource().
+ void OnUpdateDeviceResourceSuccess(const base::DictionaryValue& reply);
+ void OnUpdateDeviceResourceError(const chromeos::Error* error);
void FetchCommands(
const base::Callback<void(const base::ListValue&)>& on_success,
@@ -314,6 +318,15 @@
// to the cloud server.
bool device_state_update_pending_{false};
+ using ResourceUpdateCallbackList =
+ std::vector<std::pair<base::Closure, CloudRequestErrorCallback>>;
+ // Success/error callbacks for device resource update request currently in
+ // flight to the cloud server.
+ ResourceUpdateCallbackList in_progress_resource_update_callbacks_;
+ // Success/error callbacks for device resource update requests queued while
+ // another request is in flight to the cloud server.
+ ResourceUpdateCallbackList queued_resource_update_callbacks_;
+
const bool notifications_enabled_;
std::unique_ptr<NotificationChannel> primary_notification_channel_;
std::unique_ptr<PullChannel> pull_channel_;