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

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

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 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 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/browser/service_worker/service_worker_unregister_job.h" 5 #include "content/browser/service_worker/service_worker_unregister_job.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_job_coordinator.h" 9 #include "content/browser/service_worker/service_worker_job_coordinator.h"
10 #include "content/browser/service_worker/service_worker_registration.h" 10 #include "content/browser/service_worker/service_worker_registration.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return; 67 return;
68 } 68 }
69 69
70 // TODO: "7. If registration.updatePromise is not null..." 70 // TODO: "7. If registration.updatePromise is not null..."
71 71
72 // "8. Resolve promise." 72 // "8. Resolve promise."
73 ResolvePromise(SERVICE_WORKER_OK); 73 ResolvePromise(SERVICE_WORKER_OK);
74 74
75 registration->ClearWhenReady(); 75 registration->ClearWhenReady();
76 76
77 UnassociateProviderHostsFromRegistration(registration);
77 Complete(SERVICE_WORKER_OK); 78 Complete(SERVICE_WORKER_OK);
78 } 79 }
79 80
80 void ServiceWorkerUnregisterJob::Complete(ServiceWorkerStatusCode status) { 81 void ServiceWorkerUnregisterJob::Complete(ServiceWorkerStatusCode status) {
81 CompleteInternal(status); 82 CompleteInternal(status);
82 context_->job_coordinator()->FinishJob(pattern_, this); 83 context_->job_coordinator()->FinishJob(pattern_, this);
83 } 84 }
84 85
85 void ServiceWorkerUnregisterJob::CompleteInternal( 86 void ServiceWorkerUnregisterJob::CompleteInternal(
86 ServiceWorkerStatusCode status) { 87 ServiceWorkerStatusCode status) {
87 if (!is_promise_resolved_) 88 if (!is_promise_resolved_)
88 ResolvePromise(status); 89 ResolvePromise(status);
89 } 90 }
90 91
91 void ServiceWorkerUnregisterJob::ResolvePromise( 92 void ServiceWorkerUnregisterJob::ResolvePromise(
92 ServiceWorkerStatusCode status) { 93 ServiceWorkerStatusCode status) {
93 DCHECK(!is_promise_resolved_); 94 DCHECK(!is_promise_resolved_);
94 is_promise_resolved_ = true; 95 is_promise_resolved_ = true;
95 for (std::vector<UnregistrationCallback>::iterator it = callbacks_.begin(); 96 for (std::vector<UnregistrationCallback>::iterator it = callbacks_.begin();
96 it != callbacks_.end(); 97 it != callbacks_.end();
97 ++it) { 98 ++it) {
98 it->Run(status); 99 it->Run(status);
99 } 100 }
100 } 101 }
101 102
103 void ServiceWorkerUnregisterJob::UnassociateProviderHostsFromRegistration(
104 ServiceWorkerRegistration* registration) {
105 DCHECK(registration);
106 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
107 context_->GetProviderHostIterator();
108 !it->IsAtEnd(); it->Advance()) {
109 ServiceWorkerProviderHost* host = it->GetProviderHost();
110 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(),
111 host->document_url())) {
112 if (host->associated_registration()->id() == registration->id())
113 host->UnassociateRegistration();
michaeln 2014/09/04 00:27:23 This does not look right? The unreg doesn't reall
nhiroki 2014/09/08 15:55:51 Ah, yes. This is not correct. Removed.
114 }
115 }
116 }
117
102 } // namespace content 118 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698