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

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

Issue 377153003: Service Worker: set active worker to REDUNDANT when unregistered (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments 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
« no previous file with comments | « content/browser/service_worker/service_worker_version.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_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "content/browser/service_worker/embedded_worker_instance.h" 10 #include "content/browser/service_worker/embedded_worker_instance.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 ServiceWorkerVersion::ServiceWorkerVersion( 93 ServiceWorkerVersion::ServiceWorkerVersion(
94 ServiceWorkerRegistration* registration, 94 ServiceWorkerRegistration* registration,
95 int64 version_id, 95 int64 version_id,
96 base::WeakPtr<ServiceWorkerContextCore> context) 96 base::WeakPtr<ServiceWorkerContextCore> context)
97 : version_id_(version_id), 97 : version_id_(version_id),
98 registration_id_(kInvalidServiceWorkerVersionId), 98 registration_id_(kInvalidServiceWorkerVersionId),
99 status_(NEW), 99 status_(NEW),
100 context_(context), 100 context_(context),
101 script_cache_map_(this, context), 101 script_cache_map_(this, context),
102 is_doomed_(false),
102 weak_factory_(this) { 103 weak_factory_(this) {
103 DCHECK(context_); 104 DCHECK(context_);
104 DCHECK(registration); 105 DCHECK(registration);
105 if (registration) { 106 if (registration) {
106 registration_id_ = registration->id(); 107 registration_id_ = registration->id();
107 script_url_ = registration->script_url(); 108 script_url_ = registration->script_url();
108 scope_ = registration->pattern(); 109 scope_ = registration->pattern();
109 } 110 }
110 context_->AddLiveVersion(this); 111 context_->AddLiveVersion(this);
111 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); 112 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 stop_worker_timer_.Stop(); 380 stop_worker_timer_.Stop();
380 } 381 }
381 382
382 void ServiceWorkerVersion::RemoveControllee( 383 void ServiceWorkerVersion::RemoveControllee(
383 ServiceWorkerProviderHost* provider_host) { 384 ServiceWorkerProviderHost* provider_host) {
384 ControlleeMap::iterator found = controllee_map_.find(provider_host); 385 ControlleeMap::iterator found = controllee_map_.find(provider_host);
385 DCHECK(found != controllee_map_.end()); 386 DCHECK(found != controllee_map_.end());
386 controllee_by_id_.Remove(found->second); 387 controllee_by_id_.Remove(found->second);
387 controllee_map_.erase(found); 388 controllee_map_.erase(found);
388 RemoveProcessFromWorker(provider_host->process_id()); 389 RemoveProcessFromWorker(provider_host->process_id());
389 if (!HasControllee()) { 390 if (HasControllee())
390 ScheduleStopWorker(); 391 return;
391 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); 392 ScheduleStopWorker();
392 } 393 if (is_doomed_)
394 DoomInternal();
393 } 395 }
394 396
395 void ServiceWorkerVersion::AddPotentialControllee( 397 void ServiceWorkerVersion::AddPotentialControllee(
396 ServiceWorkerProviderHost* provider_host) { 398 ServiceWorkerProviderHost* provider_host) {
397 AddProcessToWorker(provider_host->process_id()); 399 AddProcessToWorker(provider_host->process_id());
398 } 400 }
399 401
400 void ServiceWorkerVersion::RemovePotentialControllee( 402 void ServiceWorkerVersion::RemovePotentialControllee(
401 ServiceWorkerProviderHost* provider_host) { 403 ServiceWorkerProviderHost* provider_host) {
402 RemoveProcessFromWorker(provider_host->process_id()); 404 RemoveProcessFromWorker(provider_host->process_id());
403 } 405 }
404 406
405 void ServiceWorkerVersion::AddListener(Listener* listener) { 407 void ServiceWorkerVersion::AddListener(Listener* listener) {
406 listeners_.AddObserver(listener); 408 listeners_.AddObserver(listener);
407 } 409 }
408 410
409 void ServiceWorkerVersion::RemoveListener(Listener* listener) { 411 void ServiceWorkerVersion::RemoveListener(Listener* listener) {
410 listeners_.RemoveObserver(listener); 412 listeners_.RemoveObserver(listener);
411 } 413 }
412 414
415 void ServiceWorkerVersion::Doom() {
416 if (is_doomed_)
417 return;
418 is_doomed_ = true;
419 if (!HasControllee())
420 DoomInternal();
421 }
422
413 void ServiceWorkerVersion::OnStarted() { 423 void ServiceWorkerVersion::OnStarted() {
414 DCHECK_EQ(RUNNING, running_status()); 424 DCHECK_EQ(RUNNING, running_status());
415 // Fire all start callbacks. 425 // Fire all start callbacks.
416 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); 426 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK);
417 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStarted(this)); 427 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStarted(this));
418 } 428 }
419 429
420 void ServiceWorkerVersion::OnStopped() { 430 void ServiceWorkerVersion::OnStopped() {
421 DCHECK_EQ(STOPPED, running_status()); 431 DCHECK_EQ(STOPPED, running_status());
422 scoped_refptr<ServiceWorkerVersion> protect(this); 432 scoped_refptr<ServiceWorkerVersion> protect(this);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 stop_worker_timer_.Reset(); 659 stop_worker_timer_.Reset();
650 return; 660 return;
651 } 661 }
652 stop_worker_timer_.Start( 662 stop_worker_timer_.Start(
653 FROM_HERE, base::TimeDelta::FromSeconds(kStopWorkerDelay), 663 FROM_HERE, base::TimeDelta::FromSeconds(kStopWorkerDelay),
654 base::Bind(&ServiceWorkerVersion::StopWorker, 664 base::Bind(&ServiceWorkerVersion::StopWorker,
655 weak_factory_.GetWeakPtr(), 665 weak_factory_.GetWeakPtr(),
656 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback))); 666 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)));
657 } 667 }
658 668
669 void ServiceWorkerVersion::DoomInternal() {
670 SetStatus(REDUNDANT);
671 if (!context_)
672 return;
673 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
674 script_cache_map_.GetResources(&resources);
675 context_->storage()->PurgeResources(resources);
676 }
677
659 } // namespace content 678 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698