Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_NAVIGAOR_CONNECT_NAVIGATOR_CONNECT_SERVICE_WORKER_SERVIC E_FACTORY_H_ |
| 6 #define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_NAVIGAOR_CONNECT_NAVIGATOR_CONNECT_SERVICE_WORKER_SERVIC E_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/memory/weak_ptr.h" | |
| 8 #include "content/common/service_worker/service_worker_status_code.h" | 11 #include "content/common/service_worker/service_worker_status_code.h" |
| 9 #include "content/public/browser/browser_message_filter.h" | 12 #include "content/public/browser/navigator_connect_service.h" |
| 10 | 13 #include "content/public/browser/navigator_connect_service_factory.h" |
| 11 class GURL; | |
| 12 | 14 |
| 13 namespace content { | 15 namespace content { |
| 14 | 16 |
| 15 struct CrossOriginServiceWorkerClient; | |
| 16 class NavigatorConnectContext; | |
| 17 class ServiceWorkerContextWrapper; | 17 class ServiceWorkerContextWrapper; |
| 18 class ServiceWorkerRegistration; | 18 class ServiceWorkerRegistration; |
| 19 | 19 |
| 20 // Receives navigator.connect connection attempts from a child process. | 20 // Service worker specific NavigatorConnectServiceFactory implementation. This |
| 21 // Attempts to find a service that serves the URL the connection is made to | 21 // class accepts all URLs (and thus has to be the first factory to be added to |
| 22 // and sets up the actual connection. | 22 // NavigatorConnectContext or no other factories will ever by used). |
| 23 // Constructed on the UI thread, but all other methods are called on the IO | 23 // Tries to find a service worker registration to handle the url being connected |
| 24 // thread. Typically there is one instance of this class for each renderer | 24 // to. |
| 25 // process, and this class lives at least as long as the renderer process is | 25 class NavigatorConnectServiceWorkerServiceFactory |
|
scheib
2015/01/23 22:03:58
:D
| |
| 26 // alive (since this class is refcounted it could outlive the renderer process | 26 : public NavigatorConnectServiceFactory { |
| 27 // if it is still handling a connection attempt). | |
| 28 class NavigatorConnectDispatcherHost : public BrowserMessageFilter { | |
| 29 public: | 27 public: |
| 30 NavigatorConnectDispatcherHost( | 28 explicit NavigatorConnectServiceWorkerServiceFactory( |
| 31 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, | 29 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
| 32 const scoped_refptr<NavigatorConnectContext>& navigator_connect_context); | 30 ~NavigatorConnectServiceWorkerServiceFactory() override; |
| 31 | |
| 32 // NavigatorConnectServiceFactory implementation. | |
| 33 bool HandlesUrl(const GURL& target_url) override; | |
| 34 void Connect(const NavigatorConnectClient& client, | |
| 35 const ConnectCallback& callback) override; | |
| 33 | 36 |
| 34 private: | 37 private: |
| 35 ~NavigatorConnectDispatcherHost() override; | |
| 36 | |
| 37 // BrowserMessageFilter implementation. | |
| 38 bool OnMessageReceived(const IPC::Message& message) override; | |
| 39 | |
| 40 // IPC Message handlers. | |
| 41 void OnConnect(int thread_id, | |
| 42 int request_id, | |
| 43 const CrossOriginServiceWorkerClient& client); | |
| 44 | |
| 45 // Callback called when the Service Worker context found (or didn't find) a | 38 // Callback called when the Service Worker context found (or didn't find) a |
| 46 // service worker registration to serve a particular URL. | 39 // service worker registration to serve a particular URL. |
| 47 void GotServiceWorkerRegistration( | 40 void GotServiceWorkerRegistration( |
| 48 int thread_id, | 41 const ConnectCallback& callback, |
| 49 int request_id, | 42 const NavigatorConnectClient& client, |
| 50 const CrossOriginServiceWorkerClient& client, | |
| 51 ServiceWorkerStatusCode status, | 43 ServiceWorkerStatusCode status, |
| 52 const scoped_refptr<ServiceWorkerRegistration>& registration); | 44 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 53 | 45 |
| 54 // Callback called when the service worker finished handling the cross origin | 46 // Callback called when the service worker finished handling the cross origin |
| 55 // connection event. | 47 // connection event. |
| 56 void OnConnectResult( | 48 void OnConnectResult( |
| 57 int thread_id, | 49 const ConnectCallback& callback, |
| 58 int request_id, | 50 const NavigatorConnectClient& client, |
| 59 const CrossOriginServiceWorkerClient& client, | |
| 60 const scoped_refptr<ServiceWorkerRegistration>& registration, | 51 const scoped_refptr<ServiceWorkerRegistration>& registration, |
| 61 ServiceWorkerStatusCode status, | 52 ServiceWorkerStatusCode status, |
| 62 bool accept_connection); | 53 bool accept_connection); |
| 63 | 54 |
| 64 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 55 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 65 scoped_refptr<NavigatorConnectContext> navigator_connect_context_; | 56 base::WeakPtrFactory<NavigatorConnectServiceWorkerServiceFactory> |
| 66 | 57 weak_factory_; |
| 67 DISALLOW_COPY_AND_ASSIGN(NavigatorConnectDispatcherHost); | |
| 68 }; | 58 }; |
| 69 | 59 |
| 70 } // namespace content | 60 } // namespace content |
| 71 | 61 |
| 72 #endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_DISPATCHER_HOST_H _ | 62 #endif // CONTENT_BROWSER_NAVIGAOR_CONNECT_NAVIGATOR_CONNECT_SERVICE_WORKER_SER VICE_FACTORY_H_ |
| OLD | NEW |