| 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 "base/time/time.h" |
| 9 #include "content/browser/notifications/notification_database_data.pb.h" | 10 #include "content/browser/notifications/notification_database_data.pb.h" |
| 10 #include "content/public/browser/notification_database_data.h" | 11 #include "content/public/browser/notification_database_data.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 bool DeserializeNotificationDatabaseData(const std::string& input, | 15 bool DeserializeNotificationDatabaseData(const std::string& input, |
| 15 NotificationDatabaseData* output) { | 16 NotificationDatabaseData* output) { |
| 16 DCHECK(output); | 17 DCHECK(output); |
| 17 | 18 |
| 18 NotificationDatabaseDataProto message; | 19 NotificationDatabaseDataProto message; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 48 notification_data->body = base::UTF8ToUTF16(payload.body()); | 49 notification_data->body = base::UTF8ToUTF16(payload.body()); |
| 49 notification_data->tag = payload.tag(); | 50 notification_data->tag = payload.tag(); |
| 50 notification_data->icon = GURL(payload.icon()); | 51 notification_data->icon = GURL(payload.icon()); |
| 51 | 52 |
| 52 if (payload.vibration_pattern().size() > 0) { | 53 if (payload.vibration_pattern().size() > 0) { |
| 53 notification_data->vibration_pattern.assign( | 54 notification_data->vibration_pattern.assign( |
| 54 payload.vibration_pattern().begin(), | 55 payload.vibration_pattern().begin(), |
| 55 payload.vibration_pattern().end()); | 56 payload.vibration_pattern().end()); |
| 56 } | 57 } |
| 57 | 58 |
| 59 notification_data->timestamp = base::Time::FromDoubleT(payload.timestamp()); |
| 58 notification_data->silent = payload.silent(); | 60 notification_data->silent = payload.silent(); |
| 59 notification_data->require_interaction = payload.require_interaction(); | 61 notification_data->require_interaction = payload.require_interaction(); |
| 60 | 62 |
| 61 if (payload.data().length()) { | 63 if (payload.data().length()) { |
| 62 notification_data->data.assign(payload.data().begin(), | 64 notification_data->data.assign(payload.data().begin(), |
| 63 payload.data().end()); | 65 payload.data().end()); |
| 64 } | 66 } |
| 65 | 67 |
| 66 for (const auto& payload_action : payload.actions()) { | 68 for (const auto& payload_action : payload.actions()) { |
| 67 PlatformNotificationAction action; | 69 PlatformNotificationAction action; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 102 } |
| 101 | 103 |
| 102 payload->set_lang(notification_data.lang); | 104 payload->set_lang(notification_data.lang); |
| 103 payload->set_body(base::UTF16ToUTF8(notification_data.body)); | 105 payload->set_body(base::UTF16ToUTF8(notification_data.body)); |
| 104 payload->set_tag(notification_data.tag); | 106 payload->set_tag(notification_data.tag); |
| 105 payload->set_icon(notification_data.icon.spec()); | 107 payload->set_icon(notification_data.icon.spec()); |
| 106 | 108 |
| 107 for (size_t i = 0; i < notification_data.vibration_pattern.size(); ++i) | 109 for (size_t i = 0; i < notification_data.vibration_pattern.size(); ++i) |
| 108 payload->add_vibration_pattern(notification_data.vibration_pattern[i]); | 110 payload->add_vibration_pattern(notification_data.vibration_pattern[i]); |
| 109 | 111 |
| 112 payload->set_timestamp(notification_data.timestamp.ToDoubleT()); |
| 110 payload->set_silent(notification_data.silent); | 113 payload->set_silent(notification_data.silent); |
| 111 payload->set_require_interaction(notification_data.require_interaction); | 114 payload->set_require_interaction(notification_data.require_interaction); |
| 112 | 115 |
| 113 if (notification_data.data.size()) { | 116 if (notification_data.data.size()) { |
| 114 payload->set_data(¬ification_data.data.front(), | 117 payload->set_data(¬ification_data.data.front(), |
| 115 notification_data.data.size()); | 118 notification_data.data.size()); |
| 116 } | 119 } |
| 117 | 120 |
| 118 for (const PlatformNotificationAction& action : notification_data.actions) { | 121 for (const PlatformNotificationAction& action : notification_data.actions) { |
| 119 NotificationDatabaseDataProto::NotificationAction* payload_action = | 122 NotificationDatabaseDataProto::NotificationAction* payload_action = |
| 120 payload->add_actions(); | 123 payload->add_actions(); |
| 121 payload_action->set_action(action.action); | 124 payload_action->set_action(action.action); |
| 122 payload_action->set_title(base::UTF16ToUTF8(action.title)); | 125 payload_action->set_title(base::UTF16ToUTF8(action.title)); |
| 123 } | 126 } |
| 124 | 127 |
| 125 NotificationDatabaseDataProto message; | 128 NotificationDatabaseDataProto message; |
| 126 message.set_notification_id(input.notification_id); | 129 message.set_notification_id(input.notification_id); |
| 127 message.set_origin(input.origin.spec()); | 130 message.set_origin(input.origin.spec()); |
| 128 message.set_service_worker_registration_id( | 131 message.set_service_worker_registration_id( |
| 129 input.service_worker_registration_id); | 132 input.service_worker_registration_id); |
| 130 message.set_allocated_notification_data(payload.release()); | 133 message.set_allocated_notification_data(payload.release()); |
| 131 | 134 |
| 132 return message.SerializeToString(output); | 135 return message.SerializeToString(output); |
| 133 } | 136 } |
| 134 | 137 |
| 135 } // namespace content | 138 } // namespace content |
| OLD | NEW |