buffet: Add support for DEVICE_DELETED XMPP notification
When DEVICE_DELETED notification is received over XMPP channel,
buffet will remove any cloud registration information (credentials,
robot account) and close server connections (XMPP channel, etc).
BUG=brillo:1215
TEST=`FEATURES=test emerge-link buffet`
Test manually on the device.
Change-Id: I86e19659b9fbc06685bcabb6c659a633e797cae5
Reviewed-on: https://chromium-review.googlesource.com/281666
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/notification/notification_parser.cc b/buffet/notification/notification_parser.cc
index 5885afa..8cde3fa 100644
--- a/buffet/notification/notification_parser.cc
+++ b/buffet/notification/notification_parser.cc
@@ -23,6 +23,19 @@
return true;
}
+// Processes DEVICE_DELETED notifications.
+bool ParseDeviceDeleted(const base::DictionaryValue& notification,
+ NotificationDelegate* delegate) {
+ std::string device_id;
+ if (!notification.GetString("deviceId", &device_id)) {
+ LOG(ERROR) << "DEVICE_DELETED notification is missing 'deviceId' property";
+ return false;
+ }
+
+ delegate->OnDeviceDeleted(device_id);
+ return true;
+}
+
} // anonymous namespace
bool ParseNotificationJson(const base::DictionaryValue& notification,
@@ -46,6 +59,9 @@
if (type == "COMMAND_CREATED")
return ParseCommandCreated(notification, delegate);
+ if (type == "DEVICE_DELETED")
+ return ParseDeviceDeleted(notification, delegate);
+
// Here we ignore other types of notifications for now.
LOG(INFO) << "Ignoring push notification of type " << type;
return true;