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

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: version purges the resources 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 {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 const std::vector<int64>& newly_purgeable_resources, 696 const std::vector<int64>& newly_purgeable_resources,
699 ServiceWorkerDatabase::Status status) { 697 ServiceWorkerDatabase::Status status) {
700 if (status != ServiceWorkerDatabase::STATUS_OK) { 698 if (status != ServiceWorkerDatabase::STATUS_OK) {
701 ScheduleDeleteAndStartOver(); 699 ScheduleDeleteAndStartOver();
702 callback.Run(DatabaseStatusToStatusCode(status)); 700 callback.Run(DatabaseStatusToStatusCode(status));
703 return; 701 return;
704 } 702 }
705 registered_origins_.insert(origin); 703 registered_origins_.insert(origin);
706 callback.Run(SERVICE_WORKER_OK); 704 callback.Run(SERVICE_WORKER_OK);
707 705
708 SchedulePurgeResources(deleted_version_id, newly_purgeable_resources); 706 if (!context_ || !context_->GetLiveVersion(deleted_version_id))
707 StartPurgingResources(newly_purgeable_resources);
709 } 708 }
710 709
711 void ServiceWorkerStorage::DidUpdateToActiveState( 710 void ServiceWorkerStorage::DidUpdateToActiveState(
712 const StatusCallback& callback, 711 const StatusCallback& callback,
713 ServiceWorkerDatabase::Status status) { 712 ServiceWorkerDatabase::Status status) {
714 if (status != ServiceWorkerDatabase::STATUS_OK && 713 if (status != ServiceWorkerDatabase::STATUS_OK &&
715 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 714 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
716 ScheduleDeleteAndStartOver(); 715 ScheduleDeleteAndStartOver();
717 } 716 }
718 callback.Run(DatabaseStatusToStatusCode(status)); 717 callback.Run(DatabaseStatusToStatusCode(status));
719 } 718 }
720 719
721 void ServiceWorkerStorage::DidDeleteRegistration( 720 void ServiceWorkerStorage::DidDeleteRegistration(
722 const GURL& origin, 721 const GURL& origin,
723 const StatusCallback& callback, 722 const StatusCallback& callback,
724 bool origin_is_deletable, 723 bool origin_is_deletable,
725 int64 version_id, 724 int64 version_id,
726 const std::vector<int64>& newly_purgeable_resources, 725 const std::vector<int64>& newly_purgeable_resources,
727 ServiceWorkerDatabase::Status status) { 726 ServiceWorkerDatabase::Status status) {
728 if (status != ServiceWorkerDatabase::STATUS_OK) { 727 if (status != ServiceWorkerDatabase::STATUS_OK) {
729 ScheduleDeleteAndStartOver(); 728 ScheduleDeleteAndStartOver();
730 callback.Run(DatabaseStatusToStatusCode(status)); 729 callback.Run(DatabaseStatusToStatusCode(status));
731 return; 730 return;
732 } 731 }
733 if (origin_is_deletable) 732 if (origin_is_deletable)
734 registered_origins_.erase(origin); 733 registered_origins_.erase(origin);
735 callback.Run(SERVICE_WORKER_OK); 734 callback.Run(SERVICE_WORKER_OK);
736 735
737 SchedulePurgeResources(version_id, newly_purgeable_resources); 736 if (!context_ || !context_->GetLiveVersion(version_id))
737 StartPurgingResources(newly_purgeable_resources);
738 } 738 }
739 739
740 scoped_refptr<ServiceWorkerRegistration> 740 scoped_refptr<ServiceWorkerRegistration>
741 ServiceWorkerStorage::GetOrCreateRegistration( 741 ServiceWorkerStorage::GetOrCreateRegistration(
742 const ServiceWorkerDatabase::RegistrationData& data, 742 const ServiceWorkerDatabase::RegistrationData& data,
743 const ResourceList& resources) { 743 const ResourceList& resources) {
744 scoped_refptr<ServiceWorkerRegistration> registration = 744 scoped_refptr<ServiceWorkerRegistration> registration =
745 context_->GetLiveRegistration(data.registration_id); 745 context_->GetLiveRegistration(data.registration_id);
746 if (registration) 746 if (registration)
747 return registration; 747 return registration;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 837
838 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { 838 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) {
839 if (rv != net::OK) { 839 if (rv != net::OK) {
840 LOG(ERROR) << "Failed to open the serviceworker diskcache: " 840 LOG(ERROR) << "Failed to open the serviceworker diskcache: "
841 << net::ErrorToString(rv); 841 << net::ErrorToString(rv);
842 ScheduleDeleteAndStartOver(); 842 ScheduleDeleteAndStartOver();
843 } 843 }
844 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK); 844 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK);
845 } 845 }
846 846
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( 847 void ServiceWorkerStorage::StartPurgingResources(
874 const std::vector<int64>& ids) { 848 const std::vector<int64>& ids) {
875 DCHECK(has_checked_for_stale_resources_); 849 DCHECK(has_checked_for_stale_resources_);
876 for (size_t i = 0; i < ids.size(); ++i) 850 for (size_t i = 0; i < ids.size(); ++i)
877 purgeable_resource_ids_.push_back(ids[i]); 851 purgeable_resource_ids_.push_back(ids[i]);
878 ContinuePurgingResources(); 852 ContinuePurgingResources();
879 } 853 }
880 854
855 void ServiceWorkerStorage::PurgeResources(const ResourceList& resources) {
856 StartPurgingResources(resources);
857 }
858
881 void ServiceWorkerStorage::StartPurgingResources( 859 void ServiceWorkerStorage::StartPurgingResources(
882 const ResourceList& resources) { 860 const ResourceList& resources) {
883 DCHECK(has_checked_for_stale_resources_); 861 DCHECK(has_checked_for_stale_resources_);
884 for (size_t i = 0; i < resources.size(); ++i) 862 for (size_t i = 0; i < resources.size(); ++i)
885 purgeable_resource_ids_.push_back(resources[i].resource_id); 863 purgeable_resource_ids_.push_back(resources[i].resource_id);
886 ContinuePurgingResources(); 864 ContinuePurgingResources();
887 } 865 }
888 866
889 void ServiceWorkerStorage::ContinuePurgingResources() { 867 void ServiceWorkerStorage::ContinuePurgingResources() {
890 if (purgeable_resource_ids_.empty() || is_purge_pending_) 868 if (purgeable_resource_ids_.empty() || is_purge_pending_)
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 // Give up the corruption recovery until the browser restarts. 1174 // Give up the corruption recovery until the browser restarts.
1197 LOG(ERROR) << "Failed to delete the diskcache."; 1175 LOG(ERROR) << "Failed to delete the diskcache.";
1198 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1176 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1199 return; 1177 return;
1200 } 1178 }
1201 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1179 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1202 callback.Run(SERVICE_WORKER_OK); 1180 callback.Run(SERVICE_WORKER_OK);
1203 } 1181 }
1204 1182
1205 } // namespace content 1183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698