Chromium Code Reviews| 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 "content/child/service_worker/service_worker_dispatcher.h" | 7 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 8 #include "content/child/service_worker/service_worker_handle_reference.h" | 8 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 9 #include "content/child/service_worker/service_worker_provider_context.h" | 9 #include "content/child/service_worker/service_worker_provider_context.h" |
| 10 #include "content/child/service_worker/web_service_worker_impl.h" | 10 #include "content/child/service_worker/web_service_worker_impl.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 // Make sure the provider client is removed. | 27 // Make sure the provider client is removed. |
| 28 RemoveProviderClient(); | 28 RemoveProviderClient(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void WebServiceWorkerProviderImpl::setClient( | 31 void WebServiceWorkerProviderImpl::setClient( |
| 32 blink::WebServiceWorkerProviderClient* client) { | 32 blink::WebServiceWorkerProviderClient* client) { |
| 33 if (!client) { | 33 if (!client) { |
| 34 RemoveProviderClient(); | 34 RemoveProviderClient(); |
| 35 return; | 35 return; |
| 36 } | 36 } |
| 37 if (!context_) | |
|
kinuko
2015/06/23 10:55:56
Can we add a comment about when context_ is null,
horo
2015/06/23 13:55:13
After https://codereview.chromium.org/1199183002/,
| |
| 38 return; | |
| 37 | 39 |
| 38 // TODO(kinuko): Here we could also register the current thread ID | 40 // TODO(kinuko): Here we could also register the current thread ID |
| 39 // on the provider context so that multiple WebServiceWorkerProviderImpl | 41 // on the provider context so that multiple WebServiceWorkerProviderImpl |
| 40 // (e.g. on document and on dedicated workers) can properly share | 42 // (e.g. on document and on dedicated workers) can properly share |
| 41 // the single provider context across threads. (http://crbug.com/366538 | 43 // the single provider context across threads. (http://crbug.com/366538 |
| 42 // for more context) | 44 // for more context) |
| 43 GetDispatcher()->AddProviderClient(context_->provider_id(), client); | 45 GetDispatcher()->AddProviderClient(context_->provider_id(), client); |
| 44 | 46 |
| 45 if (!context_->controller()) | 47 if (!context_->controller()) |
| 46 return; | 48 return; |
| 47 client->setController( | 49 client->setController( |
| 48 GetDispatcher()->GetServiceWorker(context_->controller()->info(), false), | 50 GetDispatcher()->GetServiceWorker(context_->controller()->info(), false), |
| 49 false /* shouldNotifyControllerChange */); | 51 false /* shouldNotifyControllerChange */); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void WebServiceWorkerProviderImpl::registerServiceWorker( | 54 void WebServiceWorkerProviderImpl::registerServiceWorker( |
| 53 const WebURL& pattern, | 55 const WebURL& pattern, |
| 54 const WebURL& script_url, | 56 const WebURL& script_url, |
| 55 WebServiceWorkerRegistrationCallbacks* callbacks) { | 57 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 58 if (!context_) | |
| 59 return; | |
|
kinuko
2015/06/23 10:55:56
Hmm, we'll leak callbacks. Also is it ok not to f
horo
2015/06/23 13:55:14
Same as the former
| |
| 56 GetDispatcher()->RegisterServiceWorker( | 60 GetDispatcher()->RegisterServiceWorker( |
| 57 context_->provider_id(), pattern, script_url, callbacks); | 61 context_->provider_id(), pattern, script_url, callbacks); |
| 58 } | 62 } |
| 59 | 63 |
| 60 void WebServiceWorkerProviderImpl::getRegistration( | 64 void WebServiceWorkerProviderImpl::getRegistration( |
| 61 const blink::WebURL& document_url, | 65 const blink::WebURL& document_url, |
| 62 WebServiceWorkerRegistrationCallbacks* callbacks) { | 66 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 67 if (!context_) | |
| 68 return; | |
| 63 GetDispatcher()->GetRegistration( | 69 GetDispatcher()->GetRegistration( |
| 64 context_->provider_id(), document_url, callbacks); | 70 context_->provider_id(), document_url, callbacks); |
| 65 } | 71 } |
| 66 | 72 |
| 67 void WebServiceWorkerProviderImpl::getRegistrations( | 73 void WebServiceWorkerProviderImpl::getRegistrations( |
| 68 WebServiceWorkerGetRegistrationsCallbacks* callbacks) { | 74 WebServiceWorkerGetRegistrationsCallbacks* callbacks) { |
| 75 if (!context_) | |
| 76 return; | |
| 69 GetDispatcher()->GetRegistrations( | 77 GetDispatcher()->GetRegistrations( |
| 70 context_->provider_id(), callbacks); | 78 context_->provider_id(), callbacks); |
| 71 } | 79 } |
| 72 | 80 |
| 73 void WebServiceWorkerProviderImpl::getRegistrationForReady( | 81 void WebServiceWorkerProviderImpl::getRegistrationForReady( |
| 74 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { | 82 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { |
| 83 if (!context_) | |
| 84 return; | |
| 75 GetDispatcher()->GetRegistrationForReady(context_->provider_id(), callbacks); | 85 GetDispatcher()->GetRegistrationForReady(context_->provider_id(), callbacks); |
| 76 } | 86 } |
| 77 | 87 |
| 78 int WebServiceWorkerProviderImpl::provider_id() const { | 88 int WebServiceWorkerProviderImpl::provider_id() const { |
| 89 if (!context_) | |
| 90 return kInvalidServiceWorkerProviderId; | |
| 79 return context_->provider_id(); | 91 return context_->provider_id(); |
| 80 } | 92 } |
| 81 | 93 |
| 82 void WebServiceWorkerProviderImpl::RemoveProviderClient() { | 94 void WebServiceWorkerProviderImpl::RemoveProviderClient() { |
| 95 if (!context_) | |
| 96 return; | |
| 83 // Remove the provider client, but only if the dispatcher is still there. | 97 // Remove the provider client, but only if the dispatcher is still there. |
| 84 // (For cleanup path we don't need to bother creating a new dispatcher) | 98 // (For cleanup path we don't need to bother creating a new dispatcher) |
| 85 ServiceWorkerDispatcher* dispatcher = | 99 ServiceWorkerDispatcher* dispatcher = |
| 86 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 100 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
| 87 if (dispatcher) | 101 if (dispatcher) |
| 88 dispatcher->RemoveProviderClient(context_->provider_id()); | 102 dispatcher->RemoveProviderClient(context_->provider_id()); |
| 89 } | 103 } |
| 90 | 104 |
| 91 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { | 105 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { |
| 92 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 106 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 93 thread_safe_sender_.get()); | 107 thread_safe_sender_.get()); |
| 94 } | 108 } |
| 95 | 109 |
| 96 } // namespace content | 110 } // namespace content |
| OLD | NEW |