Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 486083002: ServiceWorker: Introduce ServiceWorkerRegistrationObjectInfo for cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_)
201 : ServiceWorkerHandleReference::Create(info, thread_safe_sender_); 201 : ServiceWorkerHandleReference::Create(info, thread_safe_sender_);
202 // WebServiceWorkerImpl constructor calls AddServiceWorker. 202 // WebServiceWorkerImpl constructor calls AddServiceWorker.
203 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_); 203 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_);
204 } 204 }
205 205
206 WebServiceWorkerRegistrationImpl* 206 WebServiceWorkerRegistrationImpl*
207 ServiceWorkerDispatcher::GetServiceWorkerRegistration( 207 ServiceWorkerDispatcher::GetServiceWorkerRegistration(
208 int registration_handle_id, 208 const ServiceWorkerRegistrationObjectInfo& info,
209 const ServiceWorkerObjectInfo& info,
210 bool adopt_handle) { 209 bool adopt_handle) {
211 if (registration_handle_id == kInvalidServiceWorkerRegistrationHandleId) 210 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId)
212 return NULL; 211 return NULL;
213 212
214 RegistrationObjectMap::iterator existing_registration = 213 RegistrationObjectMap::iterator existing_registration =
215 registrations_.find(registration_handle_id); 214 registrations_.find(info.handle_id);
216 215
217 if (existing_registration != registrations_.end()) { 216 if (existing_registration != registrations_.end()) {
218 if (adopt_handle) { 217 if (adopt_handle) {
219 // We are instructed to adopt a handle but we already have one, so 218 // We are instructed to adopt a handle but we already have one, so
220 // adopt and destroy a handle ref. 219 // adopt and destroy a handle ref.
221 ServiceWorkerRegistrationHandleReference::Adopt( 220 ServiceWorkerRegistrationHandleReference::Adopt(
222 registration_handle_id, info, thread_safe_sender_); 221 info, thread_safe_sender_);
223 } 222 }
224 return existing_registration->second; 223 return existing_registration->second;
225 } 224 }
226 225
227 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = 226 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref =
228 adopt_handle 227 adopt_handle
229 ? ServiceWorkerRegistrationHandleReference::Adopt( 228 ? ServiceWorkerRegistrationHandleReference::Adopt(
230 registration_handle_id, info, thread_safe_sender_) 229 info, thread_safe_sender_)
231 : ServiceWorkerRegistrationHandleReference::Create( 230 : ServiceWorkerRegistrationHandleReference::Create(
232 registration_handle_id, info, thread_safe_sender_); 231 info, thread_safe_sender_);
233 232
234 // WebServiceWorkerRegistrationImpl constructor calls 233 // WebServiceWorkerRegistrationImpl constructor calls
235 // AddServiceWorkerRegistration. 234 // AddServiceWorkerRegistration.
236 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); 235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass());
237 } 236 }
238 237
239 void ServiceWorkerDispatcher::OnRegistered( 238 void ServiceWorkerDispatcher::OnRegistered(
240 int thread_id, 239 int thread_id,
241 int request_id, 240 int request_id,
242 int registration_handle_id, 241 const ServiceWorkerRegistrationObjectInfo& info) {
243 const ServiceWorkerObjectInfo& info) {
244 WebServiceWorkerRegistrationCallbacks* callbacks = 242 WebServiceWorkerRegistrationCallbacks* callbacks =
245 pending_callbacks_.Lookup(request_id); 243 pending_callbacks_.Lookup(request_id);
246 DCHECK(callbacks); 244 DCHECK(callbacks);
247 if (!callbacks) 245 if (!callbacks)
248 return; 246 return;
249 247
250 callbacks->onSuccess(GetServiceWorkerRegistration( 248 callbacks->onSuccess(GetServiceWorkerRegistration(info, true));
251 registration_handle_id, info, true));
252
253 // The handle ref is unused, so adopt and destroy it.
254 // TODO(nhiroki): ServiceWorkerDispatcherHost don't have to pass a handle ref.
255 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
256
257 pending_callbacks_.Remove(request_id); 249 pending_callbacks_.Remove(request_id);
258 } 250 }
259 251
260 void ServiceWorkerDispatcher::OnUnregistered( 252 void ServiceWorkerDispatcher::OnUnregistered(
261 int thread_id, 253 int thread_id,
262 int request_id) { 254 int request_id) {
263 WebServiceWorkerRegistrationCallbacks* callbacks = 255 WebServiceWorkerRegistrationCallbacks* callbacks =
264 pending_callbacks_.Lookup(request_id); 256 pending_callbacks_.Lookup(request_id);
265 DCHECK(callbacks); 257 DCHECK(callbacks);
266 if (!callbacks) 258 if (!callbacks)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 registrations_[registration_handle_id] = registration; 467 registrations_[registration_handle_id] = registration;
476 } 468 }
477 469
478 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
479 int registration_handle_id) { 471 int registration_handle_id) {
480 DCHECK(ContainsKey(registrations_, registration_handle_id)); 472 DCHECK(ContainsKey(registrations_, registration_handle_id));
481 registrations_.erase(registration_handle_id); 473 registrations_.erase(registration_handle_id);
482 } 474 }
483 475
484 } // namespace content 476 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/service_worker_dispatcher.h ('k') | content/child/service_worker/service_worker_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698