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

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

Issue 605163002: Service Worker: Remove legacy code for resolving register() to a version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « content/browser/service_worker/service_worker_register_job.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void ServiceWorkerRegisterJob::AddCallback( 62 void ServiceWorkerRegisterJob::AddCallback(
63 const RegistrationCallback& callback, 63 const RegistrationCallback& callback,
64 ServiceWorkerProviderHost* provider_host) { 64 ServiceWorkerProviderHost* provider_host) {
65 if (!is_promise_resolved_) { 65 if (!is_promise_resolved_) {
66 callbacks_.push_back(callback); 66 callbacks_.push_back(callback);
67 if (provider_host) 67 if (provider_host)
68 provider_host->AddScopedProcessReferenceToPattern(pattern_); 68 provider_host->AddScopedProcessReferenceToPattern(pattern_);
69 return; 69 return;
70 } 70 }
71 RunSoon(base::Bind( 71 RunSoon(base::Bind(
72 callback, promise_resolved_status_, 72 callback, promise_resolved_status_, promise_resolved_registration_));
73 promise_resolved_registration_, promise_resolved_version_));
74 } 73 }
75 74
76 void ServiceWorkerRegisterJob::Start() { 75 void ServiceWorkerRegisterJob::Start() {
77 SetPhase(START); 76 SetPhase(START);
78 ServiceWorkerStorage::FindRegistrationCallback next_step; 77 ServiceWorkerStorage::FindRegistrationCallback next_step;
79 if (job_type_ == REGISTRATION_JOB) { 78 if (job_type_ == REGISTRATION_JOB) {
80 next_step = base::Bind( 79 next_step = base::Bind(
81 &ServiceWorkerRegisterJob::ContinueWithRegistration, 80 &ServiceWorkerRegisterJob::ContinueWithRegistration,
82 weak_factory_.GetWeakPtr()); 81 weak_factory_.GetWeakPtr());
83 } else { 82 } else {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 284
286 void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl( 285 void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl(
287 const scoped_refptr<ServiceWorkerRegistration>& existing_registration, 286 const scoped_refptr<ServiceWorkerRegistration>& existing_registration,
288 ServiceWorkerStatusCode status) { 287 ServiceWorkerStatusCode status) {
289 if (status != SERVICE_WORKER_OK) { 288 if (status != SERVICE_WORKER_OK) {
290 Complete(status); 289 Complete(status);
291 return; 290 return;
292 } 291 }
293 set_registration(existing_registration); 292 set_registration(existing_registration);
294 293
295 // TODO(falken): Follow the spec: resolve the promise 294 // "If newestWorker is not null, and scriptURL is equal to
296 // with the newest version. 295 // newestWorker.scriptURL, then:
297 296 // Return a promise resolved with registration."
298 if (!existing_registration->active_version()) { 297 if (existing_registration->GetNewestVersion()) {
nhiroki 2014/09/26 09:35:53 The CL description says...
299 UpdateAndContinue(); 298 ResolvePromise(status, existing_registration.get());
299 Complete(SERVICE_WORKER_OK);
300 return; 300 return;
301 } 301 }
302 302
303 ResolvePromise(status, 303 // "Return the result of running the [[Update]] algorithm, or its equivalent,
304 existing_registration.get(), 304 // passing registration as the argument."
305 existing_registration->active_version()); 305 UpdateAndContinue();
306 Complete(SERVICE_WORKER_OK);
307 } 306 }
308 307
309 // This function corresponds to the spec's [[Update]] algorithm. 308 // This function corresponds to the spec's [[Update]] algorithm.
310 void ServiceWorkerRegisterJob::UpdateAndContinue() { 309 void ServiceWorkerRegisterJob::UpdateAndContinue() {
311 SetPhase(UPDATE); 310 SetPhase(UPDATE);
312 context_->storage()->NotifyInstallingRegistration(registration()); 311 context_->storage()->NotifyInstallingRegistration(registration());
313 312
314 // TODO(falken): "If serviceWorkerRegistration.installingWorker is not null.." 313 // TODO(falken): "If serviceWorkerRegistration.installingWorker is not null.."
315 // then terminate the installing worker. It doesn't make sense to implement 314 // then terminate the installing worker. It doesn't make sense to implement
316 // yet since we always activate the worker if install completed, so there can 315 // yet since we always activate the worker if install completed, so there can
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 363 }
365 364
366 // This function corresponds to the spec's [[Install]] algorithm. 365 // This function corresponds to the spec's [[Install]] algorithm.
367 void ServiceWorkerRegisterJob::InstallAndContinue() { 366 void ServiceWorkerRegisterJob::InstallAndContinue() {
368 SetPhase(INSTALL); 367 SetPhase(INSTALL);
369 368
370 // "2. Set registration.installingWorker to worker." 369 // "2. Set registration.installingWorker to worker."
371 registration()->SetInstallingVersion(new_version()); 370 registration()->SetInstallingVersion(new_version());
372 371
373 // "3. Resolve promise with registration." 372 // "3. Resolve promise with registration."
374 ResolvePromise(SERVICE_WORKER_OK, registration(), new_version()); 373 ResolvePromise(SERVICE_WORKER_OK, registration());
375 374
376 // "4. Run the [[UpdateState]] algorithm passing registration.installingWorker 375 // "4. Run the [[UpdateState]] algorithm passing registration.installingWorker
377 // and "installing" as the arguments." 376 // and "installing" as the arguments."
378 new_version()->SetStatus(ServiceWorkerVersion::INSTALLING); 377 new_version()->SetStatus(ServiceWorkerVersion::INSTALLING);
379 378
380 // "5. Fire a simple event named updatefound..." 379 // "5. Fire a simple event named updatefound..."
381 registration()->NotifyUpdateFound(); 380 registration()->NotifyUpdateFound();
382 381
383 // "6. Fire an event named install..." 382 // "6. Fire an event named install..."
384 new_version()->DispatchInstallEvent( 383 new_version()->DispatchInstallEvent(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (!registration()->waiting_version() && 454 if (!registration()->waiting_version() &&
456 !registration()->active_version()) { 455 !registration()->active_version()) {
457 registration()->NotifyRegistrationFailed(); 456 registration()->NotifyRegistrationFailed();
458 context_->storage()->DeleteRegistration( 457 context_->storage()->DeleteRegistration(
459 registration()->id(), 458 registration()->id(),
460 registration()->pattern().GetOrigin(), 459 registration()->pattern().GetOrigin(),
461 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 460 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
462 } 461 }
463 } 462 }
464 if (!is_promise_resolved_) 463 if (!is_promise_resolved_)
465 ResolvePromise(status, NULL, NULL); 464 ResolvePromise(status, NULL);
466 } 465 }
467 DCHECK(callbacks_.empty()); 466 DCHECK(callbacks_.empty());
468 if (registration()) { 467 if (registration()) {
469 context_->storage()->NotifyDoneInstallingRegistration( 468 context_->storage()->NotifyDoneInstallingRegistration(
470 registration(), new_version(), status); 469 registration(), new_version(), status);
471 } 470 }
472 if (new_version()) 471 if (new_version())
473 new_version()->embedded_worker()->RemoveListener(this); 472 new_version()->embedded_worker()->RemoveListener(this);
474 } 473 }
475 474
476 void ServiceWorkerRegisterJob::ResolvePromise( 475 void ServiceWorkerRegisterJob::ResolvePromise(
477 ServiceWorkerStatusCode status, 476 ServiceWorkerStatusCode status,
478 ServiceWorkerRegistration* registration, 477 ServiceWorkerRegistration* registration) {
479 ServiceWorkerVersion* version) {
480 DCHECK(!is_promise_resolved_); 478 DCHECK(!is_promise_resolved_);
481 is_promise_resolved_ = true; 479 is_promise_resolved_ = true;
482 promise_resolved_status_ = status; 480 promise_resolved_status_ = status;
483 promise_resolved_registration_ = registration; 481 promise_resolved_registration_ = registration;
484 promise_resolved_version_ = version;
485 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); 482 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin();
486 it != callbacks_.end(); 483 it != callbacks_.end();
487 ++it) { 484 ++it) {
488 it->Run(status, registration, version); 485 it->Run(status, registration);
489 } 486 }
490 callbacks_.clear(); 487 callbacks_.clear();
491 } 488 }
492 489
493 void ServiceWorkerRegisterJob::OnPausedAfterDownload() { 490 void ServiceWorkerRegisterJob::OnPausedAfterDownload() {
494 // This happens prior to OnStartWorkerFinished time. 491 // This happens prior to OnStartWorkerFinished time.
495 scoped_refptr<ServiceWorkerVersion> most_recent_version = 492 scoped_refptr<ServiceWorkerVersion> most_recent_version =
496 registration()->waiting_version() ? 493 registration()->waiting_version() ?
497 registration()->waiting_version() : 494 registration()->waiting_version() :
498 registration()->active_version(); 495 registration()->active_version();
499 DCHECK(most_recent_version.get()); 496 DCHECK(most_recent_version.get());
500 int64 most_recent_script_id = 497 int64 most_recent_script_id =
501 most_recent_version->script_cache_map()->Lookup(script_url_); 498 most_recent_version->script_cache_map()->Lookup(script_url_);
502 int64 new_script_id = 499 int64 new_script_id =
503 new_version()->script_cache_map()->Lookup(script_url_); 500 new_version()->script_cache_map()->Lookup(script_url_);
504 501
505 // TODO(michaeln): It would be better to compare as the new resource 502 // TODO(michaeln): It would be better to compare as the new resource
506 // is being downloaded and to avoid writing it to disk until we know 503 // is being downloaded and to avoid writing it to disk until we know
507 // its needed. 504 // its needed.
508 context_->storage()->CompareScriptResources( 505 context_->storage()->CompareScriptResources(
509 most_recent_script_id, new_script_id, 506 most_recent_script_id,
507 new_script_id,
510 base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete, 508 base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete,
511 weak_factory_.GetWeakPtr(), 509 weak_factory_.GetWeakPtr()));
512 most_recent_version));
513 } 510 }
514 511
515 bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) { 512 bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) {
516 return false; 513 return false;
517 } 514 }
518 515
519 void ServiceWorkerRegisterJob::OnRegistrationFinishedUninstalling( 516 void ServiceWorkerRegisterJob::OnRegistrationFinishedUninstalling(
520 ServiceWorkerRegistration* existing_registration) { 517 ServiceWorkerRegistration* existing_registration) {
521 DCHECK_EQ(phase_, WAIT_FOR_UNINSTALL); 518 DCHECK_EQ(phase_, WAIT_FOR_UNINSTALL);
522 DCHECK_EQ(existing_registration, uninstalling_registration()); 519 DCHECK_EQ(existing_registration, uninstalling_registration());
523 existing_registration->RemoveListener(this); 520 existing_registration->RemoveListener(this);
524 set_uninstalling_registration(NULL); 521 set_uninstalling_registration(NULL);
525 RegisterAndContinue(SERVICE_WORKER_OK); 522 RegisterAndContinue(SERVICE_WORKER_OK);
526 } 523 }
527 524
528 void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete( 525 void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete(
529 ServiceWorkerVersion* most_recent_version,
530 ServiceWorkerStatusCode status, 526 ServiceWorkerStatusCode status,
531 bool are_equal) { 527 bool are_equal) {
532 if (are_equal) { 528 if (are_equal) {
533 // Only bump the last check time when we've bypassed the browser cache. 529 // Only bump the last check time when we've bypassed the browser cache.
534 base::TimeDelta time_since_last_check = 530 base::TimeDelta time_since_last_check =
535 base::Time::Now() - registration()->last_update_check(); 531 base::Time::Now() - registration()->last_update_check();
536 if (time_since_last_check > base::TimeDelta::FromHours(24)) { 532 if (time_since_last_check > base::TimeDelta::FromHours(24)) {
537 registration()->set_last_update_check(base::Time::Now()); 533 registration()->set_last_update_check(base::Time::Now());
538 context_->storage()->UpdateLastUpdateCheckTime(registration()); 534 context_->storage()->UpdateLastUpdateCheckTime(registration());
539 } 535 }
540 536
541 ResolvePromise(SERVICE_WORKER_OK, registration(), most_recent_version); 537 ResolvePromise(SERVICE_WORKER_OK, registration());
542 Complete(SERVICE_WORKER_ERROR_EXISTS); 538 Complete(SERVICE_WORKER_ERROR_EXISTS);
543 return; 539 return;
544 } 540 }
545 541
546 // Proceed with really starting the worker. 542 // Proceed with really starting the worker.
547 new_version()->embedded_worker()->ResumeAfterDownload(); 543 new_version()->embedded_worker()->ResumeAfterDownload();
548 new_version()->embedded_worker()->RemoveListener(this); 544 new_version()->embedded_worker()->RemoveListener(this);
549 } 545 }
550 546
551 void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration( 547 void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration(
552 ServiceWorkerRegistration* registration) { 548 ServiceWorkerRegistration* registration) {
553 DCHECK(registration); 549 DCHECK(registration);
554 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = 550 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
555 context_->GetProviderHostIterator(); 551 context_->GetProviderHostIterator();
556 !it->IsAtEnd(); it->Advance()) { 552 !it->IsAtEnd(); it->Advance()) {
557 ServiceWorkerProviderHost* host = it->GetProviderHost(); 553 ServiceWorkerProviderHost* host = it->GetProviderHost();
558 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), 554 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(),
559 host->document_url())) { 555 host->document_url())) {
560 if (host->CanAssociateRegistration(registration)) 556 if (host->CanAssociateRegistration(registration))
561 host->AssociateRegistration(registration); 557 host->AssociateRegistration(registration);
562 } 558 }
563 } 559 }
564 } 560 }
565 561
566 } // namespace content 562 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_register_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698