| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
| 73 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdated, OnUpdated) | 73 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdated, OnUpdated) |
| 74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
| 75 OnUnregistered) | 75 OnUnregistered) |
| 76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, | 76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, |
| 77 OnDidGetRegistration) | 77 OnDidGetRegistration) |
| 78 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations, | 78 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations, |
| 79 OnDidGetRegistrations) | 79 OnDidGetRegistrations) |
| 80 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, | 80 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, |
| 81 OnDidGetRegistrationForReady) | 81 OnDidGetRegistrationForReady) |
| 82 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSetNavigationPreload, |
| 83 OnDidSetNavigationPreload) |
| 84 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetNavigationPreload, |
| 85 OnDidGetNavigationPreload) |
| 82 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 86 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
| 83 OnRegistrationError) | 87 OnRegistrationError) |
| 84 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdateError, | 88 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdateError, |
| 85 OnUpdateError) | 89 OnUpdateError) |
| 86 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, | 90 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, |
| 87 OnUnregistrationError) | 91 OnUnregistrationError) |
| 88 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, | 92 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, |
| 89 OnGetRegistrationError) | 93 OnGetRegistrationError) |
| 90 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError, | 94 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError, |
| 91 OnGetRegistrationsError) | 95 OnGetRegistrationsError) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 int provider_id, | 203 int provider_id, |
| 200 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { | 204 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { |
| 201 int request_id = get_for_ready_callbacks_.Add(callbacks); | 205 int request_id = get_for_ready_callbacks_.Add(callbacks); |
| 202 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 206 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 203 "ServiceWorkerDispatcher::GetRegistrationForReady", | 207 "ServiceWorkerDispatcher::GetRegistrationForReady", |
| 204 request_id); | 208 request_id); |
| 205 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( | 209 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( |
| 206 CurrentWorkerId(), request_id, provider_id)); | 210 CurrentWorkerId(), request_id, provider_id)); |
| 207 } | 211 } |
| 208 | 212 |
| 213 void ServiceWorkerDispatcher::SetNavigationPreload( |
| 214 int handle_id, |
| 215 const std::string& value, |
| 216 blink::WebServiceWorker::WebSetNavigationPreloadCallbacks* callback) { |
| 217 LOG(ERROR) << "ServiceWorkerDispatcher::SetNavigationPreload value=" << value; |
| 218 int request_id = pending_set_navigation_preload_callbacks_.Add(callback); |
| 219 thread_safe_sender_->Send(new ServiceWorkerHostMsg_SetNavigationPreload( |
| 220 CurrentWorkerId(), request_id, handle_id, value)); |
| 221 } |
| 222 |
| 223 void ServiceWorkerDispatcher::GetNavigationPreload( |
| 224 int handle_id, |
| 225 blink::WebServiceWorker::WebGetNavigationPreloadCallbacks* callback) { |
| 226 LOG(ERROR) << "ServiceWorkerDispatcher::GetNavigationPreload"; |
| 227 int request_id = pending_get_navigation_preload_callbacks_.Add(callback); |
| 228 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetNavigationPreload( |
| 229 CurrentWorkerId(), request_id, handle_id)); |
| 230 } |
| 231 |
| 209 void ServiceWorkerDispatcher::AddProviderContext( | 232 void ServiceWorkerDispatcher::AddProviderContext( |
| 210 ServiceWorkerProviderContext* provider_context) { | 233 ServiceWorkerProviderContext* provider_context) { |
| 211 DCHECK(provider_context); | 234 DCHECK(provider_context); |
| 212 int provider_id = provider_context->provider_id(); | 235 int provider_id = provider_context->provider_id(); |
| 213 DCHECK(!base::ContainsKey(provider_contexts_, provider_id)); | 236 DCHECK(!base::ContainsKey(provider_contexts_, provider_id)); |
| 214 provider_contexts_[provider_id] = provider_context; | 237 provider_contexts_[provider_id] = provider_context; |
| 215 } | 238 } |
| 216 | 239 |
| 217 void ServiceWorkerDispatcher::RemoveProviderContext( | 240 void ServiceWorkerDispatcher::RemoveProviderContext( |
| 218 ServiceWorkerProviderContext* provider_context) { | 241 ServiceWorkerProviderContext* provider_context) { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 get_for_ready_callbacks_.Lookup(request_id); | 536 get_for_ready_callbacks_.Lookup(request_id); |
| 514 DCHECK(callbacks); | 537 DCHECK(callbacks); |
| 515 if (!callbacks) | 538 if (!callbacks) |
| 516 return; | 539 return; |
| 517 | 540 |
| 518 callbacks->onSuccess(WebServiceWorkerRegistrationImpl::CreateHandle( | 541 callbacks->onSuccess(WebServiceWorkerRegistrationImpl::CreateHandle( |
| 519 GetOrAdoptRegistration(info, attrs))); | 542 GetOrAdoptRegistration(info, attrs))); |
| 520 get_for_ready_callbacks_.Remove(request_id); | 543 get_for_ready_callbacks_.Remove(request_id); |
| 521 } | 544 } |
| 522 | 545 |
| 546 void ServiceWorkerDispatcher::OnDidGetNavigationPreload( |
| 547 int thread_id, |
| 548 int request_id, |
| 549 bool is_enabled, |
| 550 const std::string& value) { |
| 551 LOG(ERROR) << "SWDispatcher::OnDidGetNavigationPreload: enabled=" |
| 552 << is_enabled << ", value=" << value; |
| 553 WebGetNavigationPreloadCallbacks* callbacks = |
| 554 pending_get_navigation_preload_callbacks_.Lookup(request_id); |
| 555 DCHECK(callbacks); |
| 556 if (!callbacks) |
| 557 return; |
| 558 |
| 559 if (is_enabled) |
| 560 callbacks->onSuccess(blink::WebString::fromUTF8(value)); |
| 561 else |
| 562 callbacks->onSuccess(blink::WebString()); |
| 563 pending_get_navigation_preload_callbacks_.Remove(request_id); |
| 564 } |
| 565 |
| 566 void ServiceWorkerDispatcher::OnDidSetNavigationPreload(int thread_id, |
| 567 int request_id) { |
| 568 LOG(ERROR) << "SWDispatcher::OnDidSetNavigationPreload"; |
| 569 WebSetNavigationPreloadCallbacks* callbacks = |
| 570 pending_set_navigation_preload_callbacks_.Lookup(request_id); |
| 571 DCHECK(callbacks); |
| 572 if (!callbacks) |
| 573 return; |
| 574 |
| 575 callbacks->onSuccess(); |
| 576 pending_set_navigation_preload_callbacks_.Remove(request_id); |
| 577 } |
| 578 |
| 523 void ServiceWorkerDispatcher::OnRegistrationError( | 579 void ServiceWorkerDispatcher::OnRegistrationError( |
| 524 int thread_id, | 580 int thread_id, |
| 525 int request_id, | 581 int request_id, |
| 526 WebServiceWorkerError::ErrorType error_type, | 582 WebServiceWorkerError::ErrorType error_type, |
| 527 const base::string16& message) { | 583 const base::string16& message) { |
| 528 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 584 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
| 529 "ServiceWorkerDispatcher::RegisterServiceWorker", | 585 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 530 request_id, | 586 request_id, |
| 531 "OnRegistrationError"); | 587 "OnRegistrationError"); |
| 532 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 588 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 return ServiceWorkerRegistrationHandleReference::Adopt( | 831 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 776 info, thread_safe_sender_.get()); | 832 info, thread_safe_sender_.get()); |
| 777 } | 833 } |
| 778 | 834 |
| 779 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 835 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 780 const ServiceWorkerObjectInfo& info) { | 836 const ServiceWorkerObjectInfo& info) { |
| 781 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 837 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 782 } | 838 } |
| 783 | 839 |
| 784 } // namespace content | 840 } // namespace content |
| OLD | NEW |