buffet: Integrate the XmppClient into buffet

TEST=FEATURES=test emerge-${BOARD} buffet
BUG=brillo:95

Change-Id: Ife3abac34db8e331d936891cfe4f3e937ecfb49c
Reviewed-on: https://chromium-review.googlesource.com/250462
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Nathan Bullock <nathanbullock@google.com>
Tested-by: Nathan Bullock <nathanbullock@google.com>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index a0b684e..b44498d 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -326,12 +326,24 @@
                            "Access token unavailable");
     return false;
   }
-
   access_token_expiration_ = base::Time::Now() +
                              base::TimeDelta::FromSeconds(expires_in);
-
   LOG(INFO) << "Access token is refreshed for additional " << expires_in
             << " seconds.";
+
+  // If no MessageLoop assume we're in unittests.
+  if (base::MessageLoop::current()) {
+    std::unique_ptr<XmppConnection> connection(new XmppConnection());
+    CHECK(connection->Initialize()) << "Failed to connect to XMPP server";
+    xmpp_client_.reset(new XmppClient(device_robot_account_, access_token_,
+                                      std::move(connection)));
+    CHECK(base::MessageLoopForIO::current()->WatchFileDescriptor(
+        xmpp_client_->GetFileDescriptor(), true,
+        base::MessageLoopForIO::WATCH_READ, &fd_watcher_, this))
+        << "Failed to watch XMPP file descriptor";
+    xmpp_client_->StartStream();
+  }
+
   return true;
 }