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

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

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | 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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 g_dispatcher_tls.Pointer()->Set(this); 46 g_dispatcher_tls.Pointer()->Set(this);
47 } 47 }
48 48
49 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { 49 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() {
50 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 50 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
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_AssociateRegistration,
57 OnAssociateRegistration)
58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UnassociateRegistration,
59 OnUnassociateRegistration)
56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) 60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered)
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered,
58 OnUnregistered) 62 OnUnregistered)
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
60 OnRegistrationError) 64 OnRegistrationError)
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
62 OnServiceWorkerStateChanged) 66 OnServiceWorkerStateChanged)
63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
64 OnSetVersionAttributes) 68 OnSetVersionAttributes)
65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( 234 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt(
231 info, thread_safe_sender_.get()) 235 info, thread_safe_sender_.get())
232 : ServiceWorkerRegistrationHandleReference::Create( 236 : ServiceWorkerRegistrationHandleReference::Create(
233 info, thread_safe_sender_.get()); 237 info, thread_safe_sender_.get());
234 238
235 // WebServiceWorkerRegistrationImpl constructor calls 239 // WebServiceWorkerRegistrationImpl constructor calls
236 // AddServiceWorkerRegistration. 240 // AddServiceWorkerRegistration.
237 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); 241 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass());
238 } 242 }
239 243
244 void ServiceWorkerDispatcher::OnAssociateRegistration(
245 int thread_id,
246 int provider_id,
247 const ServiceWorkerRegistrationObjectInfo& info) {
248 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
249 if (provider != provider_contexts_.end())
250 provider->second->AssociateRegistration(info);
251 }
252
253 void ServiceWorkerDispatcher::OnUnassociateRegistration(
254 int thread_id,
255 int provider_id) {
256 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
257 if (provider != provider_contexts_.end())
258 provider->second->UnassociateRegistration();
259 }
260
240 void ServiceWorkerDispatcher::OnRegistered( 261 void ServiceWorkerDispatcher::OnRegistered(
241 int thread_id, 262 int thread_id,
242 int request_id, 263 int request_id,
243 const ServiceWorkerRegistrationObjectInfo& info, 264 const ServiceWorkerRegistrationObjectInfo& info,
244 const ServiceWorkerVersionAttributes& attrs) { 265 const ServiceWorkerVersionAttributes& attrs) {
245 WebServiceWorkerRegistrationCallbacks* callbacks = 266 WebServiceWorkerRegistrationCallbacks* callbacks =
246 pending_callbacks_.Lookup(request_id); 267 pending_callbacks_.Lookup(request_id);
247 DCHECK(callbacks); 268 DCHECK(callbacks);
248 if (!callbacks) 269 if (!callbacks)
249 return; 270 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 existing_active_id != kInvalidServiceWorkerHandleId) { 421 existing_active_id != kInvalidServiceWorkerHandleId) {
401 WorkerToProviderMap::iterator associated_provider = 422 WorkerToProviderMap::iterator associated_provider =
402 worker_to_provider_.find(existing_active_id); 423 worker_to_provider_.find(existing_active_id);
403 DCHECK(associated_provider != worker_to_provider_.end()); 424 DCHECK(associated_provider != worker_to_provider_.end());
404 DCHECK(associated_provider->second->provider_id() == provider_id); 425 DCHECK(associated_provider->second->provider_id() == provider_id);
405 worker_to_provider_.erase(associated_provider); 426 worker_to_provider_.erase(associated_provider);
406 } 427 }
407 provider->second->OnSetActiveServiceWorker(provider_id, info); 428 provider->second->OnSetActiveServiceWorker(provider_id, info);
408 if (info.handle_id != kInvalidServiceWorkerHandleId) 429 if (info.handle_id != kInvalidServiceWorkerHandleId)
409 worker_to_provider_[info.handle_id] = provider->second; 430 worker_to_provider_[info.handle_id] = provider->second;
431
432 if (provider->second->registration_handle_id() == registration_handle_id) {
433 ScriptClientMap::iterator client = script_clients_.find(provider_id);
434 if (client != script_clients_.end()) {
435 // Resolve the .ready promise with the new registration object.
436 ServiceWorkerRegistrationObjectInfo info =
437 provider->second->registration()->info();
438 client->second->setReady(GetServiceWorkerRegistration(info, false));
439 }
440 }
410 } 441 }
411 442
412 RegistrationObjectMap::iterator found = 443 RegistrationObjectMap::iterator found =
413 registrations_.find(registration_handle_id); 444 registrations_.find(registration_handle_id);
414 if (found != registrations_.end()) { 445 if (found != registrations_.end()) {
415 // Populate the .active field with the new worker object. 446 // Populate the .active field with the new worker object.
416 found->second->SetActive(GetServiceWorker(info, false)); 447 found->second->SetActive(GetServiceWorker(info, false));
417 } 448 }
418 } 449 }
419 450
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 registrations_[registration_handle_id] = registration; 513 registrations_[registration_handle_id] = registration;
483 } 514 }
484 515
485 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 516 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
486 int registration_handle_id) { 517 int registration_handle_id) {
487 DCHECK(ContainsKey(registrations_, registration_handle_id)); 518 DCHECK(ContainsKey(registrations_, registration_handle_id));
488 registrations_.erase(registration_handle_id); 519 registrations_.erase(registration_handle_id);
489 } 520 }
490 521
491 } // namespace content 522 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698