buffet: Hook up XMPP to deliver push notifications to buffet

Now using XMPP not only for the device presence but for delivering
push notifications, specifically COMMAND_CREATED notification and
extracting the command instance from the notification message.
Add the commands received over XMPP to the command execution queue.

The remaining tasks for XMPP (making polling optional, provide
notification channel configuration options for buffet, update the
channel changes on GCD server, etc) are coming in follow-up CLs.

BUG=brillo:458
TEST=`FEATURES=test emerge-link buffet`
     Tested this on the device.

Change-Id: I6ba42e3687563133734aaf36d3802d6f4888f348
Reviewed-on: https://chromium-review.googlesource.com/272782
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/notification/notification_parser.cc b/buffet/notification/notification_parser.cc
new file mode 100644
index 0000000..5885afa
--- /dev/null
+++ b/buffet/notification/notification_parser.cc
@@ -0,0 +1,55 @@
+// Copyright 2015 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "buffet/notification/notification_parser.h"
+
+#include <base/logging.h>
+
+namespace buffet {
+
+namespace {
+
+// Processes COMMAND_CREATED notifications.
+bool ParseCommandCreated(const base::DictionaryValue& notification,
+                         NotificationDelegate* delegate) {
+  const base::DictionaryValue* command = nullptr;
+  if (!notification.GetDictionary("command", &command)) {
+    LOG(ERROR) << "COMMAND_CREATED notification is missing 'command' property";
+    return false;
+  }
+
+  delegate->OnCommandCreated(*command);
+  return true;
+}
+
+}  // anonymous namespace
+
+bool ParseNotificationJson(const base::DictionaryValue& notification,
+                           NotificationDelegate* delegate) {
+  CHECK(delegate);
+
+  std::string kind;
+  if (!notification.GetString("kind", &kind) ||
+      kind != "clouddevices#notification") {
+    LOG(WARNING) << "Push notification should have 'kind' property set to "
+                    "clouddevices#notification";
+    return false;
+  }
+
+  std::string type;
+  if (!notification.GetString("type", &type)) {
+    LOG(WARNING) << "Push notification should have 'type' property";
+    return false;
+  }
+
+  if (type == "COMMAND_CREATED")
+    return ParseCommandCreated(notification, delegate);
+
+  // Here we ignore other types of notifications for now.
+  LOG(INFO) << "Ignoring push notification of type " << type;
+  return true;
+}
+
+
+}  // namespace buffet