Index: content/browser/notifications/notification_database_data.cc |
diff --git a/content/browser/notifications/notification_database_data.cc b/content/browser/notifications/notification_database_data.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3510c07d304a1c62938ee6d22477028adcc4eb0b |
--- /dev/null |
+++ b/content/browser/notifications/notification_database_data.cc |
@@ -0,0 +1,77 @@ |
+// Copyright 2015 The Chromium 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 "content/browser/notifications/notification_database_data.h" |
+ |
+#include "base/strings/utf_string_conversions.h" |
+#include "content/browser/notifications/notification_database_data.pb.h" |
+ |
+namespace content { |
+ |
+NotificationDatabaseData::NotificationDatabaseData() |
+ : notification_id(0), |
+ service_worker_registration_id(0) { |
+} |
+ |
+NotificationDatabaseData::~NotificationDatabaseData() {} |
+ |
+NotificationDatabaseDataProto ToNotificationDatabaseDataProto( |
+ const NotificationDatabaseData& database_data) { |
+ const PlatformNotificationData& notification_data = |
+ database_data.notification_data; |
+ |
+ scoped_ptr<NotificationDatabaseDataProto::NotificationData> payload( |
+ new NotificationDatabaseDataProto::NotificationData()); |
+ payload->set_title(base::UTF16ToUTF8(notification_data.title)); |
+ payload->set_direction( |
+ notification_data.direction == |
+ PlatformNotificationData::NotificationDirectionRightToLeft ? |
+ NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT : |
+ NotificationDatabaseDataProto::NotificationData::LEFT_TO_RIGHT); |
+ payload->set_lang(notification_data.lang); |
+ payload->set_body(base::UTF16ToUTF8(notification_data.body)); |
+ payload->set_tag(notification_data.tag); |
+ payload->set_icon(notification_data.icon.spec()); |
+ payload->set_silent(notification_data.silent); |
+ |
+ NotificationDatabaseDataProto message; |
+ message.set_notification_id(database_data.notification_id); |
+ message.set_origin(database_data.origin.spec()); |
+ message.set_service_worker_registration_id( |
+ database_data.service_worker_registration_id); |
+ message.set_allocated_notification_data(payload.release()); |
+ |
+ return message; |
+} |
+ |
+NotificationDatabaseData ToNotificationDatabaseData( |
+ const NotificationDatabaseDataProto& database_data_proto) { |
+ const NotificationDatabaseDataProto::NotificationData& payload = |
+ database_data_proto.notification_data(); |
+ |
+ PlatformNotificationData notification_data; |
+ notification_data.title = base::UTF8ToUTF16(payload.title()); |
+ notification_data.direction = |
+ payload.direction() == |
+ NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT ? |
+ PlatformNotificationData::NotificationDirectionRightToLeft : |
+ PlatformNotificationData::NotificationDirectionLeftToRight; |
+ notification_data.lang = payload.lang(); |
+ notification_data.body = base::UTF8ToUTF16(payload.body()); |
+ notification_data.tag = payload.tag(); |
+ notification_data.icon = GURL(payload.icon()); |
+ notification_data.silent = payload.silent(); |
+ |
+ NotificationDatabaseData database_data; |
+ database_data.notification_id = |
+ database_data_proto.notification_id(); |
+ database_data.origin = GURL(database_data_proto.origin()); |
+ database_data.service_worker_registration_id = |
+ database_data_proto.service_worker_registration_id(); |
+ database_data.notification_data = notification_data; |
+ |
+ return database_data; |
+} |
+ |
+} // namespace content |