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

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.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/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/message_port_message_filter.h" 9 #include "content/browser/message_port_message_filter.h"
10 #include "content/browser/message_port_service.h" 10 #include "content/browser/message_port_service.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (!provider_host) { 322 if (!provider_host) {
323 BadMessageReceived(); 323 BadMessageReceived();
324 return; 324 return;
325 } 325 }
326 if (!provider_host->IsContextAlive()) 326 if (!provider_host->IsContextAlive())
327 return; 327 return;
328 if (!provider_host->SetHostedVersionId(version_id)) 328 if (!provider_host->SetHostedVersionId(version_id))
329 BadMessageReceived(); 329 BadMessageReceived();
330 } 330 }
331 331
332 ServiceWorkerRegistrationObjectInfo
333 ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle(
334 int provider_id,
335 ServiceWorkerRegistration* registration) {
336 ServiceWorkerRegistrationHandle* handle =
337 FindRegistrationHandle(provider_id, registration->id());
338 if (handle) {
339 handle->IncrementRefCount();
340 return handle->GetObjectInfo();
341 }
342
343 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
344 new ServiceWorkerRegistrationHandle(
345 GetContext()->AsWeakPtr(), this, provider_id, registration));
346 ServiceWorkerRegistrationObjectInfo info = new_handle->GetObjectInfo();
347 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
348 return info;
349 }
350
332 ServiceWorkerRegistrationHandle* 351 ServiceWorkerRegistrationHandle*
333 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, 352 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
334 int64 registration_id) { 353 int64 registration_id) {
335 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator 354 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator
336 iter(&registration_handles_); 355 iter(&registration_handles_);
337 !iter.IsAtEnd(); 356 !iter.IsAtEnd();
338 iter.Advance()) { 357 iter.Advance()) {
339 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); 358 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue();
340 DCHECK(handle); 359 DCHECK(handle);
341 if (handle->provider_id() == provider_id && handle->registration() && 360 if (handle->provider_id() == provider_id && handle->registration() &&
(...skipping 16 matching lines...) Expand all
358 377
359 if (status != SERVICE_WORKER_OK) { 378 if (status != SERVICE_WORKER_OK) {
360 SendRegistrationError(thread_id, request_id, status); 379 SendRegistrationError(thread_id, request_id, status);
361 return; 380 return;
362 } 381 }
363 382
364 ServiceWorkerRegistration* registration = 383 ServiceWorkerRegistration* registration =
365 GetContext()->GetLiveRegistration(registration_id); 384 GetContext()->GetLiveRegistration(registration_id);
366 DCHECK(registration); 385 DCHECK(registration);
367 386
387 ServiceWorkerRegistrationObjectInfo info =
388 GetOrCreateRegistrationHandle(provider_id, registration);
michaeln 2014/09/04 00:27:23 seems like GetOrCreateRegistrationHandle() should
nhiroki 2014/09/08 15:55:51 Done in the separate CL (https://codereview.chromi
389
368 ServiceWorkerRegistrationHandle* handle = 390 ServiceWorkerRegistrationHandle* handle =
369 FindRegistrationHandle(provider_id, registration_id); 391 FindRegistrationHandle(provider_id, registration_id);
370 ServiceWorkerRegistrationObjectInfo info; 392 DCHECK(handle);
371 if (handle) {
372 handle->IncrementRefCount();
373 info = handle->GetObjectInfo();
374 } else {
375 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
376 new ServiceWorkerRegistrationHandle(
377 GetContext()->AsWeakPtr(), this, provider_id, registration));
378 info = new_handle->GetObjectInfo();
379 handle = new_handle.get();
380 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
381 }
382 393
383 ServiceWorkerVersionAttributes attrs; 394 ServiceWorkerVersionAttributes attrs;
384 attrs.installing = handle->CreateServiceWorkerHandleAndPass( 395 attrs.installing = handle->CreateServiceWorkerHandleAndPass(
385 registration->installing_version()); 396 registration->installing_version());
386 attrs.waiting = handle->CreateServiceWorkerHandleAndPass( 397 attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
387 registration->waiting_version()); 398 registration->waiting_version());
388 attrs.active = handle->CreateServiceWorkerHandleAndPass( 399 attrs.active = handle->CreateServiceWorkerHandleAndPass(
389 registration->active_version()); 400 registration->active_version());
390 401
391 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( 402 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 status, &error_type, &error_message); 563 status, &error_type, &error_message);
553 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 564 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
554 thread_id, request_id, error_type, error_message)); 565 thread_id, request_id, error_type, error_message));
555 } 566 }
556 567
557 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 568 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
558 return context_wrapper_->context(); 569 return context_wrapper_->context();
559 } 570 }
560 571
561 } // namespace content 572 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698