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(const StatusCallback& callback) { |
| 165 DCHECK(context_); |
| 166 DCHECK(active_version()); |
| 167 // TODO(xiang): Should better not hit the database http://crbug.com/454250. |
| 168 context_->storage()->GetRegistrationsForOrigin( |
| 169 pattern_.GetOrigin(), |
| 170 base::Bind(&ServiceWorkerRegistration::DidGetRegistrationsForClaimClients, |
| 171 this, callback, active_version_)); |
| 172 } |
| 173 |
164 void ServiceWorkerRegistration::ClearWhenReady() { | 174 void ServiceWorkerRegistration::ClearWhenReady() { |
165 DCHECK(context_); | 175 DCHECK(context_); |
166 if (is_uninstalling_) | 176 if (is_uninstalling_) |
167 return; | 177 return; |
168 is_uninstalling_ = true; | 178 is_uninstalling_ = true; |
169 | 179 |
170 context_->storage()->NotifyUninstallingRegistration(this); | 180 context_->storage()->NotifyUninstallingRegistration(this); |
171 context_->storage()->DeleteRegistration( | 181 context_->storage()->DeleteRegistration( |
172 id(), | 182 id(), |
173 pattern().GetOrigin(), | 183 pattern().GetOrigin(), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 ServiceWorkerStatusCode status) { | 363 ServiceWorkerStatusCode status) { |
354 if (!context_) { | 364 if (!context_) { |
355 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 365 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
356 return; | 366 return; |
357 } | 367 } |
358 context_->storage()->NotifyDoneInstallingRegistration( | 368 context_->storage()->NotifyDoneInstallingRegistration( |
359 this, version.get(), status); | 369 this, version.get(), status); |
360 callback.Run(status); | 370 callback.Run(status); |
361 } | 371 } |
362 | 372 |
| 373 void ServiceWorkerRegistration::DidGetRegistrationsForClaimClients( |
| 374 const StatusCallback& callback, |
| 375 scoped_refptr<ServiceWorkerVersion> version, |
| 376 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
| 377 if (!context_) { |
| 378 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 379 return; |
| 380 } |
| 381 if (!active_version() || version != active_version()) { |
| 382 callback.Run(SERVICE_WORKER_ERROR_STATE); |
| 383 return; |
| 384 } |
| 385 |
| 386 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 387 context_->GetProviderHostIterator(); |
| 388 !it->IsAtEnd(); it->Advance()) { |
| 389 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 390 if (ShouldClaim(host, registrations)) |
| 391 host->ClaimedByRegistration(this); |
| 392 } |
| 393 callback.Run(SERVICE_WORKER_OK); |
| 394 } |
| 395 |
| 396 bool ServiceWorkerRegistration::ShouldClaim( |
| 397 ServiceWorkerProviderHost* provider_host, |
| 398 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
| 399 if (provider_host->controlling_version() == active_version()) |
| 400 return false; |
| 401 |
| 402 LongestScopeMatcher matcher(provider_host->document_url()); |
| 403 if (!matcher.MatchLongest(pattern_)) |
| 404 return false; |
| 405 for (const ServiceWorkerRegistrationInfo& info : registrations) { |
| 406 ServiceWorkerRegistration* registration = |
| 407 context_->GetLiveRegistration(info.registration_id); |
| 408 if (registration && |
| 409 (registration->is_uninstalling() || registration->is_uninstalled())) |
| 410 continue; |
| 411 if (matcher.MatchLongest(info.pattern)) |
| 412 return false; |
| 413 } |
| 414 return true; |
| 415 } |
| 416 |
363 } // namespace content | 417 } // namespace content |
OLD | NEW |