Chromium Code Reviews| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 if (status != SERVICE_WORKER_OK) { | 225 if (status != SERVICE_WORKER_OK) { |
| 226 Complete(status); | 226 Complete(status); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 if (existing_registration != registration()) { | 230 if (existing_registration != registration()) { |
| 231 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); | 231 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 232 return; | 232 return; |
| 233 } | 233 } |
| 234 | 234 |
| 235 // TODO(michaeln): If the last update check was less than 24 hours | |
| 236 // ago, depending on the freshness of the cached worker script we | |
| 237 // may be able to complete the update job right here. | |
| 238 | |
| 235 UpdateAndContinue(); | 239 UpdateAndContinue(); |
| 236 } | 240 } |
| 237 | 241 |
| 238 // Creates a new ServiceWorkerRegistration. | 242 // Creates a new ServiceWorkerRegistration. |
| 239 void ServiceWorkerRegisterJob::RegisterAndContinue( | 243 void ServiceWorkerRegisterJob::RegisterAndContinue( |
| 240 ServiceWorkerStatusCode status) { | 244 ServiceWorkerStatusCode status) { |
| 241 SetPhase(REGISTER); | 245 SetPhase(REGISTER); |
| 242 if (status != SERVICE_WORKER_OK) { | 246 if (status != SERVICE_WORKER_OK) { |
| 243 // Abort this registration job. | 247 // Abort this registration job. |
| 244 Complete(status); | 248 Complete(status); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 ServiceWorkerStatusCode status) { | 320 ServiceWorkerStatusCode status) { |
| 317 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is | 321 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is |
| 318 // unexpectedly terminated) we may want to retry sending the event again. | 322 // unexpectedly terminated) we may want to retry sending the event again. |
| 319 if (status != SERVICE_WORKER_OK) { | 323 if (status != SERVICE_WORKER_OK) { |
| 320 // "8. If installFailed is true, then:..." | 324 // "8. If installFailed is true, then:..." |
| 321 Complete(status); | 325 Complete(status); |
| 322 return; | 326 return; |
| 323 } | 327 } |
| 324 | 328 |
| 325 SetPhase(STORE); | 329 SetPhase(STORE); |
| 330 registration()->set_last_update_check(base::Time::Now()); | |
| 326 context_->storage()->StoreRegistration( | 331 context_->storage()->StoreRegistration( |
| 327 registration(), | 332 registration(), |
| 328 new_version(), | 333 new_version(), |
| 329 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, | 334 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, |
| 330 weak_factory_.GetWeakPtr())); | 335 weak_factory_.GetWeakPtr())); |
| 331 } | 336 } |
| 332 | 337 |
| 333 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( | 338 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
| 334 ServiceWorkerStatusCode status) { | 339 ServiceWorkerStatusCode status) { |
| 335 if (status != SERVICE_WORKER_OK) { | 340 if (status != SERVICE_WORKER_OK) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); | 414 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); |
| 410 it != callbacks_.end(); | 415 it != callbacks_.end(); |
| 411 ++it) { | 416 ++it) { |
| 412 it->Run(status, registration, version); | 417 it->Run(status, registration, version); |
| 413 } | 418 } |
| 414 callbacks_.clear(); | 419 callbacks_.clear(); |
| 415 } | 420 } |
| 416 | 421 |
| 417 void ServiceWorkerRegisterJob::OnPausedAfterDownload() { | 422 void ServiceWorkerRegisterJob::OnPausedAfterDownload() { |
| 418 // This happens prior to OnStartWorkerFinished time. | 423 // This happens prior to OnStartWorkerFinished time. |
| 419 scoped_refptr<ServiceWorkerVersion> current_version = | 424 scoped_refptr<ServiceWorkerVersion> most_recent_version = |
| 420 registration()->active_version(); | 425 registration()->waiting_version() ? |
| 421 DCHECK(current_version); | 426 registration()->waiting_version() : |
| 422 int64 current_script_id = | 427 registration()->active_version(); |
| 423 current_version->script_cache_map()->Lookup(script_url_); | 428 DCHECK(most_recent_version); |
| 429 int64 most_recent_script_id = | |
| 430 most_recent_version->script_cache_map()->Lookup(script_url_); | |
| 424 int64 new_script_id = | 431 int64 new_script_id = |
| 425 new_version()->script_cache_map()->Lookup(script_url_); | 432 new_version()->script_cache_map()->Lookup(script_url_); |
| 426 | 433 |
| 427 // TODO(michaeln): It would be better to compare as the new resource | 434 // TODO(michaeln): It would be better to compare as the new resource |
| 428 // is being downloaded and to avoid writing it to disk until we know | 435 // is being downloaded and to avoid writing it to disk until we know |
| 429 // its needed. | 436 // its needed. |
| 430 context_->storage()->CompareScriptResources( | 437 context_->storage()->CompareScriptResources( |
| 431 current_script_id, new_script_id, | 438 most_recent_script_id, new_script_id, |
| 432 base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete, | 439 base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete, |
| 433 weak_factory_.GetWeakPtr(), | 440 weak_factory_.GetWeakPtr(), |
| 434 current_version)); | 441 most_recent_version)); |
| 435 } | 442 } |
| 436 | 443 |
| 437 bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) { | 444 bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) { |
| 438 return false; | 445 return false; |
| 439 } | 446 } |
| 440 | 447 |
| 441 void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete( | 448 void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete( |
| 442 ServiceWorkerVersion* current_version, | 449 ServiceWorkerVersion* most_recent_version, |
| 443 ServiceWorkerStatusCode status, | 450 ServiceWorkerStatusCode status, |
| 444 bool are_equal) { | 451 bool are_equal) { |
| 445 if (are_equal) { | 452 if (are_equal) { |
| 446 ResolvePromise(SERVICE_WORKER_OK, registration(), current_version); | 453 // Only bump the last check time when we've bypassed the browser cache. |
|
michaeln
2014/08/15 01:39:59
i changed this part since you last looked
| |
| 454 base::TimeDelta time_since_last_check = | |
| 455 base::Time::Now() - registration()->last_update_check(); | |
| 456 if (time_since_last_check > base::TimeDelta::FromHours(24)) { | |
| 457 registration()->set_last_update_check(base::Time::Now()); | |
| 458 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
| 459 } | |
| 460 | |
| 461 ResolvePromise(SERVICE_WORKER_OK, registration(), most_recent_version); | |
| 447 Complete(SERVICE_WORKER_ERROR_EXISTS); | 462 Complete(SERVICE_WORKER_ERROR_EXISTS); |
| 448 return; | 463 return; |
| 449 } | 464 } |
| 450 | 465 |
| 451 // Proceed with really starting the worker. | 466 // Proceed with really starting the worker. |
| 452 new_version()->embedded_worker()->ResumeAfterDownload(); | 467 new_version()->embedded_worker()->ResumeAfterDownload(); |
| 453 new_version()->embedded_worker()->RemoveListener(this); | 468 new_version()->embedded_worker()->RemoveListener(this); |
| 454 } | 469 } |
| 455 | 470 |
| 456 void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration( | 471 void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration( |
| 457 ServiceWorkerRegistration* registration) { | 472 ServiceWorkerRegistration* registration) { |
| 458 DCHECK(registration); | 473 DCHECK(registration); |
| 459 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | 474 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 460 context_->GetProviderHostIterator(); | 475 context_->GetProviderHostIterator(); |
| 461 !it->IsAtEnd(); it->Advance()) { | 476 !it->IsAtEnd(); it->Advance()) { |
| 462 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 477 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 463 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 478 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 464 host->document_url())) { | 479 host->document_url())) { |
| 465 if (host->CanAssociateRegistration(registration)) | 480 if (host->CanAssociateRegistration(registration)) |
| 466 host->AssociateRegistration(registration); | 481 host->AssociateRegistration(registration); |
| 467 } | 482 } |
| 468 } | 483 } |
| 469 } | 484 } |
| 470 | 485 |
| 471 } // namespace content | 486 } // namespace content |
| OLD | NEW |