| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/notifications/notification_database_data_conversions.h
" | 5 #include "content/browser/notifications/notification_database_data_conversions.h
" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/browser/notifications/notification_database_data.pb.h" | 9 #include "content/browser/notifications/notification_database_data.pb.h" |
| 10 #include "content/public/browser/notification_database_data.h" | 10 #include "content/public/browser/notification_database_data.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 payload.direction() == | 33 payload.direction() == |
| 34 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT ? | 34 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT ? |
| 35 PlatformNotificationData::NotificationDirectionRightToLeft : | 35 PlatformNotificationData::NotificationDirectionRightToLeft : |
| 36 PlatformNotificationData::NotificationDirectionLeftToRight; | 36 PlatformNotificationData::NotificationDirectionLeftToRight; |
| 37 notification_data->lang = payload.lang(); | 37 notification_data->lang = payload.lang(); |
| 38 notification_data->body = base::UTF8ToUTF16(payload.body()); | 38 notification_data->body = base::UTF8ToUTF16(payload.body()); |
| 39 notification_data->tag = payload.tag(); | 39 notification_data->tag = payload.tag(); |
| 40 notification_data->icon = GURL(payload.icon()); | 40 notification_data->icon = GURL(payload.icon()); |
| 41 notification_data->silent = payload.silent(); | 41 notification_data->silent = payload.silent(); |
| 42 | 42 |
| 43 if (payload.data().length()) { | |
| 44 notification_data->data.assign(payload.data().begin(), | |
| 45 payload.data().end()); | |
| 46 } | |
| 47 | |
| 48 return true; | 43 return true; |
| 49 } | 44 } |
| 50 | 45 |
| 51 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, | 46 bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, |
| 52 std::string* output) { | 47 std::string* output) { |
| 53 DCHECK(output); | 48 DCHECK(output); |
| 54 | 49 |
| 55 scoped_ptr<NotificationDatabaseDataProto::NotificationData> payload( | 50 scoped_ptr<NotificationDatabaseDataProto::NotificationData> payload( |
| 56 new NotificationDatabaseDataProto::NotificationData()); | 51 new NotificationDatabaseDataProto::NotificationData()); |
| 57 | 52 |
| 58 const PlatformNotificationData& notification_data = input.notification_data; | 53 const PlatformNotificationData& notification_data = input.notification_data; |
| 59 | 54 |
| 60 payload->set_title(base::UTF16ToUTF8(notification_data.title)); | 55 payload->set_title(base::UTF16ToUTF8(notification_data.title)); |
| 61 payload->set_direction( | 56 payload->set_direction( |
| 62 notification_data.direction == | 57 notification_data.direction == |
| 63 PlatformNotificationData::NotificationDirectionRightToLeft ? | 58 PlatformNotificationData::NotificationDirectionRightToLeft ? |
| 64 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT : | 59 NotificationDatabaseDataProto::NotificationData::RIGHT_TO_LEFT : |
| 65 NotificationDatabaseDataProto::NotificationData::LEFT_TO_RIGHT); | 60 NotificationDatabaseDataProto::NotificationData::LEFT_TO_RIGHT); |
| 66 payload->set_lang(notification_data.lang); | 61 payload->set_lang(notification_data.lang); |
| 67 payload->set_body(base::UTF16ToUTF8(notification_data.body)); | 62 payload->set_body(base::UTF16ToUTF8(notification_data.body)); |
| 68 payload->set_tag(notification_data.tag); | 63 payload->set_tag(notification_data.tag); |
| 69 payload->set_icon(notification_data.icon.spec()); | 64 payload->set_icon(notification_data.icon.spec()); |
| 70 payload->set_silent(notification_data.silent); | 65 payload->set_silent(notification_data.silent); |
| 71 | 66 |
| 72 if (notification_data.data.size()) { | |
| 73 payload->set_data(¬ification_data.data.front(), | |
| 74 notification_data.data.size()); | |
| 75 } | |
| 76 | |
| 77 NotificationDatabaseDataProto message; | 67 NotificationDatabaseDataProto message; |
| 78 message.set_notification_id(input.notification_id); | 68 message.set_notification_id(input.notification_id); |
| 79 message.set_origin(input.origin.spec()); | 69 message.set_origin(input.origin.spec()); |
| 80 message.set_service_worker_registration_id( | 70 message.set_service_worker_registration_id( |
| 81 input.service_worker_registration_id); | 71 input.service_worker_registration_id); |
| 82 message.set_allocated_notification_data(payload.release()); | 72 message.set_allocated_notification_data(payload.release()); |
| 83 | 73 |
| 84 return message.SerializeToString(output); | 74 return message.SerializeToString(output); |
| 85 } | 75 } |
| 86 | 76 |
| 87 } // namespace content | 77 } // namespace content |
| OLD | NEW |