buffet: Support cloud command proxy.

This proxy allows publishing command updates to cloud API.

BUG=chromium:432540
TEST=cros_workon_make buffet --test&&manual

Change-Id: Id5730df60c3d40dfb7254d5f65c84dc51aea09eb
Reviewed-on: https://chromium-review.googlesource.com/228462
Reviewed-by: Anton Muhin <antonm@chromium.org>
Commit-Queue: Anton Muhin <antonm@chromium.org>
Tested-by: Anton Muhin <antonm@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 8fccc02..b36f114 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -19,6 +19,7 @@
 #include <chromeos/strings/string_utils.h>
 #include <chromeos/url_utils.h>
 
+#include "buffet/commands/cloud_command_proxy.h"
 #include "buffet/commands/command_definition.h"
 #include "buffet/commands/command_manager.h"
 #include "buffet/device_registration_storage_keys.h"
@@ -654,6 +655,16 @@
                   base::Unretained(this))))).Run();
 }
 
+void DeviceRegistrationInfo::UpdateCommand(
+    const std::string& command_id,
+    const base::DictionaryValue& command_patch) {
+  DoCloudRequest(
+      chromeos::http::request_type::kPatch,
+      GetServiceURL("commands/" + command_id),
+      &command_patch,
+      base::Bind(&IgnoreCloudResult), base::Bind(&IgnoreCloudError));
+}
+
 void DeviceRegistrationInfo::UpdateDeviceResource(base::Closure callback) {
   std::unique_ptr<base::DictionaryValue> device_resource =
       BuildDeviceResource(nullptr);
@@ -759,8 +770,12 @@
     }
 
     // TODO(antonm): Properly process cancellation of commands.
-    if (!command_manager_->FindCommand(command_instance->GetID()))
+    if (!command_manager_->FindCommand(command_instance->GetID())) {
+      std::unique_ptr<CommandProxyInterface> cloud_proxy{
+          new CloudCommandProxy(command_instance.get(), this)};
+      command_instance->AddProxy(std::move(cloud_proxy));
       command_manager_->AddCommand(std::move(command_instance));
+    }
   }
 }