OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/push_messaging/push_messaging_service_impl.h" | 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 app_identifier.service_worker_registration_id(), | 210 app_identifier.service_worker_registration_id(), |
211 message, message_handled_closure, | 211 message, message_handled_closure, |
212 content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED); | 212 content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED); |
213 return; | 213 return; |
214 } | 214 } |
215 | 215 |
216 rappor::SampleDomainAndRegistryFromGURL( | 216 rappor::SampleDomainAndRegistryFromGURL( |
217 g_browser_process->rappor_service(), | 217 g_browser_process->rappor_service(), |
218 "PushMessaging.MessageReceived.Origin", app_identifier.origin()); | 218 "PushMessaging.MessageReceived.Origin", app_identifier.origin()); |
219 | 219 |
220 std::string data; | 220 // The payload of a push message can be valid with content, valid with empty |
| 221 // content, or null. Only set the payload data if it is non-null. |
| 222 content::PushEventPayload payload; |
221 if (AreMessagePayloadsEnabled() && message.decrypted) | 223 if (AreMessagePayloadsEnabled() && message.decrypted) |
222 data = message.raw_data; | 224 payload.setData(message.raw_data); |
223 | 225 |
224 // Dispatch the message to the appropriate Service Worker. | 226 // Dispatch the message to the appropriate Service Worker. |
225 content::BrowserContext::DeliverPushMessage( | 227 content::BrowserContext::DeliverPushMessage( |
226 profile_, app_identifier.origin(), | 228 profile_, app_identifier.origin(), |
227 app_identifier.service_worker_registration_id(), data, | 229 app_identifier.service_worker_registration_id(), payload, |
228 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, | 230 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, |
229 weak_factory_.GetWeakPtr(), app_identifier.app_id(), | 231 weak_factory_.GetWeakPtr(), app_identifier.app_id(), |
230 app_identifier.origin(), | 232 app_identifier.origin(), |
231 app_identifier.service_worker_registration_id(), message, | 233 app_identifier.service_worker_registration_id(), message, |
232 message_handled_closure)); | 234 message_handled_closure)); |
233 | 235 |
234 // Inform tests observing message dispatching about the event. | 236 // Inform tests observing message dispatching about the event. |
235 if (!message_dispatched_callback_for_testing_.is_null()) { | 237 if (!message_dispatched_callback_for_testing_.is_null()) { |
236 message_dispatched_callback_for_testing_.Run( | 238 message_dispatched_callback_for_testing_.Run( |
237 app_id, app_identifier.origin(), | 239 app_id, app_identifier.origin(), |
238 app_identifier.service_worker_registration_id(), data); | 240 app_identifier.service_worker_registration_id(), payload); |
239 } | 241 } |
240 } | 242 } |
241 | 243 |
242 void PushMessagingServiceImpl::DeliverMessageCallback( | 244 void PushMessagingServiceImpl::DeliverMessageCallback( |
243 const std::string& app_id, | 245 const std::string& app_id, |
244 const GURL& requesting_origin, | 246 const GURL& requesting_origin, |
245 int64_t service_worker_registration_id, | 247 int64_t service_worker_registration_id, |
246 const gcm::IncomingMessage& message, | 248 const gcm::IncomingMessage& message, |
247 const base::Closure& message_handled_closure, | 249 const base::Closure& message_handled_closure, |
248 content::PushDeliveryStatus status) { | 250 content::PushDeliveryStatus status) { |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 switches::kEnableExperimentalWebPlatformFeatures); | 773 switches::kEnableExperimentalWebPlatformFeatures); |
772 } | 774 } |
773 | 775 |
774 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { | 776 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { |
775 gcm::GCMProfileService* gcm_profile_service = | 777 gcm::GCMProfileService* gcm_profile_service = |
776 gcm::GCMProfileServiceFactory::GetForProfile(profile_); | 778 gcm::GCMProfileServiceFactory::GetForProfile(profile_); |
777 CHECK(gcm_profile_service); | 779 CHECK(gcm_profile_service); |
778 CHECK(gcm_profile_service->driver()); | 780 CHECK(gcm_profile_service->driver()); |
779 return gcm_profile_service->driver(); | 781 return gcm_profile_service->driver(); |
780 } | 782 } |
OLD | NEW |