blob: 5885afabb1545dbb9684f01bdb7239d547d1b9e6 [file] [log] [blame]
Alex Vakulenkof6183df2015-05-21 17:39:25 -07001// Copyright 2015 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "buffet/notification/notification_parser.h"
6
7#include <base/logging.h>
8
9namespace buffet {
10
11namespace {
12
13// Processes COMMAND_CREATED notifications.
14bool ParseCommandCreated(const base::DictionaryValue& notification,
15 NotificationDelegate* delegate) {
16 const base::DictionaryValue* command = nullptr;
17 if (!notification.GetDictionary("command", &command)) {
18 LOG(ERROR) << "COMMAND_CREATED notification is missing 'command' property";
19 return false;
20 }
21
22 delegate->OnCommandCreated(*command);
23 return true;
24}
25
26} // anonymous namespace
27
28bool ParseNotificationJson(const base::DictionaryValue& notification,
29 NotificationDelegate* delegate) {
30 CHECK(delegate);
31
32 std::string kind;
33 if (!notification.GetString("kind", &kind) ||
34 kind != "clouddevices#notification") {
35 LOG(WARNING) << "Push notification should have 'kind' property set to "
36 "clouddevices#notification";
37 return false;
38 }
39
40 std::string type;
41 if (!notification.GetString("type", &type)) {
42 LOG(WARNING) << "Push notification should have 'type' property";
43 return false;
44 }
45
46 if (type == "COMMAND_CREATED")
47 return ParseCommandCreated(notification, delegate);
48
49 // Here we ignore other types of notifications for now.
50 LOG(INFO) << "Ignoring push notification of type " << type;
51 return true;
52}
53
54
55} // namespace buffet