| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_provider_context.h" | 5 #include "content/child/service_worker/service_worker_provider_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/child/child_thread_impl.h" | 11 #include "content/child/child_thread_impl.h" |
| 12 #include "content/child/service_worker/service_worker_dispatcher.h" | 12 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 13 #include "content/child/service_worker/service_worker_handle_reference.h" | 13 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 14 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 14 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 15 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
| 16 #include "content/child/worker_thread_registry.h" | 16 #include "content/child/worker_thread_registry.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 class ServiceWorkerProviderContext::Delegate { | 20 class ServiceWorkerProviderContext::Delegate { |
| 21 public: | 21 public: |
| 22 virtual ~Delegate(){}; | 22 virtual ~Delegate(){}; |
| 23 virtual void AssociateRegistration( | 23 virtual void AssociateRegistration( |
| 24 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration, | 24 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, |
| 25 scoped_ptr<ServiceWorkerHandleReference> installing, | 25 std::unique_ptr<ServiceWorkerHandleReference> installing, |
| 26 scoped_ptr<ServiceWorkerHandleReference> waiting, | 26 std::unique_ptr<ServiceWorkerHandleReference> waiting, |
| 27 scoped_ptr<ServiceWorkerHandleReference> active) = 0; | 27 std::unique_ptr<ServiceWorkerHandleReference> active) = 0; |
| 28 virtual void DisassociateRegistration() = 0; | 28 virtual void DisassociateRegistration() = 0; |
| 29 virtual void GetAssociatedRegistration( | 29 virtual void GetAssociatedRegistration( |
| 30 ServiceWorkerRegistrationObjectInfo* info, | 30 ServiceWorkerRegistrationObjectInfo* info, |
| 31 ServiceWorkerVersionAttributes* attrs) = 0; | 31 ServiceWorkerVersionAttributes* attrs) = 0; |
| 32 virtual void SetController( | 32 virtual void SetController( |
| 33 scoped_ptr<ServiceWorkerHandleReference> controller) = 0; | 33 std::unique_ptr<ServiceWorkerHandleReference> controller) = 0; |
| 34 virtual ServiceWorkerHandleReference* controller() = 0; | 34 virtual ServiceWorkerHandleReference* controller() = 0; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // Delegate class for ServiceWorker client (Document, SharedWorker, etc) to | 37 // Delegate class for ServiceWorker client (Document, SharedWorker, etc) to |
| 38 // keep the associated registration and the controller until | 38 // keep the associated registration and the controller until |
| 39 // ServiceWorkerContainer is initialized. | 39 // ServiceWorkerContainer is initialized. |
| 40 class ServiceWorkerProviderContext::ControlleeDelegate | 40 class ServiceWorkerProviderContext::ControlleeDelegate |
| 41 : public ServiceWorkerProviderContext::Delegate { | 41 : public ServiceWorkerProviderContext::Delegate { |
| 42 public: | 42 public: |
| 43 ControlleeDelegate() {} | 43 ControlleeDelegate() {} |
| 44 ~ControlleeDelegate() override {} | 44 ~ControlleeDelegate() override {} |
| 45 | 45 |
| 46 void AssociateRegistration( | 46 void AssociateRegistration( |
| 47 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration, | 47 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, |
| 48 scoped_ptr<ServiceWorkerHandleReference> installing, | 48 std::unique_ptr<ServiceWorkerHandleReference> installing, |
| 49 scoped_ptr<ServiceWorkerHandleReference> waiting, | 49 std::unique_ptr<ServiceWorkerHandleReference> waiting, |
| 50 scoped_ptr<ServiceWorkerHandleReference> active) override { | 50 std::unique_ptr<ServiceWorkerHandleReference> active) override { |
| 51 DCHECK(!registration_); | 51 DCHECK(!registration_); |
| 52 registration_ = std::move(registration); | 52 registration_ = std::move(registration); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void DisassociateRegistration() override { | 55 void DisassociateRegistration() override { |
| 56 controller_.reset(); | 56 controller_.reset(); |
| 57 registration_.reset(); | 57 registration_.reset(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void SetController( | 60 void SetController( |
| 61 scoped_ptr<ServiceWorkerHandleReference> controller) override { | 61 std::unique_ptr<ServiceWorkerHandleReference> controller) override { |
| 62 DCHECK(registration_); | 62 DCHECK(registration_); |
| 63 DCHECK(!controller || | 63 DCHECK(!controller || |
| 64 controller->handle_id() != kInvalidServiceWorkerHandleId); | 64 controller->handle_id() != kInvalidServiceWorkerHandleId); |
| 65 controller_ = std::move(controller); | 65 controller_ = std::move(controller); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void GetAssociatedRegistration( | 68 void GetAssociatedRegistration( |
| 69 ServiceWorkerRegistrationObjectInfo* info, | 69 ServiceWorkerRegistrationObjectInfo* info, |
| 70 ServiceWorkerVersionAttributes* attrs) override { | 70 ServiceWorkerVersionAttributes* attrs) override { |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 ServiceWorkerHandleReference* controller() override { | 74 ServiceWorkerHandleReference* controller() override { |
| 75 return controller_.get(); | 75 return controller_.get(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; | 79 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration_; |
| 80 scoped_ptr<ServiceWorkerHandleReference> controller_; | 80 std::unique_ptr<ServiceWorkerHandleReference> controller_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(ControlleeDelegate); | 82 DISALLOW_COPY_AND_ASSIGN(ControlleeDelegate); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // Delegate class for ServiceWorkerGlobalScope to keep the associated | 85 // Delegate class for ServiceWorkerGlobalScope to keep the associated |
| 86 // registration and its versions until the execution context is initialized. | 86 // registration and its versions until the execution context is initialized. |
| 87 class ServiceWorkerProviderContext::ControllerDelegate | 87 class ServiceWorkerProviderContext::ControllerDelegate |
| 88 : public ServiceWorkerProviderContext::Delegate { | 88 : public ServiceWorkerProviderContext::Delegate { |
| 89 public: | 89 public: |
| 90 ControllerDelegate() {} | 90 ControllerDelegate() {} |
| 91 ~ControllerDelegate() override {} | 91 ~ControllerDelegate() override {} |
| 92 | 92 |
| 93 void AssociateRegistration( | 93 void AssociateRegistration( |
| 94 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration, | 94 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, |
| 95 scoped_ptr<ServiceWorkerHandleReference> installing, | 95 std::unique_ptr<ServiceWorkerHandleReference> installing, |
| 96 scoped_ptr<ServiceWorkerHandleReference> waiting, | 96 std::unique_ptr<ServiceWorkerHandleReference> waiting, |
| 97 scoped_ptr<ServiceWorkerHandleReference> active) override { | 97 std::unique_ptr<ServiceWorkerHandleReference> active) override { |
| 98 DCHECK(!registration_); | 98 DCHECK(!registration_); |
| 99 registration_ = std::move(registration); | 99 registration_ = std::move(registration); |
| 100 installing_ = std::move(installing); | 100 installing_ = std::move(installing); |
| 101 waiting_ = std::move(waiting); | 101 waiting_ = std::move(waiting); |
| 102 active_ = std::move(active); | 102 active_ = std::move(active); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void DisassociateRegistration() override { | 105 void DisassociateRegistration() override { |
| 106 // ServiceWorkerGlobalScope is never disassociated. | 106 // ServiceWorkerGlobalScope is never disassociated. |
| 107 NOTREACHED(); | 107 NOTREACHED(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void SetController( | 110 void SetController( |
| 111 scoped_ptr<ServiceWorkerHandleReference> controller) override { | 111 std::unique_ptr<ServiceWorkerHandleReference> controller) override { |
| 112 NOTREACHED(); | 112 NOTREACHED(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void GetAssociatedRegistration( | 115 void GetAssociatedRegistration( |
| 116 ServiceWorkerRegistrationObjectInfo* info, | 116 ServiceWorkerRegistrationObjectInfo* info, |
| 117 ServiceWorkerVersionAttributes* attrs) override { | 117 ServiceWorkerVersionAttributes* attrs) override { |
| 118 DCHECK(registration_); | 118 DCHECK(registration_); |
| 119 *info = registration_->info(); | 119 *info = registration_->info(); |
| 120 if (installing_) | 120 if (installing_) |
| 121 attrs->installing = installing_->info(); | 121 attrs->installing = installing_->info(); |
| 122 if (waiting_) | 122 if (waiting_) |
| 123 attrs->waiting = waiting_->info(); | 123 attrs->waiting = waiting_->info(); |
| 124 if (active_) | 124 if (active_) |
| 125 attrs->active = active_->info(); | 125 attrs->active = active_->info(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 ServiceWorkerHandleReference* controller() override { | 128 ServiceWorkerHandleReference* controller() override { |
| 129 NOTREACHED(); | 129 NOTREACHED(); |
| 130 return nullptr; | 130 return nullptr; |
| 131 } | 131 } |
| 132 | 132 |
| 133 private: | 133 private: |
| 134 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; | 134 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration_; |
| 135 scoped_ptr<ServiceWorkerHandleReference> installing_; | 135 std::unique_ptr<ServiceWorkerHandleReference> installing_; |
| 136 scoped_ptr<ServiceWorkerHandleReference> waiting_; | 136 std::unique_ptr<ServiceWorkerHandleReference> waiting_; |
| 137 scoped_ptr<ServiceWorkerHandleReference> active_; | 137 std::unique_ptr<ServiceWorkerHandleReference> active_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(ControllerDelegate); | 139 DISALLOW_COPY_AND_ASSIGN(ControllerDelegate); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 ServiceWorkerProviderContext::ServiceWorkerProviderContext( | 142 ServiceWorkerProviderContext::ServiceWorkerProviderContext( |
| 143 int provider_id, | 143 int provider_id, |
| 144 ServiceWorkerProviderType provider_type, | 144 ServiceWorkerProviderType provider_type, |
| 145 ThreadSafeSender* thread_safe_sender) | 145 ThreadSafeSender* thread_safe_sender) |
| 146 : provider_id_(provider_id), | 146 : provider_id_(provider_id), |
| 147 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 147 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 159 | 159 |
| 160 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { | 160 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { |
| 161 if (ServiceWorkerDispatcher* dispatcher = | 161 if (ServiceWorkerDispatcher* dispatcher = |
| 162 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { | 162 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { |
| 163 // Remove this context from the dispatcher living on the main thread. | 163 // Remove this context from the dispatcher living on the main thread. |
| 164 dispatcher->RemoveProviderContext(this); | 164 dispatcher->RemoveProviderContext(this); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 void ServiceWorkerProviderContext::OnAssociateRegistration( | 168 void ServiceWorkerProviderContext::OnAssociateRegistration( |
| 169 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration, | 169 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, |
| 170 scoped_ptr<ServiceWorkerHandleReference> installing, | 170 std::unique_ptr<ServiceWorkerHandleReference> installing, |
| 171 scoped_ptr<ServiceWorkerHandleReference> waiting, | 171 std::unique_ptr<ServiceWorkerHandleReference> waiting, |
| 172 scoped_ptr<ServiceWorkerHandleReference> active) { | 172 std::unique_ptr<ServiceWorkerHandleReference> active) { |
| 173 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 173 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 174 delegate_->AssociateRegistration(std::move(registration), | 174 delegate_->AssociateRegistration(std::move(registration), |
| 175 std::move(installing), std::move(waiting), | 175 std::move(installing), std::move(waiting), |
| 176 std::move(active)); | 176 std::move(active)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void ServiceWorkerProviderContext::OnDisassociateRegistration() { | 179 void ServiceWorkerProviderContext::OnDisassociateRegistration() { |
| 180 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 180 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 181 delegate_->DisassociateRegistration(); | 181 delegate_->DisassociateRegistration(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( | 184 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( |
| 185 scoped_ptr<ServiceWorkerHandleReference> controller) { | 185 std::unique_ptr<ServiceWorkerHandleReference> controller) { |
| 186 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 186 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 187 delegate_->SetController(std::move(controller)); | 187 delegate_->SetController(std::move(controller)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void ServiceWorkerProviderContext::GetAssociatedRegistration( | 190 void ServiceWorkerProviderContext::GetAssociatedRegistration( |
| 191 ServiceWorkerRegistrationObjectInfo* info, | 191 ServiceWorkerRegistrationObjectInfo* info, |
| 192 ServiceWorkerVersionAttributes* attrs) { | 192 ServiceWorkerVersionAttributes* attrs) { |
| 193 DCHECK(!main_thread_task_runner_->RunsTasksOnCurrentThread()); | 193 DCHECK(!main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 194 delegate_->GetAssociatedRegistration(info, attrs); | 194 delegate_->GetAssociatedRegistration(info, attrs); |
| 195 } | 195 } |
| 196 | 196 |
| 197 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { | 197 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { |
| 198 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 198 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 199 return delegate_->controller(); | 199 return delegate_->controller(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void ServiceWorkerProviderContext::DestructOnMainThread() const { | 202 void ServiceWorkerProviderContext::DestructOnMainThread() const { |
| 203 if (!main_thread_task_runner_->RunsTasksOnCurrentThread() && | 203 if (!main_thread_task_runner_->RunsTasksOnCurrentThread() && |
| 204 main_thread_task_runner_->DeleteSoon(FROM_HERE, this)) { | 204 main_thread_task_runner_->DeleteSoon(FROM_HERE, this)) { |
| 205 return; | 205 return; |
| 206 } | 206 } |
| 207 delete this; | 207 delete this; |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace content | 210 } // namespace content |
| OLD | NEW |