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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (info.handle_id == kInvalidServiceWorkerHandleId) | 183 if (info.handle_id == kInvalidServiceWorkerHandleId) |
184 return NULL; | 184 return NULL; |
185 | 185 |
186 WorkerObjectMap::iterator existing_worker = | 186 WorkerObjectMap::iterator existing_worker = |
187 service_workers_.find(info.handle_id); | 187 service_workers_.find(info.handle_id); |
188 | 188 |
189 if (existing_worker != service_workers_.end()) { | 189 if (existing_worker != service_workers_.end()) { |
190 if (adopt_handle) { | 190 if (adopt_handle) { |
191 // We are instructed to adopt a handle but we already have one, so | 191 // We are instructed to adopt a handle but we already have one, so |
192 // adopt and destroy a handle ref. | 192 // adopt and destroy a handle ref. |
193 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 193 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
194 } | 194 } |
195 return existing_worker->second; | 195 return existing_worker->second; |
196 } | 196 } |
197 | 197 |
198 scoped_ptr<ServiceWorkerHandleReference> handle_ref = | 198 scoped_ptr<ServiceWorkerHandleReference> handle_ref = |
199 adopt_handle | 199 adopt_handle |
200 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_) | 200 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()) |
201 : ServiceWorkerHandleReference::Create(info, thread_safe_sender_); | 201 : ServiceWorkerHandleReference::Create(info, |
| 202 thread_safe_sender_.get()); |
202 // WebServiceWorkerImpl constructor calls AddServiceWorker. | 203 // WebServiceWorkerImpl constructor calls AddServiceWorker. |
203 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_); | 204 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_.get()); |
204 } | 205 } |
205 | 206 |
206 WebServiceWorkerRegistrationImpl* | 207 WebServiceWorkerRegistrationImpl* |
207 ServiceWorkerDispatcher::GetServiceWorkerRegistration( | 208 ServiceWorkerDispatcher::GetServiceWorkerRegistration( |
208 const ServiceWorkerRegistrationObjectInfo& info, | 209 const ServiceWorkerRegistrationObjectInfo& info, |
209 bool adopt_handle) { | 210 bool adopt_handle) { |
210 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) | 211 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) |
211 return NULL; | 212 return NULL; |
212 | 213 |
213 RegistrationObjectMap::iterator existing_registration = | 214 RegistrationObjectMap::iterator existing_registration = |
214 registrations_.find(info.handle_id); | 215 registrations_.find(info.handle_id); |
215 | 216 |
216 if (existing_registration != registrations_.end()) { | 217 if (existing_registration != registrations_.end()) { |
217 if (adopt_handle) { | 218 if (adopt_handle) { |
218 // We are instructed to adopt a handle but we already have one, so | 219 // We are instructed to adopt a handle but we already have one, so |
219 // adopt and destroy a handle ref. | 220 // adopt and destroy a handle ref. |
220 ServiceWorkerRegistrationHandleReference::Adopt( | 221 ServiceWorkerRegistrationHandleReference::Adopt( |
221 info, thread_safe_sender_); | 222 info, thread_safe_sender_.get()); |
222 } | 223 } |
223 return existing_registration->second; | 224 return existing_registration->second; |
224 } | 225 } |
225 | 226 |
226 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = | 227 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = |
227 adopt_handle | 228 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( |
228 ? ServiceWorkerRegistrationHandleReference::Adopt( | 229 info, thread_safe_sender_.get()) |
229 info, thread_safe_sender_) | 230 : ServiceWorkerRegistrationHandleReference::Create( |
230 : ServiceWorkerRegistrationHandleReference::Create( | 231 info, thread_safe_sender_.get()); |
231 info, thread_safe_sender_); | |
232 | 232 |
233 // WebServiceWorkerRegistrationImpl constructor calls | 233 // WebServiceWorkerRegistrationImpl constructor calls |
234 // AddServiceWorkerRegistration. | 234 // AddServiceWorkerRegistration. |
235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); | 235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); |
236 } | 236 } |
237 | 237 |
238 void ServiceWorkerDispatcher::OnRegistered( | 238 void ServiceWorkerDispatcher::OnRegistered( |
239 int thread_id, | 239 int thread_id, |
240 int request_id, | 240 int request_id, |
241 const ServiceWorkerRegistrationObjectInfo& info) { | 241 const ServiceWorkerRegistrationObjectInfo& info) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 registrations_[registration_handle_id] = registration; | 467 registrations_[registration_handle_id] = registration; |
468 } | 468 } |
469 | 469 |
470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
471 int registration_handle_id) { | 471 int registration_handle_id) { |
472 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 472 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
473 registrations_.erase(registration_handle_id); | 473 registrations_.erase(registration_handle_id); |
474 } | 474 } |
475 | 475 |
476 } // namespace content | 476 } // namespace content |
OLD | NEW |