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

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

Issue 871853002: ServiceWorker: add ServiceWorkerClients.claim() support (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change error type Created 5 years, 11 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
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 154 }
155 155
156 void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() { 156 void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
157 DCHECK(waiting_version()); 157 DCHECK(waiting_version());
158 should_activate_when_ready_ = true; 158 should_activate_when_ready_ = true;
159 if (!active_version() || !active_version()->HasControllee() || 159 if (!active_version() || !active_version()->HasControllee() ||
160 waiting_version()->skip_waiting()) 160 waiting_version()->skip_waiting())
161 ActivateWaitingVersion(); 161 ActivateWaitingVersion();
162 } 162 }
163 163
164 void ServiceWorkerRegistration::ClaimClients() {
165 DCHECK(context_);
166 DCHECK(active_version());
167 std::vector<ServiceWorkerRegistrationInfo> registration_infos =
168 context_->GetAllLiveRegistrationInfo();
169 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
170 context_->GetProviderHostIterator();
171 !it->IsAtEnd(); it->Advance()) {
172 ServiceWorkerProviderHost* host = it->GetProviderHost();
173 if (host->document_url().GetOrigin() != pattern_.GetOrigin())
174 continue;
175
176 LongestScopeMatcher matcher(host->document_url());
177 int64 match = kInvalidServiceWorkerRegistrationId;
178 for (std::vector<ServiceWorkerRegistrationInfo>::iterator it =
michaeln 2015/01/28 00:55:13 This inner loop is not so nice. I think we can avo
xiang 2015/01/28 05:38:35 Yes, move out the inner loop is more cleaner. How
falken 2015/01/28 08:59:49 I think you're right, "/foob" shouldn't claim the
michaeln 2015/01/28 21:11:14 Thats too bad because it adds code complexity and
xiang 2015/01/29 02:58:37 I thought about FindRegistrationForDocument() when
falken 2015/01/29 03:28:50 I suspected this might be the case too. Michael, w
179 registration_infos.begin();
180 it != registration_infos.end(); ++it) {
181 ServiceWorkerRegistration* registration =
182 context_->GetLiveRegistration(it->registration_id);
183 DCHECK(registration);
184 if (registration->is_uninstalled())
185 continue;
186 if (matcher.MatchLongest(it->pattern))
187 match = it->registration_id;
188 }
189 if (match != registration_id_)
190 continue;
191 if (host->controlling_version() == active_version())
192 continue;
193
194 host->SetController(this);
195 }
196 }
197
164 void ServiceWorkerRegistration::ClearWhenReady() { 198 void ServiceWorkerRegistration::ClearWhenReady() {
165 DCHECK(context_); 199 DCHECK(context_);
166 if (is_uninstalling_) 200 if (is_uninstalling_)
167 return; 201 return;
168 is_uninstalling_ = true; 202 is_uninstalling_ = true;
169 203
170 context_->storage()->NotifyUninstallingRegistration(this); 204 context_->storage()->NotifyUninstallingRegistration(this);
171 context_->storage()->DeleteRegistration( 205 context_->storage()->DeleteRegistration(
172 id(), 206 id(),
173 pattern().GetOrigin(), 207 pattern().GetOrigin(),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (!context_) { 388 if (!context_) {
355 callback.Run(SERVICE_WORKER_ERROR_ABORT); 389 callback.Run(SERVICE_WORKER_ERROR_ABORT);
356 return; 390 return;
357 } 391 }
358 context_->storage()->NotifyDoneInstallingRegistration( 392 context_->storage()->NotifyDoneInstallingRegistration(
359 this, version.get(), status); 393 this, version.get(), status);
360 callback.Run(status); 394 callback.Run(status);
361 } 395 }
362 396
363 } // namespace content 397 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698