buffet: Fix failed XMPP authorization issue

Right now, if XMPP notification channel is created early enough before
buffet was able to refresh the access token, XMPP might have invalid
or outdated credentials and XMPP SASL handshake would fail with
"not authorized" problem. Current code just retries the connection
attempt, but, sadly, using the same invalid credentials, which goes
into infinte loop of failed attempts.

Fixed the problem by making sure that XMPP authorization error causes
access token refresh and if authorization error occurrs, XMPP connection
will not be re-established until we get a new access token.

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

Change-Id: Ieebfff26f4d06524819b2a5819f468e179cd2d6f
Reviewed-on: https://chromium-review.googlesource.com/273979
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index f8c2292..9e8a8b0 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -167,6 +167,9 @@
   // Forcibly refreshes the access token.
   bool RefreshAccessToken(chromeos::ErrorPtr* error);
 
+  // Calls RefreshAccessToken(nullptr). Used as a closure.
+  void RunRefreshAccessToken();
+
   // Parse the OAuth response, and sets registration status to
   // kInvalidCredentials if our registration is no longer valid.
   std::unique_ptr<base::DictionaryValue> ParseOAuthResponse(
@@ -256,6 +259,7 @@
   std::unique_ptr<NotificationChannel> primary_notification_channel_;
   std::unique_ptr<PullChannel> pull_channel_;
   NotificationChannel* current_notification_channel_{nullptr};
+  bool notification_channel_starting_{false};
 
   // Tracks our current registration status.
   RegistrationStatus registration_status_{RegistrationStatus::kUnconfigured};