| 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 "content/browser/push_messaging/push_messaging_router.h" | 5 #include "content/browser/push_messaging/push_messaging_router.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 BrowserThread::UI, FROM_HERE, | 26 BrowserThread::UI, FROM_HERE, |
| 27 base::Bind(deliver_message_callback, delivery_status)); | 27 base::Bind(deliver_message_callback, delivery_status)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 void PushMessagingRouter::DeliverMessage( | 33 void PushMessagingRouter::DeliverMessage( |
| 34 BrowserContext* browser_context, | 34 BrowserContext* browser_context, |
| 35 const GURL& origin, | 35 const GURL& origin, |
| 36 int64 service_worker_registration_id, | 36 int64_t service_worker_registration_id, |
| 37 const std::string& data, | 37 const std::string& data, |
| 38 const DeliverMessageCallback& deliver_message_callback) { | 38 const DeliverMessageCallback& deliver_message_callback) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 StoragePartition* partition = | 40 StoragePartition* partition = |
| 41 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | 41 BrowserContext::GetStoragePartitionForSite(browser_context, origin); |
| 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = | 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = |
| 43 static_cast<ServiceWorkerContextWrapper*>( | 43 static_cast<ServiceWorkerContextWrapper*>( |
| 44 partition->GetServiceWorkerContext()); | 44 partition->GetServiceWorkerContext()); |
| 45 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 46 BrowserThread::IO, FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
| 47 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistration, origin, | 47 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistration, origin, |
| 48 service_worker_registration_id, data, deliver_message_callback, | 48 service_worker_registration_id, data, deliver_message_callback, |
| 49 service_worker_context)); | 49 service_worker_context)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 void PushMessagingRouter::FindServiceWorkerRegistration( | 53 void PushMessagingRouter::FindServiceWorkerRegistration( |
| 54 const GURL& origin, | 54 const GURL& origin, |
| 55 int64 service_worker_registration_id, | 55 int64_t service_worker_registration_id, |
| 56 const std::string& data, | 56 const std::string& data, |
| 57 const DeliverMessageCallback& deliver_message_callback, | 57 const DeliverMessageCallback& deliver_message_callback, |
| 58 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | 58 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 60 // Try to acquire the registration from storage. If it's already live we'll | 60 // Try to acquire the registration from storage. If it's already live we'll |
| 61 // receive it right away. If not, it will be revived from storage. | 61 // receive it right away. If not, it will be revived from storage. |
| 62 service_worker_context->FindReadyRegistrationForId( | 62 service_worker_context->FindReadyRegistrationForId( |
| 63 service_worker_registration_id, origin, | 63 service_worker_registration_id, origin, |
| 64 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistrationCallback, | 64 base::Bind(&PushMessagingRouter::FindServiceWorkerRegistrationCallback, |
| 65 data, deliver_message_callback)); | 65 data, deliver_message_callback)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 case SERVICE_WORKER_ERROR_MAX_VALUE: | 132 case SERVICE_WORKER_ERROR_MAX_VALUE: |
| 133 NOTREACHED() << "Got unexpected error code: " << service_worker_status | 133 NOTREACHED() << "Got unexpected error code: " << service_worker_status |
| 134 << " " << ServiceWorkerStatusToString(service_worker_status); | 134 << " " << ServiceWorkerStatusToString(service_worker_status); |
| 135 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR; | 135 delivery_status = PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR; |
| 136 break; | 136 break; |
| 137 } | 137 } |
| 138 RunDeliverCallback(deliver_message_callback, delivery_status); | 138 RunDeliverCallback(deliver_message_callback, delivery_status); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace content | 141 } // namespace content |
| OLD | NEW |