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

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

Issue 417043006: ServiceWorker: Make SWProviderHost listen to SWRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address michael's comments 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/browser/service_worker/service_worker_registration.h" 5 #include "content/browser/service_worker/service_worker_registration.h"
6 6
7 #include "content/browser/service_worker/service_worker_context_core.h" 7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_info.h" 8 #include "content/browser/service_worker/service_worker_info.h"
9 #include "content/browser/service_worker/service_worker_register_job.h" 9 #include "content/browser/service_worker/service_worker_register_job.h"
10 #include "content/browser/service_worker/service_worker_utils.h" 10 #include "content/browser/service_worker/service_worker_utils.h"
(...skipping 22 matching lines...) Expand all
33 is_deleted_(false), 33 is_deleted_(false),
34 should_activate_when_ready_(false), 34 should_activate_when_ready_(false),
35 context_(context) { 35 context_(context) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 DCHECK(context_); 37 DCHECK(context_);
38 context_->AddLiveRegistration(this); 38 context_->AddLiveRegistration(this);
39 } 39 }
40 40
41 ServiceWorkerRegistration::~ServiceWorkerRegistration() { 41 ServiceWorkerRegistration::~ServiceWorkerRegistration() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 DCHECK(!listeners_.might_have_observers());
43 if (context_) 44 if (context_)
44 context_->RemoveLiveRegistration(registration_id_); 45 context_->RemoveLiveRegistration(registration_id_);
45 ResetShouldActivateWhenReady(); 46 ResetShouldActivateWhenReady();
46 } 47 }
47 48
48 void ServiceWorkerRegistration::AddListener(Listener* listener) { 49 void ServiceWorkerRegistration::AddListener(Listener* listener) {
49 listeners_.AddObserver(listener); 50 listeners_.AddObserver(listener);
50 } 51 }
51 52
52 void ServiceWorkerRegistration::RemoveListener(Listener* listener) { 53 void ServiceWorkerRegistration::RemoveListener(Listener* listener) {
53 listeners_.RemoveObserver(listener); 54 listeners_.RemoveObserver(listener);
54 } 55 }
55 56
57 void ServiceWorkerRegistration::NotifyRegistrationFailed() {
58 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this));
59 }
60
56 ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() { 61 ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
58 return ServiceWorkerRegistrationInfo( 63 return ServiceWorkerRegistrationInfo(
59 script_url(), 64 script_url(),
60 pattern(), 65 pattern(),
61 registration_id_, 66 registration_id_,
62 GetVersionInfo(active_version_), 67 GetVersionInfo(active_version_),
63 GetVersionInfo(waiting_version_), 68 GetVersionInfo(waiting_version_),
64 GetVersionInfo(installing_version_)); 69 GetVersionInfo(installing_version_));
65 } 70 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // "2. Terminate exitingWorker." 173 // "2. Terminate exitingWorker."
169 exiting_version->StopWorker( 174 exiting_version->StopWorker(
170 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 175 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
171 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and 176 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and
172 // "redundant" as the arguments." 177 // "redundant" as the arguments."
173 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); 178 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT);
174 } 179 }
175 180
176 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." 181 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker."
177 // "6. Set serviceWorkerRegistration.waitingWorker to null." 182 // "6. Set serviceWorkerRegistration.waitingWorker to null."
178 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments(
179 context_, activating_version);
180 SetActiveVersion(activating_version); 183 SetActiveVersion(activating_version);
181 ServiceWorkerRegisterJob::AssociateActiveVersionToDocuments(
182 context_, activating_version);
183 184
184 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and 185 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and
185 // "activating" as arguments." 186 // "activating" as arguments."
186 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); 187 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING);
187 188
188 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." 189 // TODO(nhiroki): "8. Fire a simple event named controllerchange..."
189 190
190 // "9. Queue a task to fire an event named activate..." 191 // "9. Queue a task to fire an event named activate..."
191 activating_version->DispatchActivateEvent( 192 activating_version->DispatchActivateEvent(
192 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, 193 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished,
193 this, activating_version)); 194 this, activating_version));
194 } 195 }
195 196
196 void ServiceWorkerRegistration::OnActivateEventFinished( 197 void ServiceWorkerRegistration::OnActivateEventFinished(
197 ServiceWorkerVersion* activating_version, 198 ServiceWorkerVersion* activating_version,
198 ServiceWorkerStatusCode status) { 199 ServiceWorkerStatusCode status) {
199 if (!context_ || activating_version != active_version()) 200 if (!context_ || activating_version != active_version())
200 return; 201 return;
201 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is 202 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is
202 // unexpectedly terminated) we may want to retry sending the event again. 203 // unexpectedly terminated) we may want to retry sending the event again.
203 if (status != SERVICE_WORKER_OK) { 204 if (status != SERVICE_WORKER_OK) {
204 // "11. If activateFailed is true, then:..." 205 // "11. If activateFailed is true, then:..."
205 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments(
206 context_, activating_version);
207 UnsetVersion(activating_version); 206 UnsetVersion(activating_version);
208 activating_version->Doom(); 207 activating_version->Doom();
209 if (!waiting_version()) { 208 if (!waiting_version()) {
210 // Delete the records from the db. 209 // Delete the records from the db.
211 context_->storage()->DeleteRegistration( 210 context_->storage()->DeleteRegistration(
212 id(), script_url().GetOrigin(), 211 id(), script_url().GetOrigin(),
213 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); 212 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this));
214 // But not from memory if there is a version in the pipeline. 213 // But not from memory if there is a version in the pipeline.
215 if (installing_version()) 214 if (installing_version())
216 is_deleted_ = false; 215 is_deleted_ = false;
(...skipping 18 matching lines...) Expand all
235 } 234 }
236 } 235 }
237 236
238 void ServiceWorkerRegistration::OnDeleteFinished( 237 void ServiceWorkerRegistration::OnDeleteFinished(
239 ServiceWorkerStatusCode status) { 238 ServiceWorkerStatusCode status) {
240 // Intentionally empty completion callback, used to prevent 239 // Intentionally empty completion callback, used to prevent
241 // |this| from being deleted until the storage method completes. 240 // |this| from being deleted until the storage method completes.
242 } 241 }
243 242
244 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698