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

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.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/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/message_port_message_filter.h" 10 #include "content/browser/message_port_message_filter.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 bool ServiceWorkerDispatcherHost::OnMessageReceived( 108 bool ServiceWorkerDispatcherHost::OnMessageReceived(
109 const IPC::Message& message) { 109 const IPC::Message& message) {
110 bool handled = true; 110 bool handled = true;
111 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) 111 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
112 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 112 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
113 OnRegisterServiceWorker) 113 OnRegisterServiceWorker)
114 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, 114 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
115 OnUnregisterServiceWorker) 115 OnUnregisterServiceWorker)
116 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
117 OnGetRegistration)
116 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, 118 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
117 OnProviderCreated) 119 OnProviderCreated)
118 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, 120 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
119 OnProviderDestroyed) 121 OnProviderDestroyed)
120 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, 122 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId,
121 OnSetHostedVersionId) 123 OnSetHostedVersionId)
122 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, 124 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker,
123 OnPostMessageToWorker) 125 OnPostMessageToWorker)
124 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection, 126 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection,
125 OnWorkerReadyForInspection) 127 OnWorkerReadyForInspection)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 request_id, 298 request_id,
297 "Pattern", pattern.spec()); 299 "Pattern", pattern.spec());
298 GetContext()->UnregisterServiceWorker( 300 GetContext()->UnregisterServiceWorker(
299 pattern, 301 pattern,
300 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, 302 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
301 this, 303 this,
302 thread_id, 304 thread_id,
303 request_id)); 305 request_id));
304 } 306 }
305 307
308 void ServiceWorkerDispatcherHost::OnGetRegistration(
309 int thread_id,
310 int request_id,
311 int provider_id,
312 const GURL& document_url) {
313 TRACE_EVENT0("ServiceWorker",
314 "ServiceWorkerDispatcherHost::OnGetRegistration");
315 if (!GetContext()) {
316 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
317 thread_id,
318 request_id,
319 blink::WebServiceWorkerError::ErrorTypeAbort,
320 base::ASCIIToUTF16(kShutdownErrorMessage)));
321 return;
322 }
323
324 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
325 render_process_id_, provider_id);
326 if (!provider_host) {
327 BadMessageReceived();
328 return;
329 }
330 if (!provider_host->IsContextAlive()) {
331 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
332 thread_id,
333 request_id,
334 blink::WebServiceWorkerError::ErrorTypeAbort,
335 base::ASCIIToUTF16(kShutdownErrorMessage)));
336 return;
337 }
338
nhiroki 2014/09/10 04:07:22 You may want to check that the origin of |document
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
339 GetContext()->GetRegistration(
nhiroki 2014/09/10 04:07:22 You may want to add "TRACE_EVENT_ASYNC_BEGIN" here
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
340 document_url,
341 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete,
342 this,
343 thread_id,
344 provider_id,
345 request_id));
346 }
347
306 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( 348 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
307 int handle_id, 349 int handle_id,
308 const base::string16& message, 350 const base::string16& message,
309 const std::vector<int>& sent_message_port_ids) { 351 const std::vector<int>& sent_message_port_ids) {
310 TRACE_EVENT0("ServiceWorker", 352 TRACE_EVENT0("ServiceWorker",
311 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); 353 "ServiceWorkerDispatcherHost::OnPostMessageToWorker");
312 if (!GetContext()) 354 if (!GetContext())
313 return; 355 return;
314 356
315 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 357 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); 425 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue();
384 DCHECK(handle); 426 DCHECK(handle);
385 if (handle->provider_id() == provider_id && handle->registration() && 427 if (handle->provider_id() == provider_id && handle->registration() &&
386 handle->registration()->id() == registration_id) { 428 handle->registration()->id() == registration_id) {
387 return handle; 429 return handle;
388 } 430 }
389 } 431 }
390 return NULL; 432 return NULL;
391 } 433 }
392 434
435 void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes(
436 int provider_id,
437 int64 registration_id,
438 ServiceWorkerRegistrationObjectInfo* info,
439 ServiceWorkerVersionAttributes* attrs) {
440 ServiceWorkerRegistration* registration =
441 GetContext()->GetLiveRegistration(registration_id);
442 DCHECK(registration);
443
444 ServiceWorkerRegistrationHandle* handle =
445 GetOrCreateRegistrationHandle(provider_id, registration);
446 *info = handle->GetObjectInfo();
447
448 attrs->installing = handle->CreateServiceWorkerHandleAndPass(
449 registration->installing_version());
450 attrs->waiting = handle->CreateServiceWorkerHandleAndPass(
451 registration->waiting_version());
452 attrs->active = handle->CreateServiceWorkerHandleAndPass(
453 registration->active_version());
454 }
455
393 void ServiceWorkerDispatcherHost::RegistrationComplete( 456 void ServiceWorkerDispatcherHost::RegistrationComplete(
394 int thread_id, 457 int thread_id,
395 int provider_id, 458 int provider_id,
396 int request_id, 459 int request_id,
397 ServiceWorkerStatusCode status, 460 ServiceWorkerStatusCode status,
398 int64 registration_id, 461 int64 registration_id,
399 int64 version_id) { 462 int64 version_id) {
400 if (!GetContext()) 463 if (!GetContext())
401 return; 464 return;
402 465
403 if (status != SERVICE_WORKER_OK) { 466 if (status != SERVICE_WORKER_OK) {
404 SendRegistrationError(thread_id, request_id, status); 467 SendRegistrationError(thread_id, request_id, status);
405 return; 468 return;
406 } 469 }
407 470
408 ServiceWorkerRegistration* registration = 471 ServiceWorkerRegistrationObjectInfo info;
409 GetContext()->GetLiveRegistration(registration_id);
410 DCHECK(registration);
411
412 ServiceWorkerRegistrationHandle* handle =
413 GetOrCreateRegistrationHandle(provider_id, registration);
414
415 ServiceWorkerVersionAttributes attrs; 472 ServiceWorkerVersionAttributes attrs;
416 attrs.installing = handle->CreateServiceWorkerHandleAndPass( 473 GetRegistrationObjectInfoAndVersionAttributes(
417 registration->installing_version()); 474 provider_id, registration_id, &info, &attrs);
418 attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
419 registration->waiting_version());
420 attrs.active = handle->CreateServiceWorkerHandleAndPass(
421 registration->active_version());
422 475
423 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( 476 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
424 thread_id, request_id, handle->GetObjectInfo(), attrs)); 477 thread_id, request_id, info, attrs));
425 TRACE_EVENT_ASYNC_END2("ServiceWorker", 478 TRACE_EVENT_ASYNC_END2("ServiceWorker",
426 "ServiceWorkerDispatcherHost::RegisterServiceWorker", 479 "ServiceWorkerDispatcherHost::RegisterServiceWorker",
427 request_id, 480 request_id,
428 "Registration ID", registration_id, 481 "Registration ID", registration_id,
429 "Version ID", version_id); 482 "Version ID", version_id);
430 } 483 }
431 484
432 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection( 485 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection(
433 int embedded_worker_id) { 486 int embedded_worker_id) {
434 TRACE_EVENT0("ServiceWorker", 487 TRACE_EVENT0("ServiceWorker",
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 654 }
602 655
603 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); 656 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
604 TRACE_EVENT_ASYNC_END1( 657 TRACE_EVENT_ASYNC_END1(
605 "ServiceWorker", 658 "ServiceWorker",
606 "ServiceWorkerDispatcherHost::UnregisterServiceWorker", 659 "ServiceWorkerDispatcherHost::UnregisterServiceWorker",
607 request_id, 660 request_id,
608 "Status", status); 661 "Status", status);
609 } 662 }
610 663
664 void ServiceWorkerDispatcherHost::GetRegistrationComplete(
665 int thread_id,
666 int provider_id,
667 int request_id,
668 ServiceWorkerStatusCode status,
669 int64 registration_id) {
670 if (!GetContext())
671 return;
672
673 if (status != SERVICE_WORKER_OK) {
674 SendGetRegistrationError(thread_id, request_id, status);
675 return;
676 }
677
678 ServiceWorkerRegistrationObjectInfo info;
679 ServiceWorkerVersionAttributes attrs;
680 if (registration_id != kInvalidServiceWorkerRegistrationId) {
681 GetRegistrationObjectInfoAndVersionAttributes(
682 provider_id, registration_id, &info, &attrs);
683 }
684
685 Send(new ServiceWorkerMsg_DidGetRegistration(
686 thread_id, request_id, info, attrs));
nhiroki 2014/09/10 04:07:22 "TRACE_EVENT_ASYNC_END" (a separate CL is ok)
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
687 }
688
611 void ServiceWorkerDispatcherHost::SendRegistrationError( 689 void ServiceWorkerDispatcherHost::SendRegistrationError(
612 int thread_id, 690 int thread_id,
613 int request_id, 691 int request_id,
614 ServiceWorkerStatusCode status) { 692 ServiceWorkerStatusCode status) {
615 base::string16 error_message; 693 base::string16 error_message;
616 blink::WebServiceWorkerError::ErrorType error_type; 694 blink::WebServiceWorkerError::ErrorType error_type;
617 GetServiceWorkerRegistrationStatusResponse( 695 GetServiceWorkerRegistrationStatusResponse(
618 status, &error_type, &error_message); 696 status, &error_type, &error_message);
619 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 697 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
620 thread_id, request_id, error_type, error_message)); 698 thread_id, request_id, error_type, error_message));
621 } 699 }
622 700
623 void ServiceWorkerDispatcherHost::SendUnregistrationError( 701 void ServiceWorkerDispatcherHost::SendUnregistrationError(
624 int thread_id, 702 int thread_id,
625 int request_id, 703 int request_id,
626 ServiceWorkerStatusCode status) { 704 ServiceWorkerStatusCode status) {
627 base::string16 error_message; 705 base::string16 error_message;
628 blink::WebServiceWorkerError::ErrorType error_type; 706 blink::WebServiceWorkerError::ErrorType error_type;
629 GetServiceWorkerRegistrationStatusResponse( 707 GetServiceWorkerRegistrationStatusResponse(
630 status, &error_type, &error_message); 708 status, &error_type, &error_message);
631 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 709 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
632 thread_id, request_id, error_type, error_message)); 710 thread_id, request_id, error_type, error_message));
633 } 711 }
634 712
713 void ServiceWorkerDispatcherHost::SendGetRegistrationError(
714 int thread_id,
715 int request_id,
716 ServiceWorkerStatusCode status) {
717 base::string16 error_message;
718 blink::WebServiceWorkerError::ErrorType error_type;
719 GetServiceWorkerRegistrationStatusResponse(
720 status, &error_type, &error_message);
721 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
722 thread_id, request_id, error_type, error_message));
723 }
724
635 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 725 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
636 return context_wrapper_->context(); 726 return context_wrapper_->context();
637 } 727 }
638 728
639 } // namespace content 729 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698