buffet: Make periodic polling secondary if XMPP channel is up

Now that GCD server allows us to change the supported notification
channel at run-time, start with the frequent poll (every 7 seconds)
and start up XMPP channel. Once XMPP connection is established, switch
over to using XMPP as the primary command delivery mechanism and
throttle down periodic polling to once every 30 minutes.

If, for some reason, XMPP channel gets disconnected, start polling
the server frequently again, until XMPP connection is re-established.

BUG=brillo:458, brillo:713
TEST=`FEATURES=test emerge-link buffet`

Change-Id: I148a98b8229aa4597a0f6a40e596aba15265ec91
Reviewed-on: https://chromium-review.googlesource.com/273631
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index 674bbd6..fe11d87 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -23,6 +23,7 @@
 #include "buffet/commands/command_manager.h"
 #include "buffet/notification/notification_channel.h"
 #include "buffet/notification/notification_delegate.h"
+#include "buffet/notification/pull_channel.h"
 #include "buffet/registration_status.h"
 #include "buffet/storage_interface.h"
 
@@ -193,10 +194,10 @@
       const base::Callback<void(const base::ListValue&)>& on_success,
       const CloudRequestErrorCallback& on_failure);
 
-  void AbortLimboCommands(const base::Closure& callback,
-                          const base::ListValue& commands);
-
-  void PeriodicallyPollCommands();
+  // Processes the command list that is fetched from the server on connection.
+  // Aborts commands which are in transitional states and publishes queued
+  // commands which are queued.
+  void ProcessInitialCommandList(const base::ListValue& commands);
 
   void PublishCommands(const base::ListValue& commands);
   void PublishCommand(const base::DictionaryValue& command);
@@ -247,12 +248,12 @@
 
   const bool notifications_enabled_;
   std::unique_ptr<NotificationChannel> primary_notification_channel_;
+  std::unique_ptr<PullChannel> pull_channel_;
+  NotificationChannel* current_notification_channel_{nullptr};
 
   // Tracks our current registration status.
   RegistrationStatus registration_status_{RegistrationStatus::kUnconfigured};
 
-  base::RepeatingTimer<DeviceRegistrationInfo> command_poll_timer_;
-
   std::vector<OnRegistrationChangedCallback> on_registration_changed_;
 
   base::WeakPtrFactory<DeviceRegistrationInfo> weak_factory_{this};