Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 const std::vector<int64>& newly_purgeable_resources, | 689 const std::vector<int64>& newly_purgeable_resources, |
| 690 ServiceWorkerDatabase::Status status) { | 690 ServiceWorkerDatabase::Status status) { |
| 691 if (status != ServiceWorkerDatabase::STATUS_OK) { | 691 if (status != ServiceWorkerDatabase::STATUS_OK) { |
| 692 ScheduleDeleteAndStartOver(); | 692 ScheduleDeleteAndStartOver(); |
| 693 callback.Run(DatabaseStatusToStatusCode(status)); | 693 callback.Run(DatabaseStatusToStatusCode(status)); |
| 694 return; | 694 return; |
| 695 } | 695 } |
| 696 registered_origins_.insert(origin); | 696 registered_origins_.insert(origin); |
| 697 callback.Run(SERVICE_WORKER_OK); | 697 callback.Run(SERVICE_WORKER_OK); |
| 698 | 698 |
| 699 SchedulePurgeResources(deleted_version_id, newly_purgeable_resources); | 699 DecommissionVersion(deleted_version_id, newly_purgeable_resources); |
|
michaeln
2014/07/10 00:55:23
presuming two things:
* higher level job classes h
falken
2014/07/10 14:05:12
I think that block kind of makes sense, it's a spe
| |
| 700 } | 700 } |
| 701 | 701 |
| 702 void ServiceWorkerStorage::DidUpdateToActiveState( | 702 void ServiceWorkerStorage::DidUpdateToActiveState( |
| 703 const StatusCallback& callback, | 703 const StatusCallback& callback, |
| 704 ServiceWorkerDatabase::Status status) { | 704 ServiceWorkerDatabase::Status status) { |
| 705 if (status != ServiceWorkerDatabase::STATUS_OK && | 705 if (status != ServiceWorkerDatabase::STATUS_OK && |
| 706 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 706 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
| 707 ScheduleDeleteAndStartOver(); | 707 ScheduleDeleteAndStartOver(); |
| 708 } | 708 } |
| 709 callback.Run(DatabaseStatusToStatusCode(status)); | 709 callback.Run(DatabaseStatusToStatusCode(status)); |
| 710 } | 710 } |
| 711 | 711 |
| 712 void ServiceWorkerStorage::DidDeleteRegistration( | 712 void ServiceWorkerStorage::DidDeleteRegistration( |
| 713 const GURL& origin, | 713 const GURL& origin, |
| 714 const StatusCallback& callback, | 714 const StatusCallback& callback, |
| 715 bool origin_is_deletable, | 715 bool origin_is_deletable, |
| 716 int64 version_id, | 716 int64 version_id, |
| 717 const std::vector<int64>& newly_purgeable_resources, | 717 const std::vector<int64>& newly_purgeable_resources, |
| 718 ServiceWorkerDatabase::Status status) { | 718 ServiceWorkerDatabase::Status status) { |
| 719 if (status != ServiceWorkerDatabase::STATUS_OK) { | 719 if (status != ServiceWorkerDatabase::STATUS_OK) { |
| 720 ScheduleDeleteAndStartOver(); | 720 ScheduleDeleteAndStartOver(); |
| 721 callback.Run(DatabaseStatusToStatusCode(status)); | 721 callback.Run(DatabaseStatusToStatusCode(status)); |
| 722 return; | 722 return; |
| 723 } | 723 } |
| 724 if (origin_is_deletable) | 724 if (origin_is_deletable) |
| 725 registered_origins_.erase(origin); | 725 registered_origins_.erase(origin); |
| 726 callback.Run(SERVICE_WORKER_OK); | 726 callback.Run(SERVICE_WORKER_OK); |
| 727 | 727 |
| 728 SchedulePurgeResources(version_id, newly_purgeable_resources); | 728 DecommissionVersion(version_id, newly_purgeable_resources); |
| 729 } | 729 } |
| 730 | 730 |
| 731 scoped_refptr<ServiceWorkerRegistration> | 731 scoped_refptr<ServiceWorkerRegistration> |
| 732 ServiceWorkerStorage::GetOrCreateRegistration( | 732 ServiceWorkerStorage::GetOrCreateRegistration( |
| 733 const ServiceWorkerDatabase::RegistrationData& data, | 733 const ServiceWorkerDatabase::RegistrationData& data, |
| 734 const ResourceList& resources) { | 734 const ResourceList& resources) { |
| 735 scoped_refptr<ServiceWorkerRegistration> registration = | 735 scoped_refptr<ServiceWorkerRegistration> registration = |
| 736 context_->GetLiveRegistration(data.registration_id); | 736 context_->GetLiveRegistration(data.registration_id); |
| 737 if (registration) | 737 if (registration) |
| 738 return registration; | 738 return registration; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { | 829 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { |
| 830 if (rv != net::OK) { | 830 if (rv != net::OK) { |
| 831 LOG(ERROR) << "Failed to open the serviceworker diskcache: " | 831 LOG(ERROR) << "Failed to open the serviceworker diskcache: " |
| 832 << net::ErrorToString(rv); | 832 << net::ErrorToString(rv); |
| 833 ScheduleDeleteAndStartOver(); | 833 ScheduleDeleteAndStartOver(); |
| 834 } | 834 } |
| 835 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK); | 835 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK); |
| 836 } | 836 } |
| 837 | 837 |
| 838 void ServiceWorkerStorage::OnNoControllees(ServiceWorkerVersion* version) { | 838 void ServiceWorkerStorage::OnNoControllees(ServiceWorkerVersion* version) { |
| 839 version->RemoveListener(this); | |
| 840 version->SetStatus(ServiceWorkerVersion::REDUNDANT); | |
| 841 | |
| 839 std::map<int64, std::vector<int64> >::iterator it = | 842 std::map<int64, std::vector<int64> >::iterator it = |
| 840 deleted_version_resource_ids_.find(version->version_id()); | 843 deleted_version_resource_ids_.find(version->version_id()); |
| 841 DCHECK(it != deleted_version_resource_ids_.end()); | 844 DCHECK(it != deleted_version_resource_ids_.end()); |
| 842 StartPurgingResources(it->second); | 845 StartPurgingResources(it->second); |
| 843 deleted_version_resource_ids_.erase(it); | 846 deleted_version_resource_ids_.erase(it); |
| 844 version->RemoveListener(this); | |
| 845 } | 847 } |
| 846 | 848 |
| 847 void ServiceWorkerStorage::SchedulePurgeResources( | 849 void ServiceWorkerStorage::DecommissionVersion( |
| 848 int64 version_id, | 850 int64 version_id, |
| 849 const std::vector<int64>& resources) { | 851 const std::vector<int64>& resources) { |
| 850 DCHECK(deleted_version_resource_ids_.find(version_id) == | 852 DCHECK(deleted_version_resource_ids_.find(version_id) == |
| 851 deleted_version_resource_ids_.end()); | 853 deleted_version_resource_ids_.end()); |
| 852 if (resources.empty()) | |
| 853 return; | |
| 854 scoped_refptr<ServiceWorkerVersion> version = | 854 scoped_refptr<ServiceWorkerVersion> version = |
| 855 context_ ? context_->GetLiveVersion(version_id) : NULL; | 855 context_ ? context_->GetLiveVersion(version_id) : NULL; |
| 856 if (version && version->HasControllee()) { | 856 if (version && version->HasControllee()) { |
| 857 // Defer decommissioning. | |
| 857 deleted_version_resource_ids_[version_id] = resources; | 858 deleted_version_resource_ids_[version_id] = resources; |
| 858 version->AddListener(this); | 859 version->AddListener(this); |
| 859 } else { | 860 return; |
| 860 StartPurgingResources(resources); | |
| 861 } | 861 } |
| 862 | |
| 863 if (version) | |
| 864 version->SetStatus(ServiceWorkerVersion::REDUNDANT); | |
| 865 StartPurgingResources(resources); | |
| 862 } | 866 } |
| 863 | 867 |
| 864 void ServiceWorkerStorage::StartPurgingResources( | 868 void ServiceWorkerStorage::StartPurgingResources( |
| 865 const std::vector<int64>& ids) { | 869 const std::vector<int64>& ids) { |
| 866 for (size_t i = 0; i < ids.size(); ++i) | 870 for (size_t i = 0; i < ids.size(); ++i) |
| 867 purgeable_resource_ids_.push_back(ids[i]); | 871 purgeable_resource_ids_.push_back(ids[i]); |
| 868 ContinuePurgingResources(); | 872 ContinuePurgingResources(); |
| 869 } | 873 } |
| 870 | 874 |
| 871 void ServiceWorkerStorage::StartPurgingResources( | 875 void ServiceWorkerStorage::StartPurgingResources( |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1141 // Give up the corruption recovery until the browser restarts. | 1145 // Give up the corruption recovery until the browser restarts. |
| 1142 LOG(ERROR) << "Failed to delete the diskcache."; | 1146 LOG(ERROR) << "Failed to delete the diskcache."; |
| 1143 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1147 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
| 1144 return; | 1148 return; |
| 1145 } | 1149 } |
| 1146 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1150 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
| 1147 callback.Run(SERVICE_WORKER_OK); | 1151 callback.Run(SERVICE_WORKER_OK); |
| 1148 } | 1152 } |
| 1149 | 1153 |
| 1150 } // namespace content | 1154 } // namespace content |
| OLD | NEW |