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

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

Issue 535753002: ServiceWorker: Implement navigator.serviceWorker.getRegistration [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch for review 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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { 50 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() {
51 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 51 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
52 } 52 }
53 53
54 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { 54 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
55 bool handled = true; 55 bool handled = true;
56 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) 56 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg)
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered)
58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, 58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered,
59 OnUnregistered) 59 OnUnregistered)
60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration,
61 OnDidGetRegistration)
60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
61 OnRegistrationError) 63 OnRegistrationError)
62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError,
63 OnUnregistrationError) 65 OnUnregistrationError)
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError,
67 OnGetRegistrationError)
64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
65 OnServiceWorkerStateChanged) 69 OnServiceWorkerStateChanged)
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
67 OnSetVersionAttributes) 71 OnSetVersionAttributes)
68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
69 OnUpdateFound) 73 OnUpdateFound)
70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
71 OnSetControllerServiceWorker) 75 OnSetControllerServiceWorker)
72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
73 OnPostMessage) 77 OnPostMessage)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 128
125 int request_id = pending_unregistration_callbacks_.Add(callbacks); 129 int request_id = pending_unregistration_callbacks_.Add(callbacks);
126 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", 130 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
127 "ServiceWorkerDispatcher::UnregisterServiceWorker", 131 "ServiceWorkerDispatcher::UnregisterServiceWorker",
128 request_id, 132 request_id,
129 "Pettern", pattern.spec()); 133 "Pettern", pattern.spec());
130 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( 134 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
131 CurrentWorkerId(), request_id, provider_id, pattern)); 135 CurrentWorkerId(), request_id, provider_id, pattern));
132 } 136 }
133 137
138 void ServiceWorkerDispatcher::GetRegistration(
139 int provider_id,
140 const GURL& document_url,
141 WebServiceWorkerRegistrationCallbacks* callbacks) {
142 DCHECK(callbacks);
143
144 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
145 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
146 owned_callbacks(callbacks);
147 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
148 WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
149 callbacks->onError(error.release());
150 return;
151 }
152
153 int request_id = pending_get_registration_callbacks_.Add(callbacks);
154 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration(
155 CurrentWorkerId(), request_id, provider_id, document_url));
156 }
157
134 void ServiceWorkerDispatcher::AddProviderContext( 158 void ServiceWorkerDispatcher::AddProviderContext(
135 ServiceWorkerProviderContext* provider_context) { 159 ServiceWorkerProviderContext* provider_context) {
136 DCHECK(provider_context); 160 DCHECK(provider_context);
137 int provider_id = provider_context->provider_id(); 161 int provider_id = provider_context->provider_id();
138 DCHECK(!ContainsKey(provider_contexts_, provider_id)); 162 DCHECK(!ContainsKey(provider_contexts_, provider_id));
139 provider_contexts_[provider_id] = provider_context; 163 provider_contexts_[provider_id] = provider_context;
140 } 164 }
141 165
142 void ServiceWorkerDispatcher::RemoveProviderContext( 166 void ServiceWorkerDispatcher::RemoveProviderContext(
143 ServiceWorkerProviderContext* provider_context) { 167 ServiceWorkerProviderContext* provider_context) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 if (!callbacks) 315 if (!callbacks)
292 return; 316 return;
293 bool is_success = true; 317 bool is_success = true;
294 callbacks->onSuccess(&is_success); 318 callbacks->onSuccess(&is_success);
295 pending_unregistration_callbacks_.Remove(request_id); 319 pending_unregistration_callbacks_.Remove(request_id);
296 TRACE_EVENT_ASYNC_END0("ServiceWorker", 320 TRACE_EVENT_ASYNC_END0("ServiceWorker",
297 "ServiceWorkerDispatcher::UnregisterServiceWorker", 321 "ServiceWorkerDispatcher::UnregisterServiceWorker",
298 request_id); 322 request_id);
299 } 323 }
300 324
325 void ServiceWorkerDispatcher::OnDidGetRegistration(
326 int thread_id,
327 int request_id,
328 const ServiceWorkerRegistrationObjectInfo& info,
329 const ServiceWorkerVersionAttributes& attrs) {
330 WebServiceWorkerRegistrationCallbacks* callbacks =
331 pending_get_registration_callbacks_.Lookup(request_id);
332 DCHECK(callbacks);
333 if (!callbacks)
334 return;
335
336 WebServiceWorkerRegistrationImpl* registration =
337 GetServiceWorkerRegistration(info, true);
nhiroki 2014/09/10 04:07:22 FYI: I guess you copied these registration handlin
Kunihiko Sakamoto 2014/09/10 08:22:44 Acknowledged.
338 if (registration) {
339 registration->SetInstalling(GetServiceWorker(attrs.installing, true));
340 registration->SetWaiting(GetServiceWorker(attrs.waiting, true));
341 registration->SetActive(GetServiceWorker(attrs.active, true));
342 }
343 callbacks->onSuccess(registration);
344 pending_get_registration_callbacks_.Remove(request_id);
345 }
346
301 void ServiceWorkerDispatcher::OnRegistrationError( 347 void ServiceWorkerDispatcher::OnRegistrationError(
302 int thread_id, 348 int thread_id,
303 int request_id, 349 int request_id,
304 WebServiceWorkerError::ErrorType error_type, 350 WebServiceWorkerError::ErrorType error_type,
305 const base::string16& message) { 351 const base::string16& message) {
306 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", 352 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
307 "ServiceWorkerDispatcher::RegisterServiceWorker", 353 "ServiceWorkerDispatcher::RegisterServiceWorker",
308 request_id, 354 request_id,
309 "OnRegistrationError"); 355 "OnRegistrationError");
310 WebServiceWorkerRegistrationCallbacks* callbacks = 356 WebServiceWorkerRegistrationCallbacks* callbacks =
(...skipping 29 matching lines...) Expand all
340 386
341 scoped_ptr<WebServiceWorkerError> error( 387 scoped_ptr<WebServiceWorkerError> error(
342 new WebServiceWorkerError(error_type, message)); 388 new WebServiceWorkerError(error_type, message));
343 callbacks->onError(error.release()); 389 callbacks->onError(error.release());
344 pending_unregistration_callbacks_.Remove(request_id); 390 pending_unregistration_callbacks_.Remove(request_id);
345 TRACE_EVENT_ASYNC_END0("ServiceWorker", 391 TRACE_EVENT_ASYNC_END0("ServiceWorker",
346 "ServiceWorkerDispatcher::UnregisterServiceWorker", 392 "ServiceWorkerDispatcher::UnregisterServiceWorker",
347 request_id); 393 request_id);
348 } 394 }
349 395
396 void ServiceWorkerDispatcher::OnGetRegistrationError(
397 int thread_id,
398 int request_id,
399 WebServiceWorkerError::ErrorType error_type,
400 const base::string16& message) {
nhiroki 2014/09/10 04:07:22 Can you add TRACE_EVENTs like OnRegistrationError?
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
401 WebServiceWorkerGetRegistrationCallbacks* callbacks =
402 pending_get_registration_callbacks_.Lookup(request_id);
403 DCHECK(callbacks);
404 if (!callbacks)
405 return;
406
407 scoped_ptr<WebServiceWorkerError> error(
408 new WebServiceWorkerError(error_type, message));
409 callbacks->onError(error.release());
410 pending_get_registration_callbacks_.Remove(request_id);
411 }
412
350 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 413 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
351 int thread_id, 414 int thread_id,
352 int handle_id, 415 int handle_id,
353 blink::WebServiceWorkerState state) { 416 blink::WebServiceWorkerState state) {
354 TRACE_EVENT2("ServiceWorker", 417 TRACE_EVENT2("ServiceWorker",
355 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", 418 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged",
356 "Thread ID", thread_id, 419 "Thread ID", thread_id,
357 "State", state); 420 "State", state);
358 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); 421 WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
359 if (worker != service_workers_.end()) 422 if (worker != service_workers_.end())
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 registrations_[registration_handle_id] = registration; 620 registrations_[registration_handle_id] = registration;
558 } 621 }
559 622
560 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 623 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
561 int registration_handle_id) { 624 int registration_handle_id) {
562 DCHECK(ContainsKey(registrations_, registration_handle_id)); 625 DCHECK(ContainsKey(registrations_, registration_handle_id));
563 registrations_.erase(registration_handle_id); 626 registrations_.erase(registration_handle_id);
564 } 627 }
565 628
566 } // namespace content 629 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698