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 // Check all stored and initially installing registrations of this origin is | |
168 // enough for claiming documents. | |
falken
2015/01/30 10:24:02
I'd change this comment to a TODO to not have to h
xiang
2015/02/02 04:24:58
Done.
| |
169 context_->storage()->GetRegistrationsForOrigin( | |
170 pattern_.GetOrigin(), | |
171 base::Bind(&ServiceWorkerRegistration::DidGetRegistrationsForClaimClients, | |
172 this, callback, active_version_)); | |
173 } | |
174 | |
164 void ServiceWorkerRegistration::ClearWhenReady() { | 175 void ServiceWorkerRegistration::ClearWhenReady() { |
165 DCHECK(context_); | 176 DCHECK(context_); |
166 if (is_uninstalling_) | 177 if (is_uninstalling_) |
167 return; | 178 return; |
168 is_uninstalling_ = true; | 179 is_uninstalling_ = true; |
169 | 180 |
170 context_->storage()->NotifyUninstallingRegistration(this); | 181 context_->storage()->NotifyUninstallingRegistration(this); |
171 context_->storage()->DeleteRegistration( | 182 context_->storage()->DeleteRegistration( |
172 id(), | 183 id(), |
173 pattern().GetOrigin(), | 184 pattern().GetOrigin(), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 ServiceWorkerStatusCode status) { | 364 ServiceWorkerStatusCode status) { |
354 if (!context_) { | 365 if (!context_) { |
355 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 366 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
356 return; | 367 return; |
357 } | 368 } |
358 context_->storage()->NotifyDoneInstallingRegistration( | 369 context_->storage()->NotifyDoneInstallingRegistration( |
359 this, version.get(), status); | 370 this, version.get(), status); |
360 callback.Run(status); | 371 callback.Run(status); |
361 } | 372 } |
362 | 373 |
374 void ServiceWorkerRegistration::DidGetRegistrationsForClaimClients( | |
375 const StatusCallback& callback, | |
376 scoped_refptr<ServiceWorkerVersion> version, | |
377 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | |
378 if (!context_) { | |
379 callback.Run(SERVICE_WORKER_ERROR_ABORT); | |
380 return; | |
381 } | |
382 if (!active_version() || version != active_version()) { | |
383 callback.Run(SERVICE_WORKER_ERROR_STATE); | |
384 return; | |
385 } | |
386 | |
387 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | |
388 context_->GetProviderHostIterator(); | |
389 !it->IsAtEnd(); it->Advance()) { | |
390 ServiceWorkerProviderHost* host = it->GetProviderHost(); | |
391 if (ShouldClaim(host, registrations)) | |
392 host->ClaimedByRegistration(this); | |
393 } | |
394 callback.Run(SERVICE_WORKER_OK); | |
395 } | |
396 | |
397 bool ServiceWorkerRegistration::ShouldClaim( | |
398 ServiceWorkerProviderHost* provider_host, | |
399 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | |
400 if (provider_host->controlling_version() == active_version()) | |
401 return false; | |
402 | |
403 LongestScopeMatcher matcher(provider_host->document_url()); | |
404 if (!matcher.MatchLongest(pattern_)) | |
405 return false; | |
406 for (const ServiceWorkerRegistrationInfo& info : registrations) { | |
407 ServiceWorkerRegistration* registration = | |
408 context_->GetLiveRegistration(info.registration_id); | |
409 if (registration && registration->is_uninstalled()) | |
xiang
2015/01/30 07:18:57
Only live registrations maybe uninstalled during G
| |
410 continue; | |
411 if (matcher.MatchLongest(info.pattern)) | |
michaeln
2015/01/30 23:43:07
given a docurl and a matchingscope, this function
xiang
2015/02/02 04:24:58
Done.
| |
412 return false; | |
413 } | |
414 return true; | |
415 } | |
416 | |
363 } // namespace content | 417 } // namespace content |
OLD | NEW |