OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_cache.h" | 5 #include "content/browser/service_worker/service_worker_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 if (put_context->blob_data_handle) { | 708 if (put_context->blob_data_handle) { |
709 // Grab another handle to the blob for the callback response. | 709 // Grab another handle to the blob for the callback response. |
710 put_context->out_blob_data_handle = | 710 put_context->out_blob_data_handle = |
711 blob_storage_context_->GetBlobDataFromUUID( | 711 blob_storage_context_->GetBlobDataFromUUID( |
712 put_context->response->blob_uuid); | 712 put_context->response->blob_uuid); |
713 } | 713 } |
714 | 714 |
715 base::Closure continuation = base::Bind(&ServiceWorkerCache::PutImpl, | 715 base::Closure continuation = base::Bind(&ServiceWorkerCache::PutImpl, |
716 base::Passed(put_context.Pass())); | 716 base::Passed(put_context.Pass())); |
717 | 717 |
718 if (!initialized_) { | 718 if (backend_state_ == BACKEND_UNINITIALIZED) { |
719 Init(continuation); | 719 InitBackend(continuation); |
720 return; | 720 return; |
721 } | 721 } |
722 | 722 |
723 continuation.Run(); | 723 continuation.Run(); |
724 } | 724 } |
725 | 725 |
726 void ServiceWorkerCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request, | 726 void ServiceWorkerCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request, |
727 const ResponseCallback& callback) { | 727 const ResponseCallback& callback) { |
728 IncPendingOps(); | 728 IncPendingOps(); |
729 ResponseCallback pending_callback = | 729 ResponseCallback pending_callback = |
730 base::Bind(&ServiceWorkerCache::PendingResponseCallback, | 730 base::Bind(&ServiceWorkerCache::PendingResponseCallback, |
731 weak_ptr_factory_.GetWeakPtr(), callback); | 731 weak_ptr_factory_.GetWeakPtr(), callback); |
732 | 732 |
733 if (!initialized_) { | 733 switch (backend_state_) { |
734 Init(base::Bind(&ServiceWorkerCache::Match, weak_ptr_factory_.GetWeakPtr(), | 734 case BACKEND_UNINITIALIZED: |
735 base::Passed(request.Pass()), pending_callback)); | 735 InitBackend(base::Bind(&ServiceWorkerCache::Match, |
736 return; | 736 weak_ptr_factory_.GetWeakPtr(), |
737 } | 737 base::Passed(request.Pass()), pending_callback)); |
738 if (!backend_) { | 738 return; |
739 pending_callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>(), | 739 case BACKEND_CLOSED: |
740 scoped_ptr<storage::BlobDataHandle>()); | 740 pending_callback.Run(ErrorTypeStorage, |
741 return; | 741 scoped_ptr<ServiceWorkerResponse>(), |
| 742 scoped_ptr<storage::BlobDataHandle>()); |
| 743 return; |
| 744 case BACKEND_OPEN: |
| 745 DCHECK(backend_); |
| 746 break; |
742 } | 747 } |
743 | 748 |
744 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 749 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
745 | 750 |
746 disk_cache::Entry** entry_ptr = entry.get(); | 751 disk_cache::Entry** entry_ptr = entry.get(); |
747 | 752 |
748 ServiceWorkerFetchRequest* request_ptr = request.get(); | 753 ServiceWorkerFetchRequest* request_ptr = request.get(); |
749 | 754 |
750 net::CompletionCallback open_entry_callback = base::Bind( | 755 net::CompletionCallback open_entry_callback = base::Bind( |
751 MatchDidOpenEntry, base::Passed(request.Pass()), pending_callback, | 756 MatchDidOpenEntry, base::Passed(request.Pass()), pending_callback, |
752 blob_storage_context_, base::Passed(entry.Pass())); | 757 blob_storage_context_, base::Passed(entry.Pass())); |
753 | 758 |
754 int rv = backend_->OpenEntry( | 759 int rv = backend_->OpenEntry( |
755 request_ptr->url.spec(), entry_ptr, open_entry_callback); | 760 request_ptr->url.spec(), entry_ptr, open_entry_callback); |
756 if (rv != net::ERR_IO_PENDING) | 761 if (rv != net::ERR_IO_PENDING) |
757 open_entry_callback.Run(rv); | 762 open_entry_callback.Run(rv); |
758 } | 763 } |
759 | 764 |
760 void ServiceWorkerCache::Delete(scoped_ptr<ServiceWorkerFetchRequest> request, | 765 void ServiceWorkerCache::Delete(scoped_ptr<ServiceWorkerFetchRequest> request, |
761 const ErrorCallback& callback) { | 766 const ErrorCallback& callback) { |
762 IncPendingOps(); | 767 IncPendingOps(); |
763 ErrorCallback pending_callback = | 768 ErrorCallback pending_callback = |
764 base::Bind(&ServiceWorkerCache::PendingErrorCallback, | 769 base::Bind(&ServiceWorkerCache::PendingErrorCallback, |
765 weak_ptr_factory_.GetWeakPtr(), callback); | 770 weak_ptr_factory_.GetWeakPtr(), callback); |
766 | 771 |
767 if (!initialized_) { | 772 switch (backend_state_) { |
768 Init(base::Bind(&ServiceWorkerCache::Delete, weak_ptr_factory_.GetWeakPtr(), | 773 case BACKEND_UNINITIALIZED: |
769 base::Passed(request.Pass()), pending_callback)); | 774 InitBackend(base::Bind(&ServiceWorkerCache::Delete, |
770 return; | 775 weak_ptr_factory_.GetWeakPtr(), |
771 } | 776 base::Passed(request.Pass()), pending_callback)); |
772 if (!backend_) { | 777 return; |
773 pending_callback.Run(ErrorTypeStorage); | 778 case BACKEND_CLOSED: |
774 return; | 779 pending_callback.Run(ErrorTypeStorage); |
| 780 return; |
| 781 case BACKEND_OPEN: |
| 782 DCHECK(backend_); |
| 783 break; |
775 } | 784 } |
776 | 785 |
777 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 786 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
778 | 787 |
779 disk_cache::Entry** entry_ptr = entry.get(); | 788 disk_cache::Entry** entry_ptr = entry.get(); |
780 | 789 |
781 ServiceWorkerFetchRequest* request_ptr = request.get(); | 790 ServiceWorkerFetchRequest* request_ptr = request.get(); |
782 | 791 |
783 net::CompletionCallback open_entry_callback = base::Bind( | 792 net::CompletionCallback open_entry_callback = base::Bind( |
784 DeleteDidOpenEntry, origin_, base::Passed(request.Pass()), | 793 DeleteDidOpenEntry, origin_, base::Passed(request.Pass()), |
785 pending_callback, base::Passed(entry.Pass()), quota_manager_proxy_); | 794 pending_callback, base::Passed(entry.Pass()), quota_manager_proxy_); |
786 | 795 |
787 int rv = backend_->OpenEntry( | 796 int rv = backend_->OpenEntry( |
788 request_ptr->url.spec(), entry_ptr, open_entry_callback); | 797 request_ptr->url.spec(), entry_ptr, open_entry_callback); |
789 if (rv != net::ERR_IO_PENDING) | 798 if (rv != net::ERR_IO_PENDING) |
790 open_entry_callback.Run(rv); | 799 open_entry_callback.Run(rv); |
791 } | 800 } |
792 | 801 |
793 void ServiceWorkerCache::Keys(const RequestsCallback& callback) { | 802 void ServiceWorkerCache::Keys(const RequestsCallback& callback) { |
794 IncPendingOps(); | 803 IncPendingOps(); |
795 RequestsCallback pending_callback = | 804 RequestsCallback pending_callback = |
796 base::Bind(&ServiceWorkerCache::PendingRequestsCallback, | 805 base::Bind(&ServiceWorkerCache::PendingRequestsCallback, |
797 weak_ptr_factory_.GetWeakPtr(), callback); | 806 weak_ptr_factory_.GetWeakPtr(), callback); |
798 if (!initialized_) { | 807 |
799 Init(base::Bind(&ServiceWorkerCache::Keys, weak_ptr_factory_.GetWeakPtr(), | 808 switch (backend_state_) { |
800 pending_callback)); | 809 case BACKEND_UNINITIALIZED: |
801 return; | 810 InitBackend(base::Bind(&ServiceWorkerCache::Keys, |
802 } | 811 weak_ptr_factory_.GetWeakPtr(), pending_callback)); |
803 if (!backend_) { | 812 return; |
804 pending_callback.Run(ErrorTypeStorage, scoped_ptr<Requests>()); | 813 case BACKEND_CLOSED: |
805 return; | 814 pending_callback.Run(ErrorTypeStorage, scoped_ptr<Requests>()); |
| 815 return; |
| 816 case BACKEND_OPEN: |
| 817 DCHECK(backend_); |
| 818 break; |
806 } | 819 } |
807 | 820 |
808 // 1. Iterate through all of the entries, open them, and add them to a vector. | 821 // 1. Iterate through all of the entries, open them, and add them to a vector. |
809 // 2. For each open entry: | 822 // 2. For each open entry: |
810 // 2.1. Read the headers into a protobuf. | 823 // 2.1. Read the headers into a protobuf. |
811 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key"). | 824 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key"). |
812 // 2.3. Push the response into a vector of requests to be returned. | 825 // 2.3. Push the response into a vector of requests to be returned. |
813 // 3. Return the vector of requests (keys). | 826 // 3. Return the vector of requests (keys). |
814 | 827 |
815 // The entries have to be loaded into a vector first because enumeration loops | 828 // The entries have to be loaded into a vector first because enumeration loops |
816 // forever if you read data from a cache entry while enumerating. | 829 // forever if you read data from a cache entry while enumerating. |
817 | 830 |
818 scoped_ptr<KeysContext> keys_context( | 831 scoped_ptr<KeysContext> keys_context( |
819 new KeysContext(pending_callback, weak_ptr_factory_.GetWeakPtr())); | 832 new KeysContext(pending_callback, weak_ptr_factory_.GetWeakPtr())); |
820 | 833 |
821 keys_context->backend_iterator = backend_->CreateIterator(); | 834 keys_context->backend_iterator = backend_->CreateIterator(); |
822 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator; | 835 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator; |
823 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; | 836 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; |
824 | 837 |
825 net::CompletionCallback open_entry_callback = | 838 net::CompletionCallback open_entry_callback = |
826 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); | 839 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); |
827 | 840 |
828 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); | 841 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); |
829 | 842 |
830 if (rv != net::ERR_IO_PENDING) | 843 if (rv != net::ERR_IO_PENDING) |
831 open_entry_callback.Run(rv); | 844 open_entry_callback.Run(rv); |
832 } | 845 } |
833 | 846 |
834 void ServiceWorkerCache::Close(const base::Closure& callback) { | 847 void ServiceWorkerCache::Close(const base::Closure& callback) { |
835 DCHECK(!initialized_ || backend_) | 848 DCHECK(backend_state_ != BACKEND_CLOSED) |
836 << "Don't call ServiceWorkerCache::Close() twice."; | 849 << "Don't call ServiceWorkerCache::Close() twice."; |
837 | 850 |
| 851 backend_state_ = BACKEND_CLOSED; |
838 if (pending_ops_ > 0) { | 852 if (pending_ops_ > 0) { |
839 DCHECK(ops_complete_callback_.is_null()); | 853 DCHECK(ops_complete_callback_.is_null()); |
840 initialized_ = true; // So that future operations halt. | 854 ops_complete_callback_ = |
841 ops_complete_callback_ = base::Bind( | 855 base::Bind(&ServiceWorkerCache::CloseImpl, |
842 &ServiceWorkerCache::Close, weak_ptr_factory_.GetWeakPtr(), callback); | 856 weak_ptr_factory_.GetWeakPtr(), callback); |
843 return; | 857 return; |
844 } | 858 } |
845 | 859 |
846 initialized_ = true; | 860 CloseImpl(callback); |
847 backend_.reset(); | |
848 callback.Run(); | |
849 } | 861 } |
850 | 862 |
851 int64 ServiceWorkerCache::MemoryBackedSize() const { | 863 int64 ServiceWorkerCache::MemoryBackedSize() const { |
852 if (!backend_ || !memory_only_) | 864 if (backend_state_ != BACKEND_OPEN || !memory_only_) |
853 return 0; | 865 return 0; |
854 | 866 |
855 scoped_ptr<disk_cache::Backend::Iterator> backend_iter = | 867 scoped_ptr<disk_cache::Backend::Iterator> backend_iter = |
856 backend_->CreateIterator(); | 868 backend_->CreateIterator(); |
857 disk_cache::Entry* entry = nullptr; | 869 disk_cache::Entry* entry = nullptr; |
858 | 870 |
859 int64 sum = 0; | 871 int64 sum = 0; |
860 | 872 |
861 std::vector<disk_cache::Entry*> entries; | 873 std::vector<disk_cache::Entry*> entries; |
862 int rv = net::OK; | 874 int rv = net::OK; |
(...skipping 17 matching lines...) Expand all Loading... |
880 const GURL& origin, | 892 const GURL& origin, |
881 const base::FilePath& path, | 893 const base::FilePath& path, |
882 net::URLRequestContext* request_context, | 894 net::URLRequestContext* request_context, |
883 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, | 895 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
884 base::WeakPtr<storage::BlobStorageContext> blob_context) | 896 base::WeakPtr<storage::BlobStorageContext> blob_context) |
885 : origin_(origin), | 897 : origin_(origin), |
886 path_(path), | 898 path_(path), |
887 request_context_(request_context), | 899 request_context_(request_context), |
888 quota_manager_proxy_(quota_manager_proxy), | 900 quota_manager_proxy_(quota_manager_proxy), |
889 blob_storage_context_(blob_context), | 901 blob_storage_context_(blob_context), |
890 initialized_(false), | 902 backend_state_(BACKEND_UNINITIALIZED), |
891 memory_only_(path.empty()), | 903 memory_only_(path.empty()), |
892 pending_ops_(0), | 904 pending_ops_(0), |
893 weak_ptr_factory_(this) { | 905 weak_ptr_factory_(this) { |
894 } | 906 } |
895 | 907 |
896 // static | 908 // static |
897 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { | 909 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { |
898 if (!put_context->cache || !put_context->cache->backend_) { | 910 if (!put_context->cache || |
| 911 put_context->cache->backend_state_ != BACKEND_OPEN) { |
899 put_context->callback.Run(ErrorTypeStorage, | 912 put_context->callback.Run(ErrorTypeStorage, |
900 scoped_ptr<ServiceWorkerResponse>(), | 913 scoped_ptr<ServiceWorkerResponse>(), |
901 scoped_ptr<storage::BlobDataHandle>()); | 914 scoped_ptr<storage::BlobDataHandle>()); |
902 return; | 915 return; |
903 } | 916 } |
904 | 917 |
905 scoped_ptr<ServiceWorkerFetchRequest> request_copy( | 918 scoped_ptr<ServiceWorkerFetchRequest> request_copy( |
906 new ServiceWorkerFetchRequest(*put_context->request)); | 919 new ServiceWorkerFetchRequest(*put_context->request)); |
907 ServiceWorkerCache* cache_ptr = put_context->cache.get(); | 920 ServiceWorkerCache* cache_ptr = put_context->cache.get(); |
908 | 921 |
909 cache_ptr->Delete(request_copy.Pass(), | 922 cache_ptr->Delete(request_copy.Pass(), |
910 base::Bind(PutDidDelete, base::Passed(put_context.Pass()))); | 923 base::Bind(PutDidDelete, base::Passed(put_context.Pass()))); |
911 } | 924 } |
912 | 925 |
913 // static | 926 // static |
914 void ServiceWorkerCache::PutDidDelete(scoped_ptr<PutContext> put_context, | 927 void ServiceWorkerCache::PutDidDelete(scoped_ptr<PutContext> put_context, |
915 ErrorType delete_error) { | 928 ErrorType delete_error) { |
916 if (!put_context->cache || !put_context->cache->backend_) { | 929 if (!put_context->cache || |
| 930 put_context->cache->backend_state_ != BACKEND_OPEN) { |
917 put_context->callback.Run(ErrorTypeStorage, | 931 put_context->callback.Run(ErrorTypeStorage, |
918 scoped_ptr<ServiceWorkerResponse>(), | 932 scoped_ptr<ServiceWorkerResponse>(), |
919 scoped_ptr<storage::BlobDataHandle>()); | 933 scoped_ptr<storage::BlobDataHandle>()); |
920 return; | 934 return; |
921 } | 935 } |
922 | 936 |
923 disk_cache::Entry** entry_ptr = &put_context->cache_entry; | 937 disk_cache::Entry** entry_ptr = &put_context->cache_entry; |
924 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); | 938 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); |
925 disk_cache::Backend* backend_ptr = put_context->cache->backend_.get(); | 939 disk_cache::Backend* backend_ptr = put_context->cache->backend_.get(); |
926 | 940 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 return; | 1108 return; |
1095 } | 1109 } |
1096 | 1110 |
1097 base::WeakPtr<ServiceWorkerCache> cache = keys_context->cache; | 1111 base::WeakPtr<ServiceWorkerCache> cache = keys_context->cache; |
1098 if (rv < 0 || !cache) { | 1112 if (rv < 0 || !cache) { |
1099 keys_context->original_callback.Run(ErrorTypeStorage, | 1113 keys_context->original_callback.Run(ErrorTypeStorage, |
1100 scoped_ptr<Requests>()); | 1114 scoped_ptr<Requests>()); |
1101 return; | 1115 return; |
1102 } | 1116 } |
1103 | 1117 |
1104 if (!cache->backend_) { | 1118 if (cache->backend_state_ != BACKEND_OPEN) { |
1105 keys_context->original_callback.Run(ErrorTypeNotFound, | 1119 keys_context->original_callback.Run(ErrorTypeNotFound, |
1106 scoped_ptr<Requests>()); | 1120 scoped_ptr<Requests>()); |
1107 return; | 1121 return; |
1108 } | 1122 } |
1109 | 1123 |
1110 // Store the entry. | 1124 // Store the entry. |
1111 keys_context->entries.push_back(keys_context->enumerated_entry); | 1125 keys_context->entries.push_back(keys_context->enumerated_entry); |
1112 keys_context->enumerated_entry = NULL; | 1126 keys_context->enumerated_entry = NULL; |
1113 | 1127 |
1114 // Enumerate the next entry. | 1128 // Enumerate the next entry. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 const ServiceWorkerCacheHeaderMap header = metadata->request().headers(i); | 1175 const ServiceWorkerCacheHeaderMap header = metadata->request().headers(i); |
1162 req_headers.insert(std::make_pair(header.name(), header.value())); | 1176 req_headers.insert(std::make_pair(header.name(), header.value())); |
1163 } | 1177 } |
1164 } else { | 1178 } else { |
1165 entry->Doom(); | 1179 entry->Doom(); |
1166 } | 1180 } |
1167 | 1181 |
1168 KeysProcessNextEntry(keys_context.Pass(), iter + 1); | 1182 KeysProcessNextEntry(keys_context.Pass(), iter + 1); |
1169 } | 1183 } |
1170 | 1184 |
| 1185 void ServiceWorkerCache::CloseImpl(const base::Closure& callback) { |
| 1186 DCHECK(backend_state_ == BACKEND_CLOSED); |
| 1187 backend_.reset(); |
| 1188 callback.Run(); |
| 1189 } |
| 1190 |
1171 void ServiceWorkerCache::CreateBackend(const ErrorCallback& callback) { | 1191 void ServiceWorkerCache::CreateBackend(const ErrorCallback& callback) { |
1172 DCHECK(!backend_); | 1192 DCHECK(!backend_); |
1173 | 1193 |
1174 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction. | 1194 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction. |
1175 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE; | 1195 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE; |
1176 | 1196 |
1177 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr()); | 1197 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr()); |
1178 | 1198 |
1179 // Temporary pointer so that backend_ptr can be Pass()'d in Bind below. | 1199 // Temporary pointer so that backend_ptr can be Pass()'d in Bind below. |
1180 ScopedBackendPtr* backend = backend_ptr.get(); | 1200 ScopedBackendPtr* backend = backend_ptr.get(); |
(...skipping 13 matching lines...) Expand all Loading... |
1194 kMaxCacheBytes, | 1214 kMaxCacheBytes, |
1195 false, /* force */ | 1215 false, /* force */ |
1196 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), | 1216 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), |
1197 NULL, | 1217 NULL, |
1198 backend, | 1218 backend, |
1199 create_cache_callback); | 1219 create_cache_callback); |
1200 if (rv != net::ERR_IO_PENDING) | 1220 if (rv != net::ERR_IO_PENDING) |
1201 create_cache_callback.Run(rv); | 1221 create_cache_callback.Run(rv); |
1202 } | 1222 } |
1203 | 1223 |
1204 void ServiceWorkerCache::Init(const base::Closure& callback) { | 1224 void ServiceWorkerCache::InitBackend(const base::Closure& callback) { |
1205 DCHECK(!initialized_); | 1225 DCHECK(backend_state_ == BACKEND_UNINITIALIZED); |
1206 init_callbacks_.push_back(callback); | 1226 init_callbacks_.push_back(callback); |
1207 | 1227 |
1208 // If this isn't the first call to Init then return as the initialization | 1228 // If this isn't the first call to Init then return as the initialization |
1209 // has already started. | 1229 // has already started. |
1210 if (init_callbacks_.size() > 1u) | 1230 if (init_callbacks_.size() > 1u) |
1211 return; | 1231 return; |
1212 | 1232 |
1213 CreateBackend(base::Bind(&ServiceWorkerCache::InitDone, | 1233 CreateBackend(base::Bind(&ServiceWorkerCache::InitDone, |
1214 weak_ptr_factory_.GetWeakPtr())); | 1234 weak_ptr_factory_.GetWeakPtr())); |
1215 } | 1235 } |
1216 | 1236 |
1217 void ServiceWorkerCache::InitDone(ErrorType error) { | 1237 void ServiceWorkerCache::InitDone(ErrorType error) { |
1218 initialized_ = true; | 1238 backend_state_ = (error == ErrorTypeOK && backend_ && |
| 1239 backend_state_ == BACKEND_UNINITIALIZED) |
| 1240 ? BACKEND_OPEN |
| 1241 : BACKEND_CLOSED; |
1219 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | 1242 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); |
1220 it != init_callbacks_.end(); | 1243 it != init_callbacks_.end(); ++it) { |
1221 ++it) { | |
1222 it->Run(); | 1244 it->Run(); |
1223 } | 1245 } |
1224 init_callbacks_.clear(); | 1246 init_callbacks_.clear(); |
1225 } | 1247 } |
1226 | 1248 |
1227 void ServiceWorkerCache::DecPendingOps() { | 1249 void ServiceWorkerCache::DecPendingOps() { |
1228 DCHECK(pending_ops_ > 0); | 1250 DCHECK(pending_ops_ > 0); |
1229 pending_ops_--; | 1251 pending_ops_--; |
1230 if (pending_ops_ == 0 && !ops_complete_callback_.is_null()) { | 1252 if (pending_ops_ == 0 && !ops_complete_callback_.is_null()) { |
1231 ops_complete_callback_.Run(); | 1253 ops_complete_callback_.Run(); |
(...skipping 18 matching lines...) Expand all Loading... |
1250 | 1272 |
1251 void ServiceWorkerCache::PendingRequestsCallback( | 1273 void ServiceWorkerCache::PendingRequestsCallback( |
1252 const RequestsCallback& callback, | 1274 const RequestsCallback& callback, |
1253 ErrorType error, | 1275 ErrorType error, |
1254 scoped_ptr<Requests> requests) { | 1276 scoped_ptr<Requests> requests) { |
1255 callback.Run(error, requests.Pass()); | 1277 callback.Run(error, requests.Pass()); |
1256 DecPendingOps(); | 1278 DecPendingOps(); |
1257 } | 1279 } |
1258 | 1280 |
1259 } // namespace content | 1281 } // namespace content |
OLD | NEW |