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