Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 457903002: After 24 hours, bust the browser cache when checking for ServiceWorker updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if (status != SERVICE_WORKER_OK) { 224 if (status != SERVICE_WORKER_OK) {
225 Complete(status); 225 Complete(status);
226 return; 226 return;
227 } 227 }
228 228
229 if (existing_registration != registration()) { 229 if (existing_registration != registration()) {
230 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); 230 Complete(SERVICE_WORKER_ERROR_NOT_FOUND);
231 return; 231 return;
232 } 232 }
233 233
234 // TODO(michaeln): If the last update check was less then 24 hours
dominicc (has gone to gerrit) 2014/08/11 04:01:15 then -> than
michaeln 2014/08/13 03:42:55 Done.
235 // ago, depending on the freshness of the cached worker script we
236 // may be able to complete the update job right here.
237
234 UpdateAndContinue(); 238 UpdateAndContinue();
235 } 239 }
236 240
237 // Creates a new ServiceWorkerRegistration. 241 // Creates a new ServiceWorkerRegistration.
238 void ServiceWorkerRegisterJob::RegisterAndContinue( 242 void ServiceWorkerRegisterJob::RegisterAndContinue(
239 ServiceWorkerStatusCode status) { 243 ServiceWorkerStatusCode status) {
240 SetPhase(REGISTER); 244 SetPhase(REGISTER);
241 if (status != SERVICE_WORKER_OK) { 245 if (status != SERVICE_WORKER_OK) {
242 // Abort this registration job. 246 // Abort this registration job.
243 Complete(status); 247 Complete(status);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ServiceWorkerStatusCode status) { 319 ServiceWorkerStatusCode status) {
316 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is 320 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is
317 // unexpectedly terminated) we may want to retry sending the event again. 321 // unexpectedly terminated) we may want to retry sending the event again.
318 if (status != SERVICE_WORKER_OK) { 322 if (status != SERVICE_WORKER_OK) {
319 // "8. If installFailed is true, then:..." 323 // "8. If installFailed is true, then:..."
320 Complete(status); 324 Complete(status);
321 return; 325 return;
322 } 326 }
323 327
324 SetPhase(STORE); 328 SetPhase(STORE);
329 registration()->set_last_update_check(base::Time::Now());
325 context_->storage()->StoreRegistration( 330 context_->storage()->StoreRegistration(
326 registration(), 331 registration(),
327 new_version(), 332 new_version(),
328 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, 333 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete,
329 weak_factory_.GetWeakPtr())); 334 weak_factory_.GetWeakPtr()));
330 } 335 }
331 336
332 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( 337 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete(
333 ServiceWorkerStatusCode status) { 338 ServiceWorkerStatusCode status) {
334 if (status != SERVICE_WORKER_OK) { 339 if (status != SERVICE_WORKER_OK) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); 413 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin();
409 it != callbacks_.end(); 414 it != callbacks_.end();
410 ++it) { 415 ++it) {
411 it->Run(status, registration, version); 416 it->Run(status, registration, version);
412 } 417 }
413 callbacks_.clear(); 418 callbacks_.clear();
414 } 419 }
415 420
416 void ServiceWorkerRegisterJob::OnPausedAfterDownload() { 421 void ServiceWorkerRegisterJob::OnPausedAfterDownload() {
417 // This happens prior to OnStartWorkerFinished time. 422 // This happens prior to OnStartWorkerFinished time.
418 scoped_refptr<ServiceWorkerVersion> current_version = 423 scoped_refptr<ServiceWorkerVersion> most_recent_version =
419 registration()->active_version(); 424 registration()->waiting_version() ?
420 DCHECK(current_version); 425 registration()->waiting_version() :
421 int64 current_script_id = 426 registration()->active_version();
422 current_version->script_cache_map()->Lookup(script_url_); 427 DCHECK(most_recent_version);
428 int64 most_recent_script_id =
429 most_recent_version->script_cache_map()->Lookup(script_url_);
423 int64 new_script_id = 430 int64 new_script_id =
424 new_version()->script_cache_map()->Lookup(script_url_); 431 new_version()->script_cache_map()->Lookup(script_url_);
425 432
426 // TODO(michaeln): It would be better to compare as the new resource 433 // TODO(michaeln): It would be better to compare as the new resource
427 // is being downloaded and to avoid writing it to disk until we know 434 // is being downloaded and to avoid writing it to disk until we know
428 // its needed. 435 // its needed.
429 context_->storage()->CompareScriptResources( 436 context_->storage()->CompareScriptResources(
430 current_script_id, new_script_id, 437 most_recent_script_id, new_script_id,
431 base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete, 438 base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete,
432 weak_factory_.GetWeakPtr(), 439 weak_factory_.GetWeakPtr(),
433 current_version)); 440 most_recent_version));
434 } 441 }
435 442
436 bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) { 443 bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) {
437 return false; 444 return false;
438 } 445 }
439 446
440 void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete( 447 void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete(
441 ServiceWorkerVersion* current_version, 448 ServiceWorkerVersion* most_recent_version,
442 ServiceWorkerStatusCode status, 449 ServiceWorkerStatusCode status,
443 bool are_equal) { 450 bool are_equal) {
444 if (are_equal) { 451 if (are_equal) {
445 ResolvePromise(SERVICE_WORKER_OK, registration(), current_version); 452 ResolvePromise(SERVICE_WORKER_OK, registration(), most_recent_version);
453 registration()->set_last_update_check(base::Time::Now());
454 context_->storage()->UpdateLastUpdateCheckTime(registration());
446 Complete(SERVICE_WORKER_ERROR_EXISTS); 455 Complete(SERVICE_WORKER_ERROR_EXISTS);
447 return; 456 return;
448 } 457 }
449 458
450 // Proceed with really starting the worker. 459 // Proceed with really starting the worker.
451 new_version()->embedded_worker()->ResumeAfterDownload(); 460 new_version()->embedded_worker()->ResumeAfterDownload();
452 new_version()->embedded_worker()->RemoveListener(this); 461 new_version()->embedded_worker()->RemoveListener(this);
453 } 462 }
454 463
455 void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration( 464 void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration(
456 ServiceWorkerRegistration* registration) { 465 ServiceWorkerRegistration* registration) {
457 DCHECK(registration); 466 DCHECK(registration);
458 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = 467 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
459 context_->GetProviderHostIterator(); 468 context_->GetProviderHostIterator();
460 !it->IsAtEnd(); it->Advance()) { 469 !it->IsAtEnd(); it->Advance()) {
461 ServiceWorkerProviderHost* host = it->GetProviderHost(); 470 ServiceWorkerProviderHost* host = it->GetProviderHost();
462 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), 471 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(),
463 host->document_url())) { 472 host->document_url())) {
464 if (host->CanAssociateRegistration(registration)) 473 if (host->CanAssociateRegistration(registration))
465 host->AssociateRegistration(registration); 474 host->AssociateRegistration(registration);
466 } 475 }
467 } 476 }
468 } 477 }
469 478
470 } // namespace content 479 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698