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 #include "content/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
9 #include "content/child/service_worker/web_service_worker_impl.h" | 9 #include "content/child/service_worker/web_service_worker_impl.h" |
10 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 IPC_MESSAGE_UNHANDLED(handled = false) | 52 IPC_MESSAGE_UNHANDLED(handled = false) |
53 IPC_END_MESSAGE_MAP() | 53 IPC_END_MESSAGE_MAP() |
54 DCHECK(handled) << "Unhandled message:" << msg.type(); | 54 DCHECK(handled) << "Unhandled message:" << msg.type(); |
55 } | 55 } |
56 | 56 |
57 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { | 57 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { |
58 return thread_safe_sender_->Send(msg); | 58 return thread_safe_sender_->Send(msg); |
59 } | 59 } |
60 | 60 |
61 void ServiceWorkerDispatcher::RegisterServiceWorker( | 61 void ServiceWorkerDispatcher::RegisterServiceWorker( |
| 62 int provider_id, |
62 const GURL& pattern, | 63 const GURL& pattern, |
63 const GURL& script_url, | 64 const GURL& script_url, |
64 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { | 65 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { |
65 DCHECK(callbacks); | 66 DCHECK(callbacks); |
66 int request_id = pending_callbacks_.Add(callbacks); | 67 int request_id = pending_callbacks_.Add(callbacks); |
67 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 68 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
68 CurrentWorkerId(), request_id, pattern, script_url)); | 69 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
69 } | 70 } |
70 | 71 |
71 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 72 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| 73 int provider_id, |
72 const GURL& pattern, | 74 const GURL& pattern, |
73 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { | 75 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { |
74 DCHECK(callbacks); | 76 DCHECK(callbacks); |
75 int request_id = pending_callbacks_.Add(callbacks); | 77 int request_id = pending_callbacks_.Add(callbacks); |
76 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 78 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
77 CurrentWorkerId(), request_id, pattern)); | 79 CurrentWorkerId(), request_id, provider_id, pattern)); |
78 } | 80 } |
79 | 81 |
80 void ServiceWorkerDispatcher::AddScriptClient( | 82 void ServiceWorkerDispatcher::AddScriptClient( |
81 int provider_id, | 83 int provider_id, |
82 blink::WebServiceWorkerProviderClient* client) { | 84 blink::WebServiceWorkerProviderClient* client) { |
83 DCHECK(client); | 85 DCHECK(client); |
84 DCHECK(!ContainsKey(script_clients_, provider_id)); | 86 DCHECK(!ContainsKey(script_clients_, provider_id)); |
85 script_clients_[provider_id] = client; | 87 script_clients_[provider_id] = client; |
86 thread_safe_sender_->Send(new ServiceWorkerHostMsg_AddScriptClient( | 88 thread_safe_sender_->Send(new ServiceWorkerHostMsg_AddScriptClient( |
87 CurrentWorkerId(), provider_id)); | 89 CurrentWorkerId(), provider_id)); |
(...skipping 17 matching lines...) Expand all Loading... |
105 if (g_dispatcher_tls.Pointer()->Get()) | 107 if (g_dispatcher_tls.Pointer()->Get()) |
106 return g_dispatcher_tls.Pointer()->Get(); | 108 return g_dispatcher_tls.Pointer()->Get(); |
107 | 109 |
108 ServiceWorkerDispatcher* dispatcher = | 110 ServiceWorkerDispatcher* dispatcher = |
109 new ServiceWorkerDispatcher(thread_safe_sender); | 111 new ServiceWorkerDispatcher(thread_safe_sender); |
110 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) | 112 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
111 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); | 113 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); |
112 return dispatcher; | 114 return dispatcher; |
113 } | 115 } |
114 | 116 |
115 void ServiceWorkerDispatcher::OnRegistered(int32 thread_id, | 117 void ServiceWorkerDispatcher::OnRegistered(int thread_id, |
116 int32 request_id, | 118 int request_id, |
117 int handle_id) { | 119 int handle_id) { |
118 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = | 120 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = |
119 pending_callbacks_.Lookup(request_id); | 121 pending_callbacks_.Lookup(request_id); |
120 DCHECK(callbacks); | 122 DCHECK(callbacks); |
121 if (!callbacks) | 123 if (!callbacks) |
122 return; | 124 return; |
123 | 125 |
124 // the browser has to generate the registration_id so the same | 126 // the browser has to generate the registration_id so the same |
125 // worker can be called from different renderer contexts. However, | 127 // worker can be called from different renderer contexts. However, |
126 // the impl object doesn't have to be the same instance across calls | 128 // the impl object doesn't have to be the same instance across calls |
127 // unless we require the DOM objects to be identical when there's a | 129 // unless we require the DOM objects to be identical when there's a |
128 // duplicate registration. So for now we mint a new object each | 130 // duplicate registration. So for now we mint a new object each |
129 // time. | 131 // time. |
130 scoped_ptr<WebServiceWorkerImpl> worker( | 132 scoped_ptr<WebServiceWorkerImpl> worker( |
131 new WebServiceWorkerImpl(handle_id, thread_safe_sender_)); | 133 new WebServiceWorkerImpl(handle_id, thread_safe_sender_)); |
132 callbacks->onSuccess(worker.release()); | 134 callbacks->onSuccess(worker.release()); |
133 pending_callbacks_.Remove(request_id); | 135 pending_callbacks_.Remove(request_id); |
134 } | 136 } |
135 | 137 |
136 void ServiceWorkerDispatcher::OnUnregistered( | 138 void ServiceWorkerDispatcher::OnUnregistered( |
137 int32 thread_id, | 139 int thread_id, |
138 int32 request_id) { | 140 int request_id) { |
139 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = | 141 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = |
140 pending_callbacks_.Lookup(request_id); | 142 pending_callbacks_.Lookup(request_id); |
141 DCHECK(callbacks); | 143 DCHECK(callbacks); |
142 if (!callbacks) | 144 if (!callbacks) |
143 return; | 145 return; |
144 | 146 |
145 callbacks->onSuccess(NULL); | 147 callbacks->onSuccess(NULL); |
146 pending_callbacks_.Remove(request_id); | 148 pending_callbacks_.Remove(request_id); |
147 } | 149 } |
148 | 150 |
149 void ServiceWorkerDispatcher::OnRegistrationError( | 151 void ServiceWorkerDispatcher::OnRegistrationError( |
150 int32 thread_id, | 152 int thread_id, |
151 int32 request_id, | 153 int request_id, |
152 WebServiceWorkerError::ErrorType error_type, | 154 WebServiceWorkerError::ErrorType error_type, |
153 const base::string16& message) { | 155 const base::string16& message) { |
154 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = | 156 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = |
155 pending_callbacks_.Lookup(request_id); | 157 pending_callbacks_.Lookup(request_id); |
156 DCHECK(callbacks); | 158 DCHECK(callbacks); |
157 if (!callbacks) | 159 if (!callbacks) |
158 return; | 160 return; |
159 | 161 |
160 scoped_ptr<WebServiceWorkerError> error( | 162 scoped_ptr<WebServiceWorkerError> error( |
161 new WebServiceWorkerError(error_type, message)); | 163 new WebServiceWorkerError(error_type, message)); |
162 callbacks->onError(error.release()); | 164 callbacks->onError(error.release()); |
163 pending_callbacks_.Remove(request_id); | 165 pending_callbacks_.Remove(request_id); |
164 } | 166 } |
165 | 167 |
166 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { delete this; } | 168 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { delete this; } |
167 | 169 |
168 } // namespace content | 170 } // namespace content |
OLD | NEW |