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

Side by Side Diff: content/browser/service_worker/service_worker_storage.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
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_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 std::set<int64> ids; 443 std::set<int64> ids;
444 for (size_t i = 0; i < resources.size(); ++i) 444 for (size_t i = 0; i < resources.size(); ++i)
445 ids.insert(resources[i].resource_id); 445 ids.insert(resources[i].resource_id);
446 446
447 database_task_runner_->PostTask( 447 database_task_runner_->PostTask(
448 FROM_HERE, 448 FROM_HERE,
449 base::Bind(base::IgnoreResult( 449 base::Bind(base::IgnoreResult(
450 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), 450 &ServiceWorkerDatabase::PurgeUncommittedResourceIds),
451 base::Unretained(database_.get()), 451 base::Unretained(database_.get()),
452 ids)); 452 ids));
453
454 StartPurgingResources(resources);
455 } 453 }
456 } 454 }
457 455
458 void ServiceWorkerStorage::Disable() { 456 void ServiceWorkerStorage::Disable() {
459 state_ = DISABLED; 457 state_ = DISABLED;
460 if (disk_cache_) 458 if (disk_cache_)
461 disk_cache_->Disable(); 459 disk_cache_->Disable();
462 } 460 }
463 461
464 bool ServiceWorkerStorage::IsDisabled() const { 462 bool ServiceWorkerStorage::IsDisabled() const {
465 return state_ == DISABLED; 463 return state_ == DISABLED;
466 } 464 }
467 465
466 void ServiceWorkerStorage::PurgeResources(const ResourceList& resources) {
467 if (!has_checked_for_stale_resources_)
468 DeleteStaleResources();
469 StartPurgingResources(resources);
470 }
471
468 ServiceWorkerStorage::ServiceWorkerStorage( 472 ServiceWorkerStorage::ServiceWorkerStorage(
469 const base::FilePath& path, 473 const base::FilePath& path,
470 base::WeakPtr<ServiceWorkerContextCore> context, 474 base::WeakPtr<ServiceWorkerContextCore> context,
471 base::SequencedTaskRunner* database_task_runner, 475 base::SequencedTaskRunner* database_task_runner,
472 base::MessageLoopProxy* disk_cache_thread, 476 base::MessageLoopProxy* disk_cache_thread,
473 quota::QuotaManagerProxy* quota_manager_proxy) 477 quota::QuotaManagerProxy* quota_manager_proxy)
474 : next_registration_id_(kInvalidServiceWorkerRegistrationId), 478 : next_registration_id_(kInvalidServiceWorkerRegistrationId),
475 next_version_id_(kInvalidServiceWorkerVersionId), 479 next_version_id_(kInvalidServiceWorkerVersionId),
476 next_resource_id_(kInvalidServiceWorkerResourceId), 480 next_resource_id_(kInvalidServiceWorkerResourceId),
477 state_(UNINITIALIZED), 481 state_(UNINITIALIZED),
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 const std::vector<int64>& newly_purgeable_resources, 702 const std::vector<int64>& newly_purgeable_resources,
699 ServiceWorkerDatabase::Status status) { 703 ServiceWorkerDatabase::Status status) {
700 if (status != ServiceWorkerDatabase::STATUS_OK) { 704 if (status != ServiceWorkerDatabase::STATUS_OK) {
701 ScheduleDeleteAndStartOver(); 705 ScheduleDeleteAndStartOver();
702 callback.Run(DatabaseStatusToStatusCode(status)); 706 callback.Run(DatabaseStatusToStatusCode(status));
703 return; 707 return;
704 } 708 }
705 registered_origins_.insert(origin); 709 registered_origins_.insert(origin);
706 callback.Run(SERVICE_WORKER_OK); 710 callback.Run(SERVICE_WORKER_OK);
707 711
708 SchedulePurgeResources(deleted_version_id, newly_purgeable_resources); 712 if (!context_ || !context_->GetLiveVersion(deleted_version_id))
713 StartPurgingResources(newly_purgeable_resources);
709 } 714 }
710 715
711 void ServiceWorkerStorage::DidUpdateToActiveState( 716 void ServiceWorkerStorage::DidUpdateToActiveState(
712 const StatusCallback& callback, 717 const StatusCallback& callback,
713 ServiceWorkerDatabase::Status status) { 718 ServiceWorkerDatabase::Status status) {
714 if (status != ServiceWorkerDatabase::STATUS_OK && 719 if (status != ServiceWorkerDatabase::STATUS_OK &&
715 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 720 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
716 ScheduleDeleteAndStartOver(); 721 ScheduleDeleteAndStartOver();
717 } 722 }
718 callback.Run(DatabaseStatusToStatusCode(status)); 723 callback.Run(DatabaseStatusToStatusCode(status));
719 } 724 }
720 725
721 void ServiceWorkerStorage::DidDeleteRegistration( 726 void ServiceWorkerStorage::DidDeleteRegistration(
722 const GURL& origin, 727 const GURL& origin,
723 const StatusCallback& callback, 728 const StatusCallback& callback,
724 bool origin_is_deletable, 729 bool origin_is_deletable,
725 int64 version_id, 730 int64 version_id,
726 const std::vector<int64>& newly_purgeable_resources, 731 const std::vector<int64>& newly_purgeable_resources,
727 ServiceWorkerDatabase::Status status) { 732 ServiceWorkerDatabase::Status status) {
728 if (status != ServiceWorkerDatabase::STATUS_OK) { 733 if (status != ServiceWorkerDatabase::STATUS_OK) {
729 ScheduleDeleteAndStartOver(); 734 ScheduleDeleteAndStartOver();
730 callback.Run(DatabaseStatusToStatusCode(status)); 735 callback.Run(DatabaseStatusToStatusCode(status));
731 return; 736 return;
732 } 737 }
733 if (origin_is_deletable) 738 if (origin_is_deletable)
734 registered_origins_.erase(origin); 739 registered_origins_.erase(origin);
735 callback.Run(SERVICE_WORKER_OK); 740 callback.Run(SERVICE_WORKER_OK);
736 741
737 SchedulePurgeResources(version_id, newly_purgeable_resources); 742 if (!context_ || !context_->GetLiveVersion(version_id))
743 StartPurgingResources(newly_purgeable_resources);
738 } 744 }
739 745
740 scoped_refptr<ServiceWorkerRegistration> 746 scoped_refptr<ServiceWorkerRegistration>
741 ServiceWorkerStorage::GetOrCreateRegistration( 747 ServiceWorkerStorage::GetOrCreateRegistration(
742 const ServiceWorkerDatabase::RegistrationData& data, 748 const ServiceWorkerDatabase::RegistrationData& data,
743 const ResourceList& resources) { 749 const ResourceList& resources) {
744 scoped_refptr<ServiceWorkerRegistration> registration = 750 scoped_refptr<ServiceWorkerRegistration> registration =
745 context_->GetLiveRegistration(data.registration_id); 751 context_->GetLiveRegistration(data.registration_id);
746 if (registration) 752 if (registration)
747 return registration; 753 return registration;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 843
838 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { 844 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) {
839 if (rv != net::OK) { 845 if (rv != net::OK) {
840 LOG(ERROR) << "Failed to open the serviceworker diskcache: " 846 LOG(ERROR) << "Failed to open the serviceworker diskcache: "
841 << net::ErrorToString(rv); 847 << net::ErrorToString(rv);
842 ScheduleDeleteAndStartOver(); 848 ScheduleDeleteAndStartOver();
843 } 849 }
844 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK); 850 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK);
845 } 851 }
846 852
847 void ServiceWorkerStorage::OnNoControllees(ServiceWorkerVersion* version) {
848 std::map<int64, std::vector<int64> >::iterator it =
849 deleted_version_resource_ids_.find(version->version_id());
850 DCHECK(it != deleted_version_resource_ids_.end());
851 StartPurgingResources(it->second);
852 deleted_version_resource_ids_.erase(it);
853 version->RemoveListener(this);
854 }
855
856 void ServiceWorkerStorage::SchedulePurgeResources(
857 int64 version_id,
858 const std::vector<int64>& resources) {
859 DCHECK(deleted_version_resource_ids_.find(version_id) ==
860 deleted_version_resource_ids_.end());
861 if (resources.empty())
862 return;
863 scoped_refptr<ServiceWorkerVersion> version =
864 context_ ? context_->GetLiveVersion(version_id) : NULL;
865 if (version && version->HasControllee()) {
866 deleted_version_resource_ids_[version_id] = resources;
867 version->AddListener(this);
868 } else {
869 StartPurgingResources(resources);
870 }
871 }
872
873 void ServiceWorkerStorage::StartPurgingResources( 853 void ServiceWorkerStorage::StartPurgingResources(
874 const std::vector<int64>& ids) { 854 const std::vector<int64>& ids) {
875 DCHECK(has_checked_for_stale_resources_); 855 DCHECK(has_checked_for_stale_resources_);
876 for (size_t i = 0; i < ids.size(); ++i) 856 for (size_t i = 0; i < ids.size(); ++i)
877 purgeable_resource_ids_.push_back(ids[i]); 857 purgeable_resource_ids_.push_back(ids[i]);
878 ContinuePurgingResources(); 858 ContinuePurgingResources();
879 } 859 }
880 860
881 void ServiceWorkerStorage::StartPurgingResources( 861 void ServiceWorkerStorage::StartPurgingResources(
882 const ResourceList& resources) { 862 const ResourceList& resources) {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 // Give up the corruption recovery until the browser restarts. 1176 // Give up the corruption recovery until the browser restarts.
1197 LOG(ERROR) << "Failed to delete the diskcache."; 1177 LOG(ERROR) << "Failed to delete the diskcache.";
1198 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1178 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1199 return; 1179 return;
1200 } 1180 }
1201 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1181 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1202 callback.Run(SERVICE_WORKER_OK); 1182 callback.Run(SERVICE_WORKER_OK);
1203 } 1183 }
1204 1184
1205 } // namespace content 1185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698