Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/notifications/notification_database_data.cc

Issue 1003843002: Add the NotificationDatabaseData structure and protobuf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-GetNextNotificationId
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/browser/notifications/notification_database_data.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/notifications/notification_database_data.pb.h"
9
10 namespace content {
11
12 NotificationDatabaseData::NotificationDatabaseData()
13 : notification_id(0),
14 service_worker_registration_id(0) {
15 }
16
17 NotificationDatabaseData::~NotificationDatabaseData() {}
18
19 NotificationDatabaseDataProto ToNotificationDatabaseDataProto(
20 const NotificationDatabaseData& database_data) {
21 const PlatformNotificationData& notification_data =
22 database_data.notification_data;
23
24 scoped_ptr<NotificationDatabaseDataProto::NotificationData> payload(
25 new NotificationDatabaseDataProto::NotificationData());
26 payload->set_title(base::UTF16ToUTF8(notification_data.title));
27 payload->set_direction(
28 notification_data.direction ==
29 PlatformNotificationData::NotificationDirectionRightToLeft ?
30 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT :
31 NotificationDatabaseDataProto::NotificationData::LEFT_TO_RIGHT);
32 payload->set_lang(notification_data.lang);
33 payload->set_body(base::UTF16ToUTF8(notification_data.body));
34 payload->set_tag(notification_data.tag);
35 payload->set_icon(notification_data.icon.spec());
36 payload->set_silent(notification_data.silent);
37
38 NotificationDatabaseDataProto message;
39 message.set_notification_id(database_data.notification_id);
40 message.set_origin(database_data.origin.spec());
41 message.set_service_worker_registration_id(
42 database_data.service_worker_registration_id);
43 message.set_allocated_notification_data(payload.release());
44
45 return message;
46 }
47
48 NotificationDatabaseData ToNotificationDatabaseData(
49 const NotificationDatabaseDataProto& database_data_proto) {
50 const NotificationDatabaseDataProto::NotificationData& payload =
51 database_data_proto.notification_data();
52
53 PlatformNotificationData notification_data;
54 notification_data.title = base::UTF8ToUTF16(payload.title());
55 notification_data.direction =
56 payload.direction() ==
57 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT ?
58 PlatformNotificationData::NotificationDirectionRightToLeft :
59 PlatformNotificationData::NotificationDirectionLeftToRight;
60 notification_data.lang = payload.lang();
61 notification_data.body = base::UTF8ToUTF16(payload.body());
62 notification_data.tag = payload.tag();
63 notification_data.icon = GURL(payload.icon());
64 notification_data.silent = payload.silent();
65
66 NotificationDatabaseData database_data;
67 database_data.notification_id =
68 database_data_proto.notification_id();
69 database_data.origin = GURL(database_data_proto.origin());
70 database_data.service_worker_registration_id =
71 database_data_proto.service_worker_registration_id();
72 database_data.notification_data = notification_data;
73
74 return database_data;
75 }
76
77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698