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

Side by Side Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 224733014: Introduce ServiceWorkerHandle for tracking WebServiceWorkerImpl reference (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sigh, rebased Created 6 years, 8 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/browser/service_worker/service_worker_register_job.h" 5 #include "content/browser/service_worker/service_worker_register_job.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_job_coordinator.h" 10 #include "content/browser/service_worker/service_worker_job_coordinator.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // registration and abort. 78 // registration and abort.
79 if (registration.get() && registration->script_url() == script_url_) { 79 if (registration.get() && registration->script_url() == script_url_) {
80 registration_ = registration; 80 registration_ = registration;
81 // If there's no active version, go ahead to Update (this isn't in the spec 81 // If there's no active version, go ahead to Update (this isn't in the spec
82 // but seems reasonable, and without SoftUpdate implemented we can never 82 // but seems reasonable, and without SoftUpdate implemented we can never
83 // Update otherwise). 83 // Update otherwise).
84 if (!registration_->active_version()) { 84 if (!registration_->active_version()) {
85 UpdateAndContinue(status); 85 UpdateAndContinue(status);
86 return; 86 return;
87 } 87 }
88 RunCallbacks(status, registration_->active_version()); 88 RunCallbacks(status, registration_, registration_->active_version());
89 Complete(SERVICE_WORKER_OK); 89 Complete(SERVICE_WORKER_OK);
90 return; 90 return;
91 } 91 }
92 92
93 // "If serviceWorkerRegistration is null..." create a new registration. 93 // "If serviceWorkerRegistration is null..." create a new registration.
94 if (!registration.get()) { 94 if (!registration.get()) {
95 RegisterAndContinue(SERVICE_WORKER_OK); 95 RegisterAndContinue(SERVICE_WORKER_OK);
96 return; 96 return;
97 } 97 }
98 98
99 // On script URL mismatch, "set serviceWorkerRegistration.scriptUrl to 99 // On script URL mismatch, "set serviceWorkerRegistration.scriptUrl to
100 // script." We accomplish this by deleting the existing registration and 100 // script." We accomplish this by deleting the existing registration and
101 // registering a new one. 101 // registering a new one.
102 // TODO(falken): Match the spec. We now throw away the active_version_ and 102 // TODO(falken): Match the spec. We now throw away the active_version_ and
103 // pending_version_ of the existing registration, which isn't in the spec. 103 // pending_version_ of the existing registration, which isn't in the spec.
104 registration->Shutdown();
105 context_->storage()->DeleteRegistration( 104 context_->storage()->DeleteRegistration(
106 pattern_, 105 pattern_,
107 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue, 106 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue,
108 weak_factory_.GetWeakPtr())); 107 weak_factory_.GetWeakPtr()));
109 } 108 }
110 109
111 // Registers a new ServiceWorkerRegistration. 110 // Registers a new ServiceWorkerRegistration.
112 void ServiceWorkerRegisterJob::RegisterAndContinue( 111 void ServiceWorkerRegisterJob::RegisterAndContinue(
113 ServiceWorkerStatusCode status) { 112 ServiceWorkerStatusCode status) {
114 DCHECK(!registration_); 113 DCHECK(!registration_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 Complete(status); 166 Complete(status);
168 return; 167 return;
169 } 168 }
170 169
171 // "Resolve promise with serviceWorker." 170 // "Resolve promise with serviceWorker."
172 // Although the spec doesn't set pendingWorker until after resolving the 171 // Although the spec doesn't set pendingWorker until after resolving the
173 // promise, our system's resolving works by passing ServiceWorkerRegistration 172 // promise, our system's resolving works by passing ServiceWorkerRegistration
174 // to the callbacks, so pendingWorker must be set first. 173 // to the callbacks, so pendingWorker must be set first.
175 DCHECK(!registration_->pending_version()); 174 DCHECK(!registration_->pending_version());
176 registration_->set_pending_version(pending_version_); 175 registration_->set_pending_version(pending_version_);
177 RunCallbacks(status, pending_version_.get()); 176 RunCallbacks(status, registration_, pending_version_.get());
178 177
179 InstallAndContinue(); 178 InstallAndContinue();
180 } 179 }
181 180
182 // This function corresponds to the spec's _Install algorithm. 181 // This function corresponds to the spec's _Install algorithm.
183 void ServiceWorkerRegisterJob::InstallAndContinue() { 182 void ServiceWorkerRegisterJob::InstallAndContinue() {
184 // "Set serviceWorkerRegistration.pendingWorker._state to installing." 183 // "Set serviceWorkerRegistration.pendingWorker._state to installing."
185 // "Fire install event on the associated ServiceWorkerGlobalScope object." 184 // "Fire install event on the associated ServiceWorkerGlobalScope object."
186 pending_version_->DispatchInstallEvent( 185 pending_version_->DispatchInstallEvent(
187 -1, 186 -1,
(...skipping 27 matching lines...) Expand all
215 registration_->set_active_version(pending_version_); 214 registration_->set_active_version(pending_version_);
216 pending_version_ = NULL; 215 pending_version_ = NULL;
217 Complete(SERVICE_WORKER_OK); 216 Complete(SERVICE_WORKER_OK);
218 } 217 }
219 218
220 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { 219 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) {
221 // In success case the callbacks must have been dispatched already 220 // In success case the callbacks must have been dispatched already
222 // (so this is no-op), otherwise we must have come here for abort case, 221 // (so this is no-op), otherwise we must have come here for abort case,
223 // so dispatch callbacks with NULL. 222 // so dispatch callbacks with NULL.
224 DCHECK(callbacks_.empty() || status != SERVICE_WORKER_OK); 223 DCHECK(callbacks_.empty() || status != SERVICE_WORKER_OK);
225 RunCallbacks(status, NULL); 224 RunCallbacks(status, NULL, NULL);
226
227 // If |pending_version_| exists, it was not activated, so we are the sole
228 // owner of it, so it will be destroyed when this job ends, so Shutdown here.
229 // We should be able to remove this code later, when something else holds a
230 // reference to |pending_version_|.
231 // TODO(kinuko): Fix these ownership and shutdown semantics.
232 if (pending_version_) {
233 DCHECK(!registration_->pending_version());
234 DCHECK(!registration_->active_version());
235 pending_version_->Shutdown();
236 }
237 225
238 context_->job_coordinator()->FinishJob(pattern_, this); 226 context_->job_coordinator()->FinishJob(pattern_, this);
239 } 227 }
240 228
241 void ServiceWorkerRegisterJob::RunCallbacks(ServiceWorkerStatusCode status, 229 void ServiceWorkerRegisterJob::RunCallbacks(
242 ServiceWorkerVersion* version) { 230 ServiceWorkerStatusCode status,
231 ServiceWorkerRegistration* registration,
232 ServiceWorkerVersion* version) {
243 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); 233 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin();
244 it != callbacks_.end(); 234 it != callbacks_.end();
245 ++it) { 235 ++it) {
246 it->Run(status, version); 236 it->Run(status, registration, version);
247 } 237 }
248 callbacks_.clear(); 238 callbacks_.clear();
249 } 239 }
250 240
251 } // namespace content 241 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698