Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / notifications / notification_database_data_conversions.cc
blobd656f7dec6b5c9f6cacb22d13206a0acd09faa07
1 // Copyright 2015 The Chromium 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.
5 #include "content/browser/notifications/notification_database_data_conversions.h"
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/notifications/notification_database_data.pb.h"
10 #include "content/public/browser/notification_database_data.h"
12 namespace content {
14 bool DeserializeNotificationDatabaseData(const std::string& input,
15 NotificationDatabaseData* output) {
16 DCHECK(output);
18 NotificationDatabaseDataProto message;
19 if (!message.ParseFromString(input))
20 return false;
22 output->notification_id = message.notification_id();
23 output->origin = GURL(message.origin());
24 output->service_worker_registration_id =
25 message.service_worker_registration_id();
27 PlatformNotificationData* notification_data = &output->notification_data;
28 const NotificationDatabaseDataProto::NotificationData& payload =
29 message.notification_data();
31 notification_data->title = base::UTF8ToUTF16(payload.title());
32 notification_data->direction =
33 payload.direction() ==
34 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT ?
35 PlatformNotificationData::NotificationDirectionRightToLeft :
36 PlatformNotificationData::NotificationDirectionLeftToRight;
37 notification_data->lang = payload.lang();
38 notification_data->body = base::UTF8ToUTF16(payload.body());
39 notification_data->tag = payload.tag();
40 notification_data->icon = GURL(payload.icon());
41 notification_data->silent = payload.silent();
43 if (payload.data().length()) {
44 notification_data->data.assign(payload.data().begin(),
45 payload.data().end());
48 return true;
51 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input,
52 std::string* output) {
53 DCHECK(output);
55 scoped_ptr<NotificationDatabaseDataProto::NotificationData> payload(
56 new NotificationDatabaseDataProto::NotificationData());
58 const PlatformNotificationData& notification_data = input.notification_data;
60 payload->set_title(base::UTF16ToUTF8(notification_data.title));
61 payload->set_direction(
62 notification_data.direction ==
63 PlatformNotificationData::NotificationDirectionRightToLeft ?
64 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT :
65 NotificationDatabaseDataProto::NotificationData::LEFT_TO_RIGHT);
66 payload->set_lang(notification_data.lang);
67 payload->set_body(base::UTF16ToUTF8(notification_data.body));
68 payload->set_tag(notification_data.tag);
69 payload->set_icon(notification_data.icon.spec());
70 payload->set_silent(notification_data.silent);
72 if (notification_data.data.size()) {
73 payload->set_data(&notification_data.data.front(),
74 notification_data.data.size());
77 NotificationDatabaseDataProto message;
78 message.set_notification_id(input.notification_id);
79 message.set_origin(input.origin.spec());
80 message.set_service_worker_registration_id(
81 input.service_worker_registration_id);
82 message.set_allocated_notification_data(payload.release());
84 return message.SerializeToString(output);
87 } // namespace content