buffet: add a timeout to HTTP requests

CloudCommandProxy makes the understandable assumption that either one of
the success or error callbacks it provides to
chromeos::http::SendRequest will be invoked in the future.  When neither
of these callbacks are invoked future updates to that command will not
be sent to the cloud.  Add a timeout to all requests made by buffet to
allow these assumptions to function.

BUG=chrome-os-partner:40663
TEST=FEATURES=test emerge-amd64-generic test

Change-Id: Ia1e1f265818c9c69427fe641651c76c6783d720f
Reviewed-on: https://chromium-review.googlesource.com/274046
Reviewed-by: Garret Kelly <gdk@chromium.org>
Commit-Queue: Garret Kelly <gdk@chromium.org>
Tested-by: Garret Kelly <gdk@chromium.org>
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 1fd85c2..23e4fca 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -16,6 +16,7 @@
 #include <chromeos/dbus/async_event_sequencer.h>
 #include <chromeos/dbus/exported_object_manager.h>
 #include <chromeos/errors/error.h>
+#include <chromeos/http/http_transport.h>
 #include <chromeos/key_value_store.h>
 #include <dbus/bus.h>
 #include <dbus/object_path.h>
@@ -36,6 +37,8 @@
 namespace {
 // Max of 100 state update events should be enough in the queue.
 const size_t kMaxStateChangeQueueSize = 100;
+// The number of seconds each HTTP request will be allowed before timing out.
+const int kRequestTimeoutSeconds = 30;
 }  // anonymous namespace
 
 Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager)
@@ -69,11 +72,15 @@
       base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr()));
   config->Load(config_path);
 
+  auto transport = chromeos::http::Transport::CreateDefault();
+  transport->SetDefaultTimeout(base::TimeDelta::FromSeconds(
+      kRequestTimeoutSeconds));
+
   // TODO(avakulenko): Figure out security implications of storing
   // device info state data unencrypted.
   device_info_.reset(new DeviceRegistrationInfo(
-      command_manager_, state_manager_, std::move(config),
-      chromeos::http::Transport::CreateDefault(), xmpp_enabled));
+      command_manager_, state_manager_, std::move(config), transport,
+      xmpp_enabled));
   device_info_->AddOnRegistrationChangedCallback(base::Bind(
       &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr()));