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

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

Issue 516823003: ServiceWorker: Change the return value of ServiceWorkerRegistration::unregister to boolean (2/4) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { 53 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
54 bool handled = true; 54 bool handled = true;
55 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) 55 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg)
56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) 56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered)
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered,
58 OnUnregistered) 58 OnUnregistered)
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
60 OnRegistrationError) 60 OnRegistrationError)
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError,
62 OnUnregistrationError)
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
62 OnServiceWorkerStateChanged) 64 OnServiceWorkerStateChanged)
63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
64 OnSetVersionAttributes) 66 OnSetVersionAttributes)
65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
66 OnUpdateFound) 68 OnUpdateFound)
67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
68 OnSetControllerServiceWorker) 70 OnSetControllerServiceWorker)
69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 71 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
70 OnPostMessage) 72 OnPostMessage)
(...skipping 16 matching lines...) Expand all
87 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || 89 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() ||
88 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { 90 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
89 scoped_ptr<WebServiceWorkerRegistrationCallbacks> 91 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
90 owned_callbacks(callbacks); 92 owned_callbacks(callbacks);
91 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( 93 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
92 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); 94 WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
93 callbacks->onError(error.release()); 95 callbacks->onError(error.release());
94 return; 96 return;
95 } 97 }
96 98
97 int request_id = pending_callbacks_.Add(callbacks); 99 int request_id = pending_registration_callbacks_.Add(callbacks);
98 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( 100 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
99 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); 101 CurrentWorkerId(), request_id, provider_id, pattern, script_url));
100 } 102 }
101 103
102 void ServiceWorkerDispatcher::UnregisterServiceWorker( 104 void ServiceWorkerDispatcher::UnregisterServiceWorker(
103 int provider_id, 105 int provider_id,
104 const GURL& pattern, 106 const GURL& pattern,
105 WebServiceWorkerRegistrationCallbacks* callbacks) { 107 WebServiceWorkerUnregistrationCallbacks* callbacks) {
106 DCHECK(callbacks); 108 DCHECK(callbacks);
107 109
108 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { 110 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) {
109 scoped_ptr<WebServiceWorkerRegistrationCallbacks> 111 scoped_ptr<WebServiceWorkerUnregistrationCallbacks>
110 owned_callbacks(callbacks); 112 owned_callbacks(callbacks);
111 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( 113 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
112 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); 114 WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
113 callbacks->onError(error.release()); 115 callbacks->onError(error.release());
114 return; 116 return;
115 } 117 }
116 118
117 int request_id = pending_callbacks_.Add(callbacks); 119 int request_id = pending_unregistration_callbacks_.Add(callbacks);
118 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( 120 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
119 CurrentWorkerId(), request_id, provider_id, pattern)); 121 CurrentWorkerId(), request_id, provider_id, pattern));
120 } 122 }
121 123
122 void ServiceWorkerDispatcher::AddProviderContext( 124 void ServiceWorkerDispatcher::AddProviderContext(
123 ServiceWorkerProviderContext* provider_context) { 125 ServiceWorkerProviderContext* provider_context) {
124 DCHECK(provider_context); 126 DCHECK(provider_context);
125 int provider_id = provider_context->provider_id(); 127 int provider_id = provider_context->provider_id();
126 DCHECK(!ContainsKey(provider_contexts_, provider_id)); 128 DCHECK(!ContainsKey(provider_contexts_, provider_id));
127 provider_contexts_[provider_id] = provider_context; 129 provider_contexts_[provider_id] = provider_context;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // AddServiceWorkerRegistration. 238 // AddServiceWorkerRegistration.
237 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); 239 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass());
238 } 240 }
239 241
240 void ServiceWorkerDispatcher::OnRegistered( 242 void ServiceWorkerDispatcher::OnRegistered(
241 int thread_id, 243 int thread_id,
242 int request_id, 244 int request_id,
243 const ServiceWorkerRegistrationObjectInfo& info, 245 const ServiceWorkerRegistrationObjectInfo& info,
244 const ServiceWorkerVersionAttributes& attrs) { 246 const ServiceWorkerVersionAttributes& attrs) {
245 WebServiceWorkerRegistrationCallbacks* callbacks = 247 WebServiceWorkerRegistrationCallbacks* callbacks =
246 pending_callbacks_.Lookup(request_id); 248 pending_registration_callbacks_.Lookup(request_id);
247 DCHECK(callbacks); 249 DCHECK(callbacks);
248 if (!callbacks) 250 if (!callbacks)
249 return; 251 return;
250 252
251 WebServiceWorkerRegistrationImpl* registration = 253 WebServiceWorkerRegistrationImpl* registration =
252 GetServiceWorkerRegistration(info, true); 254 GetServiceWorkerRegistration(info, true);
253 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); 255 registration->SetInstalling(GetServiceWorker(attrs.installing, true));
254 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); 256 registration->SetWaiting(GetServiceWorker(attrs.waiting, true));
255 registration->SetActive(GetServiceWorker(attrs.active, true)); 257 registration->SetActive(GetServiceWorker(attrs.active, true));
256 258
257 callbacks->onSuccess(registration); 259 callbacks->onSuccess(registration);
258 pending_callbacks_.Remove(request_id); 260 pending_registration_callbacks_.Remove(request_id);
259 } 261 }
260 262
261 void ServiceWorkerDispatcher::OnUnregistered( 263 void ServiceWorkerDispatcher::OnUnregistered(
262 int thread_id, 264 int thread_id,
263 int request_id) { 265 int request_id) {
264 WebServiceWorkerRegistrationCallbacks* callbacks = 266 WebServiceWorkerUnregistrationCallbacks* callbacks =
265 pending_callbacks_.Lookup(request_id); 267 pending_unregistration_callbacks_.Lookup(request_id);
266 DCHECK(callbacks); 268 DCHECK(callbacks);
267 if (!callbacks) 269 if (!callbacks)
268 return; 270 return;
269 271 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN
270 callbacks->onSuccess(NULL); 272 callbacks->onSuccess(NULL);
271 pending_callbacks_.Remove(request_id); 273 #else
274 bool is_success = true;
275 callbacks->onSuccess(&is_success);
276 #endif
277 pending_unregistration_callbacks_.Remove(request_id);
272 } 278 }
273 279
274 void ServiceWorkerDispatcher::OnRegistrationError( 280 void ServiceWorkerDispatcher::OnRegistrationError(
275 int thread_id, 281 int thread_id,
276 int request_id, 282 int request_id,
277 WebServiceWorkerError::ErrorType error_type, 283 WebServiceWorkerError::ErrorType error_type,
278 const base::string16& message) { 284 const base::string16& message) {
279 WebServiceWorkerRegistrationCallbacks* callbacks = 285 WebServiceWorkerRegistrationCallbacks* callbacks =
280 pending_callbacks_.Lookup(request_id); 286 pending_registration_callbacks_.Lookup(request_id);
281 DCHECK(callbacks); 287 DCHECK(callbacks);
282 if (!callbacks) 288 if (!callbacks)
283 return; 289 return;
290
291 scoped_ptr<WebServiceWorkerError> error(
292 new WebServiceWorkerError(error_type, message));
293 callbacks->onError(error.release());
294 pending_registration_callbacks_.Remove(request_id);
295 }
296
297 void ServiceWorkerDispatcher::OnUnregistrationError(
298 int thread_id,
299 int request_id,
300 WebServiceWorkerError::ErrorType error_type,
301 const base::string16& message) {
302 WebServiceWorkerUnregistrationCallbacks* callbacks =
303 pending_unregistration_callbacks_.Lookup(request_id);
304 DCHECK(callbacks);
305 if (!callbacks)
306 return;
284 307
285 scoped_ptr<WebServiceWorkerError> error( 308 scoped_ptr<WebServiceWorkerError> error(
286 new WebServiceWorkerError(error_type, message)); 309 new WebServiceWorkerError(error_type, message));
287 callbacks->onError(error.release()); 310 callbacks->onError(error.release());
288 pending_callbacks_.Remove(request_id); 311 pending_unregistration_callbacks_.Remove(request_id);
289 } 312 }
290 313
291 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 314 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
292 int thread_id, 315 int thread_id,
293 int handle_id, 316 int handle_id,
294 blink::WebServiceWorkerState state) { 317 blink::WebServiceWorkerState state) {
295 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); 318 WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
296 if (worker != service_workers_.end()) 319 if (worker != service_workers_.end())
297 worker->second->OnStateChanged(state); 320 worker->second->OnStateChanged(state);
298 321
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 registrations_[registration_handle_id] = registration; 505 registrations_[registration_handle_id] = registration;
483 } 506 }
484 507
485 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 508 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
486 int registration_handle_id) { 509 int registration_handle_id) {
487 DCHECK(ContainsKey(registrations_, registration_handle_id)); 510 DCHECK(ContainsKey(registrations_, registration_handle_id));
488 registrations_.erase(registration_handle_id); 511 registrations_.erase(registration_handle_id);
489 } 512 }
490 513
491 } // namespace content 514 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698