OLD | NEW |
---|---|
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 Loading... | |
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 // Live registrations contains longest matched registrations in database | |
168 // and new registrations on the fly. So we can just check these living ones. | |
falken
2015/01/29 15:10:37
Maybe more clear to say: "It's sufficient to only
michaeln
2015/01/29 22:35:34
Not so sure about this comment? I think its incorr
| |
169 std::vector<ServiceWorkerRegistrationInfo> infos = | |
170 context_->GetAllLiveRegistrationInfo(); | |
171 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | |
172 context_->GetProviderHostIterator(); | |
173 !it->IsAtEnd(); it->Advance()) { | |
174 ServiceWorkerProviderHost* host = it->GetProviderHost(); | |
175 if (!ShouldClaim(host, infos)) | |
176 continue; | |
177 if (host->associated_registration() == this) { | |
178 host->ClaimedByNewVersion(); | |
179 continue; | |
180 } | |
181 host->DisassociateRegistration(); | |
falken
2015/01/29 15:10:37
It seems strange to preemptively Disassociate and
michaeln
2015/01/29 22:35:34
Agreed, the most direct thing to do might be to ad
| |
182 // There will still chance that a new registration triggers claim | |
183 // while a navigation is happening. | |
falken
2015/01/29 15:10:37
I'm not sure what this comment is intended to be a
| |
184 if (host->CanAssociateRegistration(this)) | |
185 host->AssociateRegistration(this); | |
186 } | |
187 } | |
188 | |
164 void ServiceWorkerRegistration::ClearWhenReady() { | 189 void ServiceWorkerRegistration::ClearWhenReady() { |
165 DCHECK(context_); | 190 DCHECK(context_); |
166 if (is_uninstalling_) | 191 if (is_uninstalling_) |
167 return; | 192 return; |
168 is_uninstalling_ = true; | 193 is_uninstalling_ = true; |
169 | 194 |
170 context_->storage()->NotifyUninstallingRegistration(this); | 195 context_->storage()->NotifyUninstallingRegistration(this); |
171 context_->storage()->DeleteRegistration( | 196 context_->storage()->DeleteRegistration( |
172 id(), | 197 id(), |
173 pattern().GetOrigin(), | 198 pattern().GetOrigin(), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 ServiceWorkerStatusCode status) { | 378 ServiceWorkerStatusCode status) { |
354 if (!context_) { | 379 if (!context_) { |
355 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 380 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
356 return; | 381 return; |
357 } | 382 } |
358 context_->storage()->NotifyDoneInstallingRegistration( | 383 context_->storage()->NotifyDoneInstallingRegistration( |
359 this, version.get(), status); | 384 this, version.get(), status); |
360 callback.Run(status); | 385 callback.Run(status); |
361 } | 386 } |
362 | 387 |
388 bool ServiceWorkerRegistration::ShouldClaim( | |
389 ServiceWorkerProviderHost* provider_host, | |
390 std::vector<ServiceWorkerRegistrationInfo>& registration_infos) { | |
391 if (!ServiceWorkerUtils::ScopeMatches( | |
392 pattern_, provider_host->document_url())) | |
393 return false; | |
394 | |
395 LongestScopeMatcher matcher(provider_host->document_url()); | |
396 int64 match = kInvalidServiceWorkerRegistrationId; | |
397 for (std::vector<ServiceWorkerRegistrationInfo>::iterator it = | |
398 registration_infos.begin(); | |
399 it != registration_infos.end(); ++it) { | |
400 ServiceWorkerRegistration* registration = | |
401 context_->GetLiveRegistration(it->registration_id); | |
402 if (!registration || registration->is_uninstalled()) | |
michaeln
2015/01/29 22:35:34
I think FindRegistrationForDocument would return '
xiang
2015/01/30 07:18:57
Yes, I think so, the spec defined this behavior.
| |
403 continue; | |
404 if (matcher.MatchLongest(it->pattern)) | |
405 match = it->registration_id; | |
406 } | |
407 | |
408 if (match != registration_id_) | |
409 return false; | |
410 if (provider_host->controlling_version() == active_version()) | |
411 return false; | |
falken
2015/01/29 15:10:37
small optimization: we could move this check to th
michaeln
2015/01/29 22:35:34
another small opt: seed the matcher with the match
xiang
2015/01/30 07:18:57
Done.
| |
412 return true; | |
413 } | |
414 | |
363 } // namespace content | 415 } // namespace content |
OLD | NEW |