buffet: Handle cloud request failures due to device deleted on cloud

When making cloud request and receiving "authorization failed" error,
we are refreshing the access token. If that fails with "invalid_grant",
we are certain that the device's robot account has been deleted, so
we should treat the device as no longer registered with the cloud, and
delete its cached credentials.

This CL adds OnDeviceDeleted() notification which wipes out the device
registration information. This notification is called when refreshing
the access token fails with "invalid_grant".

A follow-up CL will add handling for DEVICE_DELETED XMPP notification.

BUG=brillo:1215
TEST=`FEATURES=test emerge-link buffet`
     `test_that -b link 100.96.49.59 e:buffet_.*`
CQ-DEPEND=CL:281664

Change-Id: I220c286dbd286dd036d7664a4d14e9d761d70f28
Reviewed-on: https://chromium-review.googlesource.com/281393
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: 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 ed96db0..19c698c 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -113,7 +113,10 @@
   void Start();
 
   // Checks whether we have credentials generated during registration.
-  bool HaveRegistrationCredentials(chromeos::ErrorPtr* error);
+  bool HaveRegistrationCredentials() const;
+  // Calls HaveRegistrationCredentials() and logs an error if no credentials
+  // are available.
+  bool VerifyRegistrationCredentials(chromeos::ErrorPtr* error) const;
 
   // Gets the full device description JSON object asynchronously.
   // Passes the device info as the first argument to |callback|, or nullptr if
@@ -278,6 +281,9 @@
   void OnPermanentFailure() override;
   void OnCommandCreated(const base::DictionaryValue& command) override;
 
+  // Wipes out the device registration information and stops server connections.
+  void MarkDeviceUnregistered();
+
   // Transient data
   std::string access_token_;
   base::Time access_token_expiration_;