buffet: Add abstract CloudCommandUpdateInterface

Added a simple interface for DeviceRegistrationInfo class that just deals
with updating the command status on the cloud without having to use the
DeviceRegistrationInfo class directly.

This will allow to mock out that class more easily in the tests for
subsequent CLs.

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

Change-Id: I04b931bb2c54e18206e2e3cf588b2e2ce86d9507
Reviewed-on: https://chromium-review.googlesource.com/282260
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/cloud_command_proxy.cc b/buffet/commands/cloud_command_proxy.cc
index 78f87cb..a87e410 100644
--- a/buffet/commands/cloud_command_proxy.cc
+++ b/buffet/commands/cloud_command_proxy.cc
@@ -29,9 +29,9 @@
 
 CloudCommandProxy::CloudCommandProxy(
     CommandInstance* command_instance,
-    DeviceRegistrationInfo* device_registration_info)
-    : command_instance_(command_instance),
-      device_registration_info_(device_registration_info) {
+    CloudCommandUpdateInterface* cloud_command_updater)
+    : command_instance_{command_instance},
+      cloud_command_updater_{cloud_command_updater} {
 }
 
 void CloudCommandProxy::OnResultsChanged() {
@@ -71,7 +71,7 @@
   command_update_in_progress_ = true;
   in_progress_command_updates_ = new_pending_command_updates_;
   new_pending_command_updates_.reset();
-  device_registration_info_->UpdateCommand(
+  cloud_command_updater_->UpdateCommand(
       command_instance_->GetID(), patch,
       base::Bind(&CloudCommandProxy::OnUpdateCommandFinished,
                  weak_ptr_factory_.GetWeakPtr(), true),
diff --git a/buffet/commands/cloud_command_proxy.h b/buffet/commands/cloud_command_proxy.h
index 12c7f88..2c607ea 100644
--- a/buffet/commands/cloud_command_proxy.h
+++ b/buffet/commands/cloud_command_proxy.h
@@ -11,18 +11,18 @@
 #include <base/macros.h>
 #include <base/memory/weak_ptr.h>
 
+#include "buffet/commands/cloud_command_update_interface.h"
 #include "buffet/commands/command_proxy_interface.h"
 
 namespace buffet {
 
 class CommandInstance;
-class DeviceRegistrationInfo;
 
 // Command proxy which publishes command updates to the cloud.
 class CloudCommandProxy final : public CommandProxyInterface {
  public:
   CloudCommandProxy(CommandInstance* command_instance,
-                    DeviceRegistrationInfo* device_registration_info);
+                    CloudCommandUpdateInterface* cloud_command_updater);
   ~CloudCommandProxy() override = default;
 
   // CommandProxyInterface implementation/overloads.
@@ -47,7 +47,7 @@
   void OnUpdateCommandFinished(bool success);
 
   CommandInstance* command_instance_;
-  DeviceRegistrationInfo* device_registration_info_;
+  CloudCommandUpdateInterface* cloud_command_updater_;
 
   // Set to true while a pending PATCH request is in flight to the server.
   bool command_update_in_progress_{false};
diff --git a/buffet/commands/cloud_command_update_interface.h b/buffet/commands/cloud_command_update_interface.h
new file mode 100644
index 0000000..d18ec85
--- /dev/null
+++ b/buffet/commands/cloud_command_update_interface.h
@@ -0,0 +1,30 @@
+// Copyright 2015 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BUFFET_COMMANDS_CLOUD_COMMAND_UPDATE_INTERFACE_H_
+#define BUFFET_COMMANDS_CLOUD_COMMAND_UPDATE_INTERFACE_H_
+
+#include <string>
+
+#include <base/callback_forward.h>
+#include <base/values.h>
+
+namespace buffet {
+
+// An abstract interface to allow for sending command update requests to the
+// cloud server.
+class CloudCommandUpdateInterface {
+ public:
+  virtual void UpdateCommand(const std::string& command_id,
+                             const base::DictionaryValue& command_patch,
+                             const base::Closure& on_success,
+                             const base::Closure& on_error) = 0;
+
+ protected:
+  virtual ~CloudCommandUpdateInterface() = default;
+};
+
+}  // namespace buffet
+
+#endif  // BUFFET_COMMANDS_CLOUD_COMMAND_UPDATE_INTERFACE_H_
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index 43c70a4..bce8c6f 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -22,6 +22,7 @@
 #include <chromeos/http/http_transport.h>
 
 #include "buffet/buffet_config.h"
+#include "buffet/commands/cloud_command_update_interface.h"
 #include "buffet/commands/command_manager.h"
 #include "buffet/notification/notification_channel.h"
 #include "buffet/notification/notification_delegate.h"
@@ -50,7 +51,8 @@
 extern const char kErrorDomainGCDServer[];
 
 // The DeviceRegistrationInfo class represents device registration information.
-class DeviceRegistrationInfo : public NotificationDelegate {
+class DeviceRegistrationInfo : public NotificationDelegate,
+                               public CloudCommandUpdateInterface {
  public:
   using OnRegistrationChangedCallback =
       base::Callback<void(RegistrationStatus)>;
@@ -129,11 +131,11 @@
   std::string RegisterDevice(const std::string& ticket_id,
                              chromeos::ErrorPtr* error);
 
-  // Updates a command.
+  // Updates a command (override from buffet::CloudCommandUpdateInterface).
   void UpdateCommand(const std::string& command_id,
                      const base::DictionaryValue& command_patch,
                      const base::Closure& on_success,
-                     const base::Closure& on_error);
+                     const base::Closure& on_error) override;
 
   // Updates basic device information.
   bool UpdateDeviceInfo(const std::string& name,