| 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/web_service_worker_provider_impl.h" | 5 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/child/child_thread.h" | 9 #include "content/child/child_thread.h" |
| 10 #include "content/child/service_worker/service_worker_dispatcher.h" | 10 #include "content/child/service_worker/service_worker_dispatcher.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl( | 25 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl( |
| 26 ThreadSafeSender* thread_safe_sender, | 26 ThreadSafeSender* thread_safe_sender, |
| 27 ServiceWorkerProviderContext* context) | 27 ServiceWorkerProviderContext* context) |
| 28 : thread_safe_sender_(thread_safe_sender), | 28 : thread_safe_sender_(thread_safe_sender), |
| 29 context_(context), | 29 context_(context), |
| 30 provider_id_(context->provider_id()) { | 30 provider_id_(context->provider_id()) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() { | 33 WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() { |
| 34 // Make sure the script client is removed. | 34 // Make sure the provider client is removed. |
| 35 RemoveScriptClient(); | 35 RemoveProviderClient(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void WebServiceWorkerProviderImpl::setClient( | 38 void WebServiceWorkerProviderImpl::setClient( |
| 39 blink::WebServiceWorkerProviderClient* client) { | 39 blink::WebServiceWorkerProviderClient* client) { |
| 40 if (!client) { | 40 if (!client) { |
| 41 RemoveScriptClient(); | 41 RemoveProviderClient(); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // TODO(kinuko): Here we could also register the current thread ID | 45 // TODO(kinuko): Here we could also register the current thread ID |
| 46 // on the provider context so that multiple WebServiceWorkerProviderImpl | 46 // on the provider context so that multiple WebServiceWorkerProviderImpl |
| 47 // (e.g. on document and on dedicated workers) can properly share | 47 // (e.g. on document and on dedicated workers) can properly share |
| 48 // the single provider context across threads. (http://crbug.com/366538 | 48 // the single provider context across threads. (http://crbug.com/366538 |
| 49 // for more context) | 49 // for more context) |
| 50 GetDispatcher()->AddScriptClient(provider_id_, client); | 50 GetDispatcher()->AddProviderClient(provider_id_, client); |
| 51 | 51 |
| 52 if (!context_->registration()) { | 52 if (!context_->registration()) { |
| 53 // This provider is not associated with any registration. | 53 // This provider is not associated with any registration. |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Set .ready if the associated registration has the active service worker. | 57 // Set .ready if the associated registration has the active service worker. |
| 58 if (context_->active_handle_id() != kInvalidServiceWorkerHandleId) { | 58 if (context_->active_handle_id() != kInvalidServiceWorkerHandleId) { |
| 59 WebServiceWorkerRegistrationImpl* registration = | 59 WebServiceWorkerRegistrationImpl* registration = |
| 60 GetDispatcher()->FindServiceWorkerRegistration( | 60 GetDispatcher()->FindServiceWorkerRegistration( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 GetDispatcher()->UnregisterServiceWorker( | 94 GetDispatcher()->UnregisterServiceWorker( |
| 95 provider_id_, pattern, callbacks); | 95 provider_id_, pattern, callbacks); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void WebServiceWorkerProviderImpl::getRegistration( | 98 void WebServiceWorkerProviderImpl::getRegistration( |
| 99 const blink::WebURL& document_url, | 99 const blink::WebURL& document_url, |
| 100 WebServiceWorkerRegistrationCallbacks* callbacks) { | 100 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 101 GetDispatcher()->GetRegistration(provider_id_, document_url, callbacks); | 101 GetDispatcher()->GetRegistration(provider_id_, document_url, callbacks); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void WebServiceWorkerProviderImpl::RemoveScriptClient() { | 104 void WebServiceWorkerProviderImpl::RemoveProviderClient() { |
| 105 // Remove the script client, but only if the dispatcher is still there. | 105 // Remove the provider client, but only if the dispatcher is still there. |
| 106 // (For cleanup path we don't need to bother creating a new dispatcher) | 106 // (For cleanup path we don't need to bother creating a new dispatcher) |
| 107 ServiceWorkerDispatcher* dispatcher = | 107 ServiceWorkerDispatcher* dispatcher = |
| 108 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 108 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
| 109 if (dispatcher) | 109 if (dispatcher) |
| 110 dispatcher->RemoveScriptClient(provider_id_); | 110 dispatcher->RemoveProviderClient(provider_id_); |
| 111 } | 111 } |
| 112 | 112 |
| 113 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { | 113 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { |
| 114 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 114 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 115 thread_safe_sender_.get()); | 115 thread_safe_sender_.get()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace content | 118 } // namespace content |
| OLD | NEW |