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

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

Issue 415963002: ServiceWorker: Implement ServiceWorkerRegistration [2/3] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 #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/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/threading/thread_local.h" 9 #include "base/threading/thread_local.h"
10 #include "content/child/child_thread.h" 10 #include "content/child/child_thread.h"
11 #include "content/child/service_worker/service_worker_handle_reference.h" 11 #include "content/child/service_worker/service_worker_handle_reference.h"
12 #include "content/child/service_worker/service_worker_provider_context.h" 12 #include "content/child/service_worker/service_worker_provider_context.h"
13 #include "content/child/service_worker/web_service_worker_impl.h" 13 #include "content/child/service_worker/web_service_worker_impl.h"
14 #include "content/child/service_worker/web_service_worker_registration_impl.h"
14 #include "content/child/thread_safe_sender.h" 15 #include "content/child/thread_safe_sender.h"
15 #include "content/child/webmessageportchannel_impl.h" 16 #include "content/child/webmessageportchannel_impl.h"
16 #include "content/common/service_worker/service_worker_messages.h" 17 #include "content/common/service_worker/service_worker_messages.h"
17 #include "content/public/common/url_utils.h" 18 #include "content/public/common/url_utils.h"
18 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" 19 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
19 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 20 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
20 21
21 using blink::WebServiceWorkerError; 22 using blink::WebServiceWorkerError;
22 using blink::WebServiceWorkerProvider; 23 using blink::WebServiceWorkerProvider;
23 using base::ThreadLocalPointer; 24 using base::ThreadLocalPointer;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 75 }
75 76
76 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { 77 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) {
77 return thread_safe_sender_->Send(msg); 78 return thread_safe_sender_->Send(msg);
78 } 79 }
79 80
80 void ServiceWorkerDispatcher::RegisterServiceWorker( 81 void ServiceWorkerDispatcher::RegisterServiceWorker(
81 int provider_id, 82 int provider_id,
82 const GURL& pattern, 83 const GURL& pattern,
83 const GURL& script_url, 84 const GURL& script_url,
84 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { 85 WebServiceWorkerRegistrationCallbacks* callbacks) {
85 DCHECK(callbacks); 86 DCHECK(callbacks);
86 87
87 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || 88 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() ||
88 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { 89 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
89 scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks> 90 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
90 owned_callbacks(callbacks); 91 owned_callbacks(callbacks);
91 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( 92 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
92 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); 93 WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
93 callbacks->onError(error.release()); 94 callbacks->onError(error.release());
94 return; 95 return;
95 } 96 }
96 97
97 int request_id = pending_callbacks_.Add(callbacks); 98 int request_id = pending_callbacks_.Add(callbacks);
98 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( 99 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
99 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); 100 CurrentWorkerId(), request_id, provider_id, pattern, script_url));
100 } 101 }
101 102
102 void ServiceWorkerDispatcher::UnregisterServiceWorker( 103 void ServiceWorkerDispatcher::UnregisterServiceWorker(
103 int provider_id, 104 int provider_id,
104 const GURL& pattern, 105 const GURL& pattern,
105 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { 106 WebServiceWorkerRegistrationCallbacks* callbacks) {
106 DCHECK(callbacks); 107 DCHECK(callbacks);
107 108
108 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { 109 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) {
109 scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks> 110 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
110 owned_callbacks(callbacks); 111 owned_callbacks(callbacks);
111 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( 112 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
112 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); 113 WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
113 callbacks->onError(error.release()); 114 callbacks->onError(error.release());
114 return; 115 return;
115 } 116 }
116 117
117 int request_id = pending_callbacks_.Add(callbacks); 118 int request_id = pending_callbacks_.Add(callbacks);
118 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( 119 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
119 CurrentWorkerId(), request_id, provider_id, pattern)); 120 CurrentWorkerId(), request_id, provider_id, pattern));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_) 203 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_)
203 : ServiceWorkerHandleReference::Create(info, thread_safe_sender_); 204 : ServiceWorkerHandleReference::Create(info, thread_safe_sender_);
204 // WebServiceWorkerImpl constructor calls AddServiceWorker. 205 // WebServiceWorkerImpl constructor calls AddServiceWorker.
205 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_); 206 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_);
206 } 207 }
207 208
208 void ServiceWorkerDispatcher::OnRegistered( 209 void ServiceWorkerDispatcher::OnRegistered(
209 int thread_id, 210 int thread_id,
210 int request_id, 211 int request_id,
211 const ServiceWorkerObjectInfo& info) { 212 const ServiceWorkerObjectInfo& info) {
212 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = 213 WebServiceWorkerRegistrationCallbacks* callbacks =
213 pending_callbacks_.Lookup(request_id); 214 pending_callbacks_.Lookup(request_id);
214 DCHECK(callbacks); 215 DCHECK(callbacks);
215 if (!callbacks) 216 if (!callbacks)
216 return; 217 return;
217 218
219 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION
218 callbacks->onSuccess(GetServiceWorker(info, true)); 220 callbacks->onSuccess(GetServiceWorker(info, true));
221 #else
222 callbacks->onSuccess(new WebServiceWorkerRegistrationImpl(info));
223 #endif
219 pending_callbacks_.Remove(request_id); 224 pending_callbacks_.Remove(request_id);
220 } 225 }
221 226
222 void ServiceWorkerDispatcher::OnUnregistered( 227 void ServiceWorkerDispatcher::OnUnregistered(
223 int thread_id, 228 int thread_id,
224 int request_id) { 229 int request_id) {
225 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = 230 WebServiceWorkerRegistrationCallbacks* callbacks =
226 pending_callbacks_.Lookup(request_id); 231 pending_callbacks_.Lookup(request_id);
227 DCHECK(callbacks); 232 DCHECK(callbacks);
228 if (!callbacks) 233 if (!callbacks)
229 return; 234 return;
230 235
231 callbacks->onSuccess(NULL); 236 callbacks->onSuccess(NULL);
232 pending_callbacks_.Remove(request_id); 237 pending_callbacks_.Remove(request_id);
233 } 238 }
234 239
235 void ServiceWorkerDispatcher::OnRegistrationError( 240 void ServiceWorkerDispatcher::OnRegistrationError(
236 int thread_id, 241 int thread_id,
237 int request_id, 242 int request_id,
238 WebServiceWorkerError::ErrorType error_type, 243 WebServiceWorkerError::ErrorType error_type,
239 const base::string16& message) { 244 const base::string16& message) {
240 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = 245 WebServiceWorkerRegistrationCallbacks* callbacks =
241 pending_callbacks_.Lookup(request_id); 246 pending_callbacks_.Lookup(request_id);
242 DCHECK(callbacks); 247 DCHECK(callbacks);
243 if (!callbacks) 248 if (!callbacks)
244 return; 249 return;
245 250
246 scoped_ptr<WebServiceWorkerError> error( 251 scoped_ptr<WebServiceWorkerError> error(
247 new WebServiceWorkerError(error_type, message)); 252 new WebServiceWorkerError(error_type, message));
248 callbacks->onError(error.release()); 253 callbacks->onError(error.release());
249 pending_callbacks_.Remove(request_id); 254 pending_callbacks_.Remove(request_id);
250 } 255 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 DCHECK(!ContainsKey(service_workers_, handle_id)); 400 DCHECK(!ContainsKey(service_workers_, handle_id));
396 service_workers_[handle_id] = worker; 401 service_workers_[handle_id] = worker;
397 } 402 }
398 403
399 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { 404 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) {
400 DCHECK(ContainsKey(service_workers_, handle_id)); 405 DCHECK(ContainsKey(service_workers_, handle_id));
401 service_workers_.erase(handle_id); 406 service_workers_.erase(handle_id);
402 } 407 }
403 408
404 } // namespace content 409 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698