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 std::vector<ServiceWorkerRegistrationInfo> 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 (ShouldClaim(host, infos)) |
| 174 host->UseRegistration(this); |
| 175 } |
| 176 } |
| 177 |
164 void ServiceWorkerRegistration::ClearWhenReady() { | 178 void ServiceWorkerRegistration::ClearWhenReady() { |
165 DCHECK(context_); | 179 DCHECK(context_); |
166 if (is_uninstalling_) | 180 if (is_uninstalling_) |
167 return; | 181 return; |
168 is_uninstalling_ = true; | 182 is_uninstalling_ = true; |
169 | 183 |
170 context_->storage()->NotifyUninstallingRegistration(this); | 184 context_->storage()->NotifyUninstallingRegistration(this); |
171 context_->storage()->DeleteRegistration( | 185 context_->storage()->DeleteRegistration( |
172 id(), | 186 id(), |
173 pattern().GetOrigin(), | 187 pattern().GetOrigin(), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 ServiceWorkerStatusCode status) { | 367 ServiceWorkerStatusCode status) { |
354 if (!context_) { | 368 if (!context_) { |
355 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 369 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
356 return; | 370 return; |
357 } | 371 } |
358 context_->storage()->NotifyDoneInstallingRegistration( | 372 context_->storage()->NotifyDoneInstallingRegistration( |
359 this, version.get(), status); | 373 this, version.get(), status); |
360 callback.Run(status); | 374 callback.Run(status); |
361 } | 375 } |
362 | 376 |
| 377 bool ServiceWorkerRegistration::ShouldClaim( |
| 378 ServiceWorkerProviderHost* provider_host, |
| 379 std::vector<ServiceWorkerRegistrationInfo>& registration_infos) { |
| 380 if (!ServiceWorkerUtils::ScopeMatches(pattern_, |
| 381 provider_host->document_url())) |
| 382 return false; |
| 383 |
| 384 LongestScopeMatcher matcher(provider_host->document_url()); |
| 385 int64 match = kInvalidServiceWorkerRegistrationId; |
| 386 for (std::vector<ServiceWorkerRegistrationInfo>::iterator it = |
| 387 registration_infos.begin(); |
| 388 it != registration_infos.end(); ++it) { |
| 389 ServiceWorkerRegistration* registration = |
| 390 context_->GetLiveRegistration(it->registration_id); |
| 391 if (!registration || registration->is_uninstalled()) |
| 392 continue; |
| 393 if (matcher.MatchLongest(it->pattern)) |
| 394 match = it->registration_id; |
| 395 } |
| 396 |
| 397 if (match != registration_id_) |
| 398 return false; |
| 399 if (provider_host->controlling_version() == active_version()) |
| 400 return false; |
| 401 return true; |
| 402 } |
| 403 |
363 } // namespace content | 404 } // namespace content |
OLD | NEW |