Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.h

Issue 261533003: Populate .current when navigator.serviceWorker is accessed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 9
10 #include "base/id_map.h" 10 #include "base/id_map.h"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 namespace IPC { 24 namespace IPC {
25 class Message; 25 class Message;
26 } 26 }
27 27
28 namespace content { 28 namespace content {
29 29
30 class ServiceWorkerMessageFilter; 30 class ServiceWorkerMessageFilter;
31 struct ServiceWorkerObjectInfo; 31 struct ServiceWorkerObjectInfo;
32 class ServiceWorkerProviderContext;
32 class ThreadSafeSender; 33 class ThreadSafeSender;
33 class WebServiceWorkerImpl; 34 class WebServiceWorkerImpl;
34 35
35 // This class manages communication with the browser process about 36 // This class manages communication with the browser process about
36 // registration of the service worker, exposed to renderer and worker 37 // registration of the service worker, exposed to renderer and worker
37 // scripts through methods like navigator.registerServiceWorker(). 38 // scripts through methods like navigator.registerServiceWorker().
38 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { 39 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
39 public: 40 public:
40 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); 41 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender);
41 virtual ~ServiceWorkerDispatcher(); 42 virtual ~ServiceWorkerDispatcher();
42 43
43 void OnMessageReceived(const IPC::Message& msg); 44 void OnMessageReceived(const IPC::Message& msg);
44 bool Send(IPC::Message* msg); 45 bool Send(IPC::Message* msg);
45 46
46 // Corresponds to navigator.serviceWorker.register() 47 // Corresponds to navigator.serviceWorker.register()
47 void RegisterServiceWorker( 48 void RegisterServiceWorker(
48 int provider_id, 49 int provider_id,
49 const GURL& pattern, 50 const GURL& pattern,
50 const GURL& script_url, 51 const GURL& script_url,
51 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks); 52 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
52 // Corresponds to navigator.serviceWorker.unregister() 53 // Corresponds to navigator.serviceWorker.unregister()
53 void UnregisterServiceWorker( 54 void UnregisterServiceWorker(
54 int provider_id, 55 int provider_id,
55 const GURL& pattern, 56 const GURL& pattern,
56 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks); 57 blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
57 58
59 // Called when a new provider context for a document is created. Usually
60 // this happens when a new document is being loaded, and is called much
61 // earlier than AddScriptClient.
62 // (This is attached only to the document thread's ServiceWorkerDispatcher)
63 void AddProviderContext(ServiceWorkerProviderContext* provider_context);
64 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context);
65
58 // Called when navigator.serviceWorker is instantiated or detached 66 // Called when navigator.serviceWorker is instantiated or detached
59 // for a document whose provider can be identified by |provider_id|. 67 // for a document whose provider can be identified by |provider_id|.
60 void AddScriptClient(int provider_id, 68 void AddScriptClient(int provider_id,
61 blink::WebServiceWorkerProviderClient* client); 69 blink::WebServiceWorkerProviderClient* client);
62 void RemoveScriptClient(int provider_id); 70 void RemoveScriptClient(int provider_id);
63 71
64 // |thread_safe_sender| needs to be passed in because if the call leads to 72 // |thread_safe_sender| needs to be passed in because if the call leads to
65 // construction it will be needed. 73 // construction it will be needed.
66 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( 74 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance(
67 ThreadSafeSender* thread_safe_sender); 75 ThreadSafeSender* thread_safe_sender);
68 76
69 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new 77 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new
70 // instance if thread-local instance doesn't exist. 78 // instance if thread-local instance doesn't exist.
71 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); 79 static ServiceWorkerDispatcher* GetThreadSpecificInstance();
72 80
73 private: 81 private:
74 typedef IDMap<blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks, 82 typedef IDMap<blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks,
75 IDMapOwnPointer> CallbackMap; 83 IDMapOwnPointer> CallbackMap;
76 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; 84 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap;
77 typedef std::map<int, WebServiceWorkerImpl*> ServiceWorkerMap; 85 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap;
86 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap;
87 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap;
78 88
79 friend class WebServiceWorkerImpl; 89 friend class WebServiceWorkerImpl;
80 90
81 // WorkerTaskRunner::Observer implementation. 91 // WorkerTaskRunner::Observer implementation.
82 virtual void OnWorkerRunLoopStopped() OVERRIDE; 92 virtual void OnWorkerRunLoopStopped() OVERRIDE;
83 93
84 void OnRegistered(int thread_id, 94 void OnRegistered(int thread_id,
85 int request_id, 95 int request_id,
86 const ServiceWorkerObjectInfo& info); 96 const ServiceWorkerObjectInfo& info);
87 void OnUnregistered(int thread_id, 97 void OnUnregistered(int thread_id,
88 int request_id); 98 int request_id);
89 void OnRegistrationError(int thread_id, 99 void OnRegistrationError(int thread_id,
90 int request_id, 100 int request_id,
91 blink::WebServiceWorkerError::ErrorType error_type, 101 blink::WebServiceWorkerError::ErrorType error_type,
92 const base::string16& message); 102 const base::string16& message);
93 void OnServiceWorkerStateChanged(int thread_id, 103 void OnServiceWorkerStateChanged(int thread_id,
94 int handle_id, 104 int handle_id,
95 blink::WebServiceWorkerState state); 105 blink::WebServiceWorkerState state);
96 void OnSetCurrentServiceWorker(int thread_id, 106 void OnSetCurrentServiceWorker(int thread_id,
97 int provider_id, 107 int provider_id,
98 const ServiceWorkerObjectInfo& info); 108 const ServiceWorkerObjectInfo& info);
99 109
100 // Keeps map from handle_id to ServiceWorker object. 110 // Keeps map from handle_id to ServiceWorker object.
101 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); 111 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker);
102 void RemoveServiceWorker(int handle_id); 112 void RemoveServiceWorker(int handle_id);
103 113
104 CallbackMap pending_callbacks_; 114 CallbackMap pending_callbacks_;
105 ScriptClientMap script_clients_; 115 ScriptClientMap script_clients_;
106 ServiceWorkerMap service_workers_; 116 ProviderContextMap provider_contexts_;
117 WorkerObjectMap service_workers_;
118
119 // A map for ServiceWorkers that are associated to a particular document
120 // (e.g. as .current).
121 WorkerToProviderMap worker_to_provider_;
107 122
108 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 123 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
109 124
110 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); 125 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher);
111 }; 126 };
112 127
113 } // namespace content 128 } // namespace content
114 129
115 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ 130 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698