Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_PUSH_MESSAGING_ROUTER_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_PUSH_MESSAGING_ROUTER_IMPL_H_ | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "content/common/service_worker/service_worker_status_code.h" | |
| 11 #include "content/public/browser/push_messaging_router.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 class BrowserContext; | |
| 16 class ServiceWorkerContextWrapper; | |
| 17 class ServiceWorkerRegistration; | |
| 18 struct PushMessagingApplicationId; | |
| 19 | |
| 20 class PushMessagingRouterImpl : public PushMessagingRouter { | |
| 21 public: | |
| 22 // PushMessagingRouter implementation. | |
| 23 virtual void SendMessage( | |
| 24 const PushMessagingApplicationId& application_id, | |
| 25 const std::string& data, | |
| 26 const SendMessageCallback& send_message_callback) OVERRIDE; | |
| 27 | |
| 28 explicit PushMessagingRouterImpl(BrowserContext* browser_context); | |
|
johnme
2014/07/23 14:25:23
I'd suggest to either make this constructor privat
Michael van Ouwerkerk
2014/07/23 16:57:52
The PushMessagingRouterImpl constructor does need
| |
| 29 virtual ~PushMessagingRouterImpl(); | |
| 30 | |
| 31 private: | |
| 32 // Attempts to find a Service Worker registration for |application_id| so that | |
| 33 // a message can be dispatched. Must be called on the IO thread. | |
| 34 void FindServiceWorkerRegistration( | |
| 35 const PushMessagingApplicationId& application_id, | |
| 36 const std::string& data, | |
| 37 const SendMessageCallback& send_message_callback, | |
| 38 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); | |
| 39 | |
| 40 // Sends the message if a registration was found. Must be called on the IO | |
| 41 // thread. | |
| 42 void FindServiceWorkerRegistrationCallback( | |
| 43 const PushMessagingApplicationId& application_id, | |
| 44 const std::string& data, | |
| 45 const SendMessageCallback& send_message_callback, | |
| 46 ServiceWorkerStatusCode service_worker_status, | |
| 47 const scoped_refptr<ServiceWorkerRegistration>& | |
| 48 service_worker_registration); | |
| 49 | |
| 50 // Sends a push message with |data| to the Service Worker identified by | |
| 51 // |service_worker_registration|. Must be called on the IO thread. | |
| 52 void DoSendMessage(const std::string& data, | |
| 53 const SendMessageCallback& send_message_callback, | |
| 54 const scoped_refptr<ServiceWorkerRegistration>& | |
| 55 service_worker_registration); | |
| 56 | |
| 57 // Gets called asynchronously after the Service Worker has dispatched the push | |
| 58 // event. Must be called on the IO thread. | |
| 59 void SendMessageEnd(const SendMessageCallback& send_message_callback, | |
| 60 const scoped_refptr<ServiceWorkerRegistration>& | |
| 61 service_worker_registration, | |
| 62 ServiceWorkerStatusCode service_worker_status); | |
| 63 | |
| 64 BrowserContext* browser_context_; // It indirectly owns this. | |
| 65 | |
| 66 base::WeakPtrFactory<PushMessagingRouterImpl> weak_factory_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(PushMessagingRouterImpl); | |
| 69 }; | |
| 70 | |
| 71 } // namespace content | |
| 72 | |
| 73 #endif // CONTENT_BROWSER_PUSH_MESSAGING_ROUTER_IMPL_H_ | |
| OLD | NEW |