| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 struct ServiceWorkerObjectInfo; | 32 struct ServiceWorkerObjectInfo; |
| 33 class ServiceWorkerProviderContext; | 33 class ServiceWorkerProviderContext; |
| 34 class ThreadSafeSender; | 34 class ThreadSafeSender; |
| 35 class WebServiceWorkerImpl; | 35 class WebServiceWorkerImpl; |
| 36 | 36 |
| 37 // This class manages communication with the browser process about | 37 // This class manages communication with the browser process about |
| 38 // registration of the service worker, exposed to renderer and worker | 38 // registration of the service worker, exposed to renderer and worker |
| 39 // scripts through methods like navigator.registerServiceWorker(). | 39 // scripts through methods like navigator.registerServiceWorker(). |
| 40 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { | 40 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { |
| 41 public: | 41 public: |
| 42 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
| 43 WebServiceWorkerRegistrationCallbacks; |
| 44 |
| 42 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); | 45 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); |
| 43 virtual ~ServiceWorkerDispatcher(); | 46 virtual ~ServiceWorkerDispatcher(); |
| 44 | 47 |
| 45 void OnMessageReceived(const IPC::Message& msg); | 48 void OnMessageReceived(const IPC::Message& msg); |
| 46 bool Send(IPC::Message* msg); | 49 bool Send(IPC::Message* msg); |
| 47 | 50 |
| 48 // Corresponds to navigator.serviceWorker.register() | 51 // Corresponds to navigator.serviceWorker.register() |
| 49 void RegisterServiceWorker( | 52 void RegisterServiceWorker( |
| 50 int provider_id, | 53 int provider_id, |
| 51 const GURL& pattern, | 54 const GURL& pattern, |
| 52 const GURL& script_url, | 55 const GURL& script_url, |
| 53 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks); | 56 WebServiceWorkerRegistrationCallbacks* callbacks); |
| 54 // Corresponds to navigator.serviceWorker.unregister() | 57 // Corresponds to navigator.serviceWorker.unregister() |
| 55 void UnregisterServiceWorker( | 58 void UnregisterServiceWorker( |
| 56 int provider_id, | 59 int provider_id, |
| 57 const GURL& pattern, | 60 const GURL& pattern, |
| 58 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks); | 61 WebServiceWorkerRegistrationCallbacks* callbacks); |
| 59 | 62 |
| 60 // Called when a new provider context for a document is created. Usually | 63 // Called when a new provider context for a document is created. Usually |
| 61 // this happens when a new document is being loaded, and is called much | 64 // this happens when a new document is being loaded, and is called much |
| 62 // earlier than AddScriptClient. | 65 // earlier than AddScriptClient. |
| 63 // (This is attached only to the document thread's ServiceWorkerDispatcher) | 66 // (This is attached only to the document thread's ServiceWorkerDispatcher) |
| 64 void AddProviderContext(ServiceWorkerProviderContext* provider_context); | 67 void AddProviderContext(ServiceWorkerProviderContext* provider_context); |
| 65 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); | 68 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); |
| 66 | 69 |
| 67 // Called when navigator.serviceWorker is instantiated or detached | 70 // Called when navigator.serviceWorker is instantiated or detached |
| 68 // for a document whose provider can be identified by |provider_id|. | 71 // for a document whose provider can be identified by |provider_id|. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 89 // |thread_safe_sender| needs to be passed in because if the call leads to | 92 // |thread_safe_sender| needs to be passed in because if the call leads to |
| 90 // construction it will be needed. | 93 // construction it will be needed. |
| 91 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( | 94 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( |
| 92 ThreadSafeSender* thread_safe_sender); | 95 ThreadSafeSender* thread_safe_sender); |
| 93 | 96 |
| 94 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new | 97 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new |
| 95 // instance if thread-local instance doesn't exist. | 98 // instance if thread-local instance doesn't exist. |
| 96 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 99 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
| 97 | 100 |
| 98 private: | 101 private: |
| 99 typedef IDMap<blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks, | 102 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
| 100 IDMapOwnPointer> CallbackMap; | 103 IDMapOwnPointer> CallbackMap; |
| 101 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; | 104 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; |
| 102 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 105 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
| 103 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 106 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
| 104 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 107 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
| 105 | 108 |
| 106 friend class WebServiceWorkerImpl; | 109 friend class WebServiceWorkerImpl; |
| 107 | 110 |
| 108 // WorkerTaskRunner::Observer implementation. | 111 // WorkerTaskRunner::Observer implementation. |
| 109 virtual void OnWorkerRunLoopStopped() OVERRIDE; | 112 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 WorkerToProviderMap worker_to_provider_; | 155 WorkerToProviderMap worker_to_provider_; |
| 153 | 156 |
| 154 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 157 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 155 | 158 |
| 156 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 159 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
| 157 }; | 160 }; |
| 158 | 161 |
| 159 } // namespace content | 162 } // namespace content |
| 160 | 163 |
| 161 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 164 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| OLD | NEW |