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

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

Issue 354643003: ServiceWorker: Support navigator.serviceWorker.active (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 6 years, 5 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // this way. 337 // this way.
338 NOTREACHED(); 338 NOTREACHED();
339 // TODO(falken): Register an continuation task to wait for NoControllees 339 // TODO(falken): Register an continuation task to wait for NoControllees
340 // notification so that we can resume activation later. 340 // notification so that we can resume activation later.
341 Complete(SERVICE_WORKER_OK); 341 Complete(SERVICE_WORKER_OK);
342 return; 342 return;
343 } 343 }
344 344
345 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." 345 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker."
346 // "6. Set serviceWorkerRegistration.waitingWorker to null." 346 // "6. Set serviceWorkerRegistration.waitingWorker to null."
347 DisassociateVersionFromDocuments(context_, new_version());
347 registration()->SetActiveVersion(new_version()); 348 registration()->SetActiveVersion(new_version());
349 AssociateActiveVersionToDocuments(context_, new_version());
348 350
349 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and 351 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and
350 // "activating" as arguments." 352 // "activating" as arguments."
351 new_version()->SetStatus(ServiceWorkerVersion::ACTIVATING); 353 new_version()->SetStatus(ServiceWorkerVersion::ACTIVATING);
352 354
353 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." 355 // TODO(nhiroki): "8. Fire a simple event named controllerchange..."
354 356
355 // "9. Fire an event named activate..." 357 // "9. Fire an event named activate..."
356 new_version()->DispatchActivateEvent( 358 new_version()->DispatchActivateEvent(
357 base::Bind(&ServiceWorkerRegisterJob::OnActivateFinished, 359 base::Bind(&ServiceWorkerRegisterJob::OnActivateFinished,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (ServiceWorkerUtils::ScopeMatches(version->scope(), 478 if (ServiceWorkerUtils::ScopeMatches(version->scope(),
477 host->document_url())) { 479 host->document_url())) {
478 if (!host->CanAssociateVersion(version)) 480 if (!host->CanAssociateVersion(version))
479 continue; 481 continue;
480 host->SetWaitingVersion(version); 482 host->SetWaitingVersion(version);
481 } 483 }
482 } 484 }
483 } 485 }
484 486
485 // static 487 // static
488 void ServiceWorkerRegisterJob::AssociateActiveVersionToDocuments(
489 base::WeakPtr<ServiceWorkerContextCore> context,
490 ServiceWorkerVersion* version) {
491 DCHECK(context);
492 DCHECK(version);
493
494 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
495 context->GetProviderHostIterator();
496 !it->IsAtEnd(); it->Advance()) {
497 ServiceWorkerProviderHost* host = it->GetProviderHost();
498 if (ServiceWorkerUtils::ScopeMatches(version->scope(),
499 host->document_url())) {
500 if (!host->CanAssociateVersion(version))
501 continue;
502 host->SetActiveVersion(version);
503 }
504 }
505 }
506
507 // static
486 void ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( 508 void ServiceWorkerRegisterJob::DisassociateVersionFromDocuments(
487 base::WeakPtr<ServiceWorkerContextCore> context, 509 base::WeakPtr<ServiceWorkerContextCore> context,
488 ServiceWorkerVersion* version) { 510 ServiceWorkerVersion* version) {
489 DCHECK(context); 511 DCHECK(context);
490 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = 512 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
491 context->GetProviderHostIterator(); 513 context->GetProviderHostIterator();
492 !it->IsAtEnd(); it->Advance()) { 514 !it->IsAtEnd(); it->Advance()) {
493 ServiceWorkerProviderHost* host = it->GetProviderHost(); 515 ServiceWorkerProviderHost* host = it->GetProviderHost();
494 host->UnsetVersion(version); 516 host->UnsetVersion(version);
495 } 517 }
496 } 518 }
497 519
498 } // namespace content 520 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_register_job.h ('k') | content/child/service_worker/service_worker_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698