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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // keep the associated registration and the controller until | 39 // keep the associated registration and the controller until |
40 // ServiceWorkerContainer is initialized. | 40 // ServiceWorkerContainer is initialized. |
41 class ServiceWorkerProviderContext::ControlleeDelegate | 41 class ServiceWorkerProviderContext::ControlleeDelegate |
42 : public ServiceWorkerProviderContext::Delegate { | 42 : public ServiceWorkerProviderContext::Delegate { |
43 public: | 43 public: |
44 ControlleeDelegate() {} | 44 ControlleeDelegate() {} |
45 ~ControlleeDelegate() override {} | 45 ~ControlleeDelegate() override {} |
46 | 46 |
47 void AssociateRegistration( | 47 void AssociateRegistration( |
48 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, | 48 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, |
49 std::unique_ptr<ServiceWorkerHandleReference> installing, | 49 std::unique_ptr<ServiceWorkerHandleReference> /* installing */, |
50 std::unique_ptr<ServiceWorkerHandleReference> waiting, | 50 std::unique_ptr<ServiceWorkerHandleReference> /* waiting */, |
51 std::unique_ptr<ServiceWorkerHandleReference> active) override { | 51 std::unique_ptr<ServiceWorkerHandleReference> /* active */) override { |
52 DCHECK(!registration_); | 52 DCHECK(!registration_); |
53 registration_ = std::move(registration); | 53 registration_ = std::move(registration); |
54 } | 54 } |
55 | 55 |
56 void DisassociateRegistration() override { | 56 void DisassociateRegistration() override { |
57 controller_.reset(); | 57 controller_.reset(); |
58 registration_.reset(); | 58 registration_.reset(); |
59 } | 59 } |
60 | 60 |
61 void SetController( | 61 void SetController( |
62 std::unique_ptr<ServiceWorkerHandleReference> controller) override { | 62 std::unique_ptr<ServiceWorkerHandleReference> controller) override { |
63 DCHECK(registration_); | 63 DCHECK(registration_); |
64 DCHECK(!controller || | 64 DCHECK(!controller || |
65 controller->handle_id() != kInvalidServiceWorkerHandleId); | 65 controller->handle_id() != kInvalidServiceWorkerHandleId); |
66 controller_ = std::move(controller); | 66 controller_ = std::move(controller); |
67 } | 67 } |
68 | 68 |
69 bool HasAssociatedRegistration() override { return !!registration_; } | 69 bool HasAssociatedRegistration() override { return !!registration_; } |
70 | 70 |
71 void GetAssociatedRegistration( | 71 void GetAssociatedRegistration( |
72 ServiceWorkerRegistrationObjectInfo* info, | 72 ServiceWorkerRegistrationObjectInfo* /* info */, |
73 ServiceWorkerVersionAttributes* attrs) override { | 73 ServiceWorkerVersionAttributes* /* attrs */) override { |
74 NOTREACHED(); | 74 NOTREACHED(); |
75 } | 75 } |
76 | 76 |
77 ServiceWorkerHandleReference* controller() override { | 77 ServiceWorkerHandleReference* controller() override { |
78 return controller_.get(); | 78 return controller_.get(); |
79 } | 79 } |
80 | 80 |
81 private: | 81 private: |
82 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration_; | 82 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration_; |
83 std::unique_ptr<ServiceWorkerHandleReference> controller_; | 83 std::unique_ptr<ServiceWorkerHandleReference> controller_; |
(...skipping 20 matching lines...) Expand all Loading... |
104 waiting_ = std::move(waiting); | 104 waiting_ = std::move(waiting); |
105 active_ = std::move(active); | 105 active_ = std::move(active); |
106 } | 106 } |
107 | 107 |
108 void DisassociateRegistration() override { | 108 void DisassociateRegistration() override { |
109 // ServiceWorkerGlobalScope is never disassociated. | 109 // ServiceWorkerGlobalScope is never disassociated. |
110 NOTREACHED(); | 110 NOTREACHED(); |
111 } | 111 } |
112 | 112 |
113 void SetController( | 113 void SetController( |
114 std::unique_ptr<ServiceWorkerHandleReference> controller) override { | 114 std::unique_ptr<ServiceWorkerHandleReference> /* controller */) override { |
115 NOTREACHED(); | 115 NOTREACHED(); |
116 } | 116 } |
117 | 117 |
118 bool HasAssociatedRegistration() override { return !!registration_; } | 118 bool HasAssociatedRegistration() override { return !!registration_; } |
119 | 119 |
120 void GetAssociatedRegistration( | 120 void GetAssociatedRegistration( |
121 ServiceWorkerRegistrationObjectInfo* info, | 121 ServiceWorkerRegistrationObjectInfo* info, |
122 ServiceWorkerVersionAttributes* attrs) override { | 122 ServiceWorkerVersionAttributes* attrs) override { |
123 DCHECK(HasAssociatedRegistration()); | 123 DCHECK(HasAssociatedRegistration()); |
124 *info = registration_->info(); | 124 *info = registration_->info(); |
(...skipping 15 matching lines...) Expand all Loading... |
140 std::unique_ptr<ServiceWorkerHandleReference> installing_; | 140 std::unique_ptr<ServiceWorkerHandleReference> installing_; |
141 std::unique_ptr<ServiceWorkerHandleReference> waiting_; | 141 std::unique_ptr<ServiceWorkerHandleReference> waiting_; |
142 std::unique_ptr<ServiceWorkerHandleReference> active_; | 142 std::unique_ptr<ServiceWorkerHandleReference> active_; |
143 | 143 |
144 DISALLOW_COPY_AND_ASSIGN(ControllerDelegate); | 144 DISALLOW_COPY_AND_ASSIGN(ControllerDelegate); |
145 }; | 145 }; |
146 | 146 |
147 ServiceWorkerProviderContext::ServiceWorkerProviderContext( | 147 ServiceWorkerProviderContext::ServiceWorkerProviderContext( |
148 int provider_id, | 148 int provider_id, |
149 ServiceWorkerProviderType provider_type, | 149 ServiceWorkerProviderType provider_type, |
| 150 mojom::ServiceWorkerProviderAssociatedRequest request, |
150 ThreadSafeSender* thread_safe_sender) | 151 ThreadSafeSender* thread_safe_sender) |
151 : provider_id_(provider_id), | 152 : provider_id_(provider_id), |
152 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 153 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
153 thread_safe_sender_(thread_safe_sender) { | 154 thread_safe_sender_(thread_safe_sender), |
| 155 binding_(this, std::move(request)) { |
154 if (provider_type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) | 156 if (provider_type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) |
155 delegate_.reset(new ControllerDelegate); | 157 delegate_.reset(new ControllerDelegate); |
156 else | 158 else |
157 delegate_.reset(new ControlleeDelegate); | 159 delegate_.reset(new ControlleeDelegate); |
158 | 160 |
159 ServiceWorkerDispatcher* dispatcher = | 161 ServiceWorkerDispatcher* dispatcher = |
160 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 162 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
161 thread_safe_sender_.get(), main_thread_task_runner_.get()); | 163 thread_safe_sender_.get(), main_thread_task_runner_.get()); |
162 dispatcher->AddProviderContext(this); | 164 dispatcher->AddProviderContext(this); |
163 } | 165 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 214 |
213 void ServiceWorkerProviderContext::DestructOnMainThread() const { | 215 void ServiceWorkerProviderContext::DestructOnMainThread() const { |
214 if (!main_thread_task_runner_->RunsTasksInCurrentSequence() && | 216 if (!main_thread_task_runner_->RunsTasksInCurrentSequence() && |
215 main_thread_task_runner_->DeleteSoon(FROM_HERE, this)) { | 217 main_thread_task_runner_->DeleteSoon(FROM_HERE, this)) { |
216 return; | 218 return; |
217 } | 219 } |
218 delete this; | 220 delete this; |
219 } | 221 } |
220 | 222 |
221 } // namespace content | 223 } // namespace content |
OLD | NEW |