| OLD | NEW |
| (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/logging.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "content/browser/notifications/notification_database_data.pb.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 NotificationDatabaseData::NotificationDatabaseData() | |
| 14 : notification_id(0), | |
| 15 service_worker_registration_id(0) { | |
| 16 } | |
| 17 | |
| 18 NotificationDatabaseData::~NotificationDatabaseData() {} | |
| 19 | |
| 20 bool NotificationDatabaseData::ParseFromString(const std::string& input) { | |
| 21 NotificationDatabaseDataProto message; | |
| 22 if (!message.ParseFromString(input)) | |
| 23 return false; | |
| 24 | |
| 25 notification_id = message.notification_id(); | |
| 26 origin = GURL(message.origin()); | |
| 27 service_worker_registration_id = message.service_worker_registration_id(); | |
| 28 | |
| 29 const NotificationDatabaseDataProto::NotificationData& payload = | |
| 30 message.notification_data(); | |
| 31 | |
| 32 notification_data.title = base::UTF8ToUTF16(payload.title()); | |
| 33 notification_data.direction = | |
| 34 payload.direction() == | |
| 35 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT ? | |
| 36 PlatformNotificationData::NotificationDirectionRightToLeft : | |
| 37 PlatformNotificationData::NotificationDirectionLeftToRight; | |
| 38 notification_data.lang = payload.lang(); | |
| 39 notification_data.body = base::UTF8ToUTF16(payload.body()); | |
| 40 notification_data.tag = payload.tag(); | |
| 41 notification_data.icon = GURL(payload.icon()); | |
| 42 notification_data.silent = payload.silent(); | |
| 43 | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 bool NotificationDatabaseData::SerializeToString(std::string* output) const { | |
| 48 DCHECK(output); | |
| 49 | |
| 50 scoped_ptr<NotificationDatabaseDataProto::NotificationData> payload( | |
| 51 new NotificationDatabaseDataProto::NotificationData()); | |
| 52 payload->set_title(base::UTF16ToUTF8(notification_data.title)); | |
| 53 payload->set_direction( | |
| 54 notification_data.direction == | |
| 55 PlatformNotificationData::NotificationDirectionRightToLeft ? | |
| 56 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT : | |
| 57 NotificationDatabaseDataProto::NotificationData::LEFT_TO_RIGHT); | |
| 58 payload->set_lang(notification_data.lang); | |
| 59 payload->set_body(base::UTF16ToUTF8(notification_data.body)); | |
| 60 payload->set_tag(notification_data.tag); | |
| 61 payload->set_icon(notification_data.icon.spec()); | |
| 62 payload->set_silent(notification_data.silent); | |
| 63 | |
| 64 NotificationDatabaseDataProto message; | |
| 65 message.set_notification_id(notification_id); | |
| 66 message.set_origin(origin.spec()); | |
| 67 message.set_service_worker_registration_id( | |
| 68 service_worker_registration_id); | |
| 69 message.set_allocated_notification_data(payload.release()); | |
| 70 | |
| 71 return message.SerializeToString(output); | |
| 72 } | |
| 73 | |
| 74 } // namespace content | |
| OLD | NEW |