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