| 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_register_job.h" | 5 #include "content/browser/service_worker/service_worker_register_job.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 ServiceWorkerRegistration* ServiceWorkerRegisterJob::registration() { | 90 ServiceWorkerRegistration* ServiceWorkerRegisterJob::registration() { |
| 91 DCHECK(phase_ >= REGISTER) << phase_; | 91 DCHECK(phase_ >= REGISTER) << phase_; |
| 92 DCHECK(internal_.registration); | 92 DCHECK(internal_.registration); |
| 93 return internal_.registration; | 93 return internal_.registration; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ServiceWorkerRegisterJob::set_pending_version( | 96 void ServiceWorkerRegisterJob::set_pending_version( |
| 97 ServiceWorkerVersion* version) { | 97 ServiceWorkerVersion* version) { |
| 98 DCHECK(phase_ == UPDATE || phase_ == ACTIVATE) << phase_; | 98 DCHECK(phase_ == UPDATE) << phase_; |
| 99 DCHECK(!internal_.pending_version || !version); | 99 DCHECK(!internal_.pending_version); |
| 100 internal_.pending_version = version; | 100 internal_.pending_version = version; |
| 101 } | 101 } |
| 102 | 102 |
| 103 ServiceWorkerVersion* ServiceWorkerRegisterJob::pending_version() { | 103 ServiceWorkerVersion* ServiceWorkerRegisterJob::pending_version() { |
| 104 DCHECK(phase_ >= UPDATE) << phase_; | 104 DCHECK(phase_ >= UPDATE) << phase_; |
| 105 return internal_.pending_version; | 105 return internal_.pending_version; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ServiceWorkerRegisterJob::SetPhase(Phase phase) { | 108 void ServiceWorkerRegisterJob::SetPhase(Phase phase) { |
| 109 switch (phase) { | 109 switch (phase) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (registration() && !registration()->active_version()) { | 368 if (registration() && !registration()->active_version()) { |
| 369 context_->storage()->DeleteRegistration( | 369 context_->storage()->DeleteRegistration( |
| 370 registration()->id(), | 370 registration()->id(), |
| 371 registration()->script_url().GetOrigin(), | 371 registration()->script_url().GetOrigin(), |
| 372 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 372 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 373 } | 373 } |
| 374 if (!is_promise_resolved_) | 374 if (!is_promise_resolved_) |
| 375 ResolvePromise(status, NULL, NULL); | 375 ResolvePromise(status, NULL, NULL); |
| 376 } | 376 } |
| 377 DCHECK(callbacks_.empty()); | 377 DCHECK(callbacks_.empty()); |
| 378 context_->storage()->NotifyDoneInstallingRegistration(registration()); | 378 if (registration()) |
| 379 context_->storage()->NotifyDoneInstallingRegistration(registration()); |
| 379 context_->job_coordinator()->FinishJob(pattern_, this); | 380 context_->job_coordinator()->FinishJob(pattern_, this); |
| 380 } | 381 } |
| 381 | 382 |
| 382 void ServiceWorkerRegisterJob::ResolvePromise( | 383 void ServiceWorkerRegisterJob::ResolvePromise( |
| 383 ServiceWorkerStatusCode status, | 384 ServiceWorkerStatusCode status, |
| 384 ServiceWorkerRegistration* registration, | 385 ServiceWorkerRegistration* registration, |
| 385 ServiceWorkerVersion* version) { | 386 ServiceWorkerVersion* version) { |
| 386 DCHECK(!is_promise_resolved_); | 387 DCHECK(!is_promise_resolved_); |
| 387 is_promise_resolved_ = true; | 388 is_promise_resolved_ = true; |
| 388 promise_resolved_status_ = status; | 389 promise_resolved_status_ = status; |
| 389 promise_resolved_registration_ = registration; | 390 promise_resolved_registration_ = registration; |
| 390 promise_resolved_version_ = version; | 391 promise_resolved_version_ = version; |
| 391 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); | 392 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); |
| 392 it != callbacks_.end(); | 393 it != callbacks_.end(); |
| 393 ++it) { | 394 ++it) { |
| 394 it->Run(status, registration, version); | 395 it->Run(status, registration, version); |
| 395 } | 396 } |
| 396 callbacks_.clear(); | 397 callbacks_.clear(); |
| 397 } | 398 } |
| 398 | 399 |
| 399 void ServiceWorkerRegisterJob::AssociatePendingVersionToDocuments( | 400 void ServiceWorkerRegisterJob::AssociatePendingVersionToDocuments( |
| 400 ServiceWorkerVersion* version) { | 401 ServiceWorkerVersion* version) { |
| 401 // TODO(michaeln): This needs to respect the longest prefix wins | 402 // TODO(michaeln): This needs to respect the longest prefix wins |
| 402 // when it comes to finding a registration for a document url. | 403 // when it comes to finding a registration for a document url. |
| 403 // This should should utilize storage->FindRegistrationForDocument(). | 404 // This should utilize storage->FindRegistrationForDocument(). |
| 404 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | 405 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 405 context_->GetProviderHostIterator(); | 406 context_->GetProviderHostIterator(); |
| 406 !it->IsAtEnd(); | 407 !it->IsAtEnd(); |
| 407 it->Advance()) { | 408 it->Advance()) { |
| 408 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); | 409 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); |
| 409 if (ServiceWorkerUtils::ScopeMatches(pattern_, | 410 if (ServiceWorkerUtils::ScopeMatches(pattern_, |
| 410 provider_host->document_url())) | 411 provider_host->document_url())) |
| 411 provider_host->SetPendingVersion(version); | 412 provider_host->SetPendingVersion(version); |
| 412 } | 413 } |
| 413 } | 414 } |
| 414 | 415 |
| 415 } // namespace content | 416 } // namespace content |
| OLD | NEW |