| 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 #ifndef CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_ROUTER_H_ | 5 #ifndef CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_ROUTER_H_ |
| 6 #define CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_ROUTER_H_ | 6 #define CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_ROUTER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/macros.h" |
| 8 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 10 #include "content/common/service_worker/service_worker_status_code.h" | 13 #include "content/common/service_worker/service_worker_status_code.h" |
| 11 #include "content/public/common/push_messaging_status.h" | 14 #include "content/public/common/push_messaging_status.h" |
| 12 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 13 | 16 |
| 14 namespace content { | 17 namespace content { |
| 15 | 18 |
| 16 class BrowserContext; | 19 class BrowserContext; |
| 17 class ServiceWorkerContextWrapper; | 20 class ServiceWorkerContextWrapper; |
| 18 class ServiceWorkerRegistration; | 21 class ServiceWorkerRegistration; |
| 19 | 22 |
| 20 class PushMessagingRouter { | 23 class PushMessagingRouter { |
| 21 public: | 24 public: |
| 22 typedef base::Callback<void(PushDeliveryStatus)> DeliverMessageCallback; | 25 typedef base::Callback<void(PushDeliveryStatus)> DeliverMessageCallback; |
| 23 | 26 |
| 24 // Delivers a push message with |data| to the Service Worker identified by | 27 // Delivers a push message with |data| to the Service Worker identified by |
| 25 // |origin| and |service_worker_registration_id|. Must be called on the UI | 28 // |origin| and |service_worker_registration_id|. Must be called on the UI |
| 26 // thread. | 29 // thread. |
| 27 static void DeliverMessage( | 30 static void DeliverMessage( |
| 28 BrowserContext* browser_context, | 31 BrowserContext* browser_context, |
| 29 const GURL& origin, | 32 const GURL& origin, |
| 30 int64 service_worker_registration_id, | 33 int64_t service_worker_registration_id, |
| 31 const std::string& data, | 34 const std::string& data, |
| 32 const DeliverMessageCallback& deliver_message_callback); | 35 const DeliverMessageCallback& deliver_message_callback); |
| 33 | 36 |
| 34 private: | 37 private: |
| 35 // Attempts to find a Service Worker registration so that a push event can be | 38 // Attempts to find a Service Worker registration so that a push event can be |
| 36 // dispatched. Must be called on the IO thread. | 39 // dispatched. Must be called on the IO thread. |
| 37 static void FindServiceWorkerRegistration( | 40 static void FindServiceWorkerRegistration( |
| 38 const GURL& origin, | 41 const GURL& origin, |
| 39 int64 service_worker_registration_id, | 42 int64_t service_worker_registration_id, |
| 40 const std::string& data, | 43 const std::string& data, |
| 41 const DeliverMessageCallback& deliver_message_callback, | 44 const DeliverMessageCallback& deliver_message_callback, |
| 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); | 45 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
| 43 | 46 |
| 44 // If a registration was successfully retrieved, dispatches a push event with | 47 // If a registration was successfully retrieved, dispatches a push event with |
| 45 // |data| on the Service Worker identified by |service_worker_registration|. | 48 // |data| on the Service Worker identified by |service_worker_registration|. |
| 46 // Must be called on the IO thread. | 49 // Must be called on the IO thread. |
| 47 static void FindServiceWorkerRegistrationCallback( | 50 static void FindServiceWorkerRegistrationCallback( |
| 48 const std::string& data, | 51 const std::string& data, |
| 49 const DeliverMessageCallback& deliver_message_callback, | 52 const DeliverMessageCallback& deliver_message_callback, |
| 50 ServiceWorkerStatusCode service_worker_status, | 53 ServiceWorkerStatusCode service_worker_status, |
| 51 const scoped_refptr<ServiceWorkerRegistration>& | 54 const scoped_refptr<ServiceWorkerRegistration>& |
| 52 service_worker_registration); | 55 service_worker_registration); |
| 53 | 56 |
| 54 // Gets called asynchronously after the Service Worker has dispatched the push | 57 // Gets called asynchronously after the Service Worker has dispatched the push |
| 55 // event. Must be called on the IO thread. | 58 // event. Must be called on the IO thread. |
| 56 static void DeliverMessageEnd( | 59 static void DeliverMessageEnd( |
| 57 const DeliverMessageCallback& deliver_message_callback, | 60 const DeliverMessageCallback& deliver_message_callback, |
| 58 const scoped_refptr<ServiceWorkerRegistration>& | 61 const scoped_refptr<ServiceWorkerRegistration>& |
| 59 service_worker_registration, | 62 service_worker_registration, |
| 60 ServiceWorkerStatusCode service_worker_status); | 63 ServiceWorkerStatusCode service_worker_status); |
| 61 | 64 |
| 62 DISALLOW_IMPLICIT_CONSTRUCTORS(PushMessagingRouter); | 65 DISALLOW_IMPLICIT_CONSTRUCTORS(PushMessagingRouter); |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 } // namespace content | 68 } // namespace content |
| 66 | 69 |
| 67 #endif // CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_ROUTER_H_ | 70 #endif // CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_ROUTER_H_ |
| OLD | NEW |