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

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: 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/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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 bool ServiceWorkerDispatcherHost::OnMessageReceived( 105 bool ServiceWorkerDispatcherHost::OnMessageReceived(
106 const IPC::Message& message) { 106 const IPC::Message& message) {
107 bool handled = true; 107 bool handled = true;
108 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) 108 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
109 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 109 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
110 OnRegisterServiceWorker) 110 OnRegisterServiceWorker)
111 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, 111 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
112 OnUnregisterServiceWorker) 112 OnUnregisterServiceWorker)
113 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
114 OnGetRegistration)
113 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, 115 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
114 OnProviderCreated) 116 OnProviderCreated)
115 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, 117 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
116 OnProviderDestroyed) 118 OnProviderDestroyed)
117 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, 119 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId,
118 OnSetHostedVersionId) 120 OnSetHostedVersionId)
119 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, 121 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker,
120 OnPostMessageToWorker) 122 OnPostMessageToWorker)
121 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection, 123 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection,
122 OnWorkerReadyForInspection) 124 OnWorkerReadyForInspection)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 262 }
261 263
262 GetContext()->UnregisterServiceWorker( 264 GetContext()->UnregisterServiceWorker(
263 pattern, 265 pattern,
264 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, 266 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
265 this, 267 this,
266 thread_id, 268 thread_id,
267 request_id)); 269 request_id));
268 } 270 }
269 271
272 void ServiceWorkerDispatcherHost::OnGetRegistration(
273 int thread_id,
274 int request_id,
275 int provider_id,
276 const GURL& document_url) {
277 if (!GetContext()) {
278 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
279 thread_id,
280 request_id,
281 blink::WebServiceWorkerError::ErrorTypeAbort,
282 base::ASCIIToUTF16(kShutdownErrorMessage)));
283 return;
284 }
285
286 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
287 render_process_id_, provider_id);
288 if (!provider_host) {
289 BadMessageReceived();
290 return;
291 }
292 if (!provider_host->IsContextAlive()) {
293 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
294 thread_id,
295 request_id,
296 blink::WebServiceWorkerError::ErrorTypeAbort,
297 base::ASCIIToUTF16(kShutdownErrorMessage)));
298 return;
299 }
300
301 GetContext()->GetRegistration(
302 document_url,
303 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete,
304 this,
305 thread_id,
306 provider_id,
307 request_id));
308 }
309
270 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( 310 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
271 int handle_id, 311 int handle_id,
272 const base::string16& message, 312 const base::string16& message,
273 const std::vector<int>& sent_message_port_ids) { 313 const std::vector<int>& sent_message_port_ids) {
274 if (!GetContext()) 314 if (!GetContext())
275 return; 315 return;
276 316
277 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 317 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
278 if (!handle) { 318 if (!handle) {
279 BadMessageReceived(); 319 BadMessageReceived();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 int request_id, 575 int request_id,
536 ServiceWorkerStatusCode status) { 576 ServiceWorkerStatusCode status) {
537 if (status != SERVICE_WORKER_OK) { 577 if (status != SERVICE_WORKER_OK) {
538 SendRegistrationError(thread_id, request_id, status); 578 SendRegistrationError(thread_id, request_id, status);
539 return; 579 return;
540 } 580 }
541 581
542 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); 582 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
543 } 583 }
544 584
585 void ServiceWorkerDispatcherHost::GetRegistrationComplete(
586 int thread_id,
587 int provider_id,
588 int request_id,
589 ServiceWorkerStatusCode status,
590 int64 registration_id) {
591 if (!GetContext())
592 return;
593
594 if (status != SERVICE_WORKER_OK) {
595 SendRegistrationError(thread_id, request_id, status);
596 return;
597 }
598
599 ServiceWorkerRegistrationObjectInfo info;
600 ServiceWorkerVersionAttributes attrs;
601
602 if (registration_id != kInvalidServiceWorkerRegistrationId) {
603 ServiceWorkerRegistration* registration =
604 GetContext()->GetLiveRegistration(registration_id);
605 DCHECK(registration);
606
607 ServiceWorkerRegistrationHandle* handle =
608 FindRegistrationHandle(provider_id, registration_id);
609 if (handle) {
610 handle->IncrementRefCount();
611 info = handle->GetObjectInfo();
612 } else {
613 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
614 new ServiceWorkerRegistrationHandle(
615 GetContext()->AsWeakPtr(), this, provider_id, registration));
616 info = new_handle->GetObjectInfo();
617 handle = new_handle.get();
618 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
619 }
620
621 attrs.installing = handle->CreateServiceWorkerHandleAndPass(
622 registration->installing_version());
623 attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
624 registration->waiting_version());
625 attrs.active = handle->CreateServiceWorkerHandleAndPass(
626 registration->active_version());
nhiroki 2014/09/05 04:55:09 Since RegistrationComplete does the same thing, ca
Kunihiko Sakamoto 2014/09/09 07:28:10 Done.
627 }
628
629 Send(new ServiceWorkerMsg_DidGetRegistration(
630 thread_id, request_id, info, attrs));
631 }
632
545 void ServiceWorkerDispatcherHost::SendRegistrationError( 633 void ServiceWorkerDispatcherHost::SendRegistrationError(
546 int thread_id, 634 int thread_id,
547 int request_id, 635 int request_id,
548 ServiceWorkerStatusCode status) { 636 ServiceWorkerStatusCode status) {
549 base::string16 error_message; 637 base::string16 error_message;
550 blink::WebServiceWorkerError::ErrorType error_type; 638 blink::WebServiceWorkerError::ErrorType error_type;
551 GetServiceWorkerRegistrationStatusResponse( 639 GetServiceWorkerRegistrationStatusResponse(
552 status, &error_type, &error_message); 640 status, &error_type, &error_message);
553 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 641 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
554 thread_id, request_id, error_type, error_message)); 642 thread_id, request_id, error_type, error_message));
555 } 643 }
556 644
557 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 645 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
558 return context_wrapper_->context(); 646 return context_wrapper_->context();
559 } 647 }
560 648
561 } // namespace content 649 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698