Chromium Code Reviews| 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 if (AreMessagePayloadsEnabled() && message.decrypted) | 221 // content, or null. Only set the payload data if it is non-null. |
| 222 data = message.raw_data; | 222 content::PushEventPayload payload; |
| 223 if (AreMessagePayloadsEnabled() && message.decrypted) { | |
| 224 payload.setData(message.raw_data); | |
|
Peter Beverloo
2016/01/25 17:39:06
nit: we don't use curly brackets for one-line cond
harkness
2016/01/26 12:07:19
Done.
| |
| 225 } | |
| 223 | 226 |
| 224 // Dispatch the message to the appropriate Service Worker. | 227 // Dispatch the message to the appropriate Service Worker. |
| 225 content::BrowserContext::DeliverPushMessage( | 228 content::BrowserContext::DeliverPushMessage( |
| 226 profile_, app_identifier.origin(), | 229 profile_, app_identifier.origin(), |
| 227 app_identifier.service_worker_registration_id(), data, | 230 app_identifier.service_worker_registration_id(), payload, |
| 228 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, | 231 base::Bind(&PushMessagingServiceImpl::DeliverMessageCallback, |
| 229 weak_factory_.GetWeakPtr(), app_identifier.app_id(), | 232 weak_factory_.GetWeakPtr(), app_identifier.app_id(), |
| 230 app_identifier.origin(), | 233 app_identifier.origin(), |
| 231 app_identifier.service_worker_registration_id(), message, | 234 app_identifier.service_worker_registration_id(), message, |
| 232 message_handled_closure)); | 235 message_handled_closure)); |
| 233 | 236 |
| 234 // Inform tests observing message dispatching about the event. | 237 // Inform tests observing message dispatching about the event. |
| 235 if (!message_dispatched_callback_for_testing_.is_null()) { | 238 if (!message_dispatched_callback_for_testing_.is_null()) { |
| 236 message_dispatched_callback_for_testing_.Run( | 239 message_dispatched_callback_for_testing_.Run( |
| 237 app_id, app_identifier.origin(), | 240 app_id, app_identifier.origin(), |
| 238 app_identifier.service_worker_registration_id(), data); | 241 app_identifier.service_worker_registration_id(), payload); |
| 239 } | 242 } |
| 240 } | 243 } |
| 241 | 244 |
| 242 void PushMessagingServiceImpl::DeliverMessageCallback( | 245 void PushMessagingServiceImpl::DeliverMessageCallback( |
| 243 const std::string& app_id, | 246 const std::string& app_id, |
| 244 const GURL& requesting_origin, | 247 const GURL& requesting_origin, |
| 245 int64_t service_worker_registration_id, | 248 int64_t service_worker_registration_id, |
| 246 const gcm::IncomingMessage& message, | 249 const gcm::IncomingMessage& message, |
| 247 const base::Closure& message_handled_closure, | 250 const base::Closure& message_handled_closure, |
| 248 content::PushDeliveryStatus status) { | 251 content::PushDeliveryStatus status) { |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 switches::kEnableExperimentalWebPlatformFeatures); | 774 switches::kEnableExperimentalWebPlatformFeatures); |
| 772 } | 775 } |
| 773 | 776 |
| 774 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { | 777 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { |
| 775 gcm::GCMProfileService* gcm_profile_service = | 778 gcm::GCMProfileService* gcm_profile_service = |
| 776 gcm::GCMProfileServiceFactory::GetForProfile(profile_); | 779 gcm::GCMProfileServiceFactory::GetForProfile(profile_); |
| 777 CHECK(gcm_profile_service); | 780 CHECK(gcm_profile_service); |
| 778 CHECK(gcm_profile_service->driver()); | 781 CHECK(gcm_profile_service->driver()); |
| 779 return gcm_profile_service->driver(); | 782 return gcm_profile_service->driver(); |
| 780 } | 783 } |
| OLD | NEW |