| 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 "webkit/browser/appcache/appcache_service_impl.h" | 5 #include "content/browser/appcache/appcache_service_impl.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "content/browser/appcache/appcache.h" |
| 15 #include "content/browser/appcache/appcache_backend_impl.h" |
| 16 #include "content/browser/appcache/appcache_entry.h" |
| 17 #include "content/browser/appcache/appcache_executable_handler.h" |
| 18 #include "content/browser/appcache/appcache_histograms.h" |
| 19 #include "content/browser/appcache/appcache_policy.h" |
| 20 #include "content/browser/appcache/appcache_quota_client.h" |
| 21 #include "content/browser/appcache/appcache_response.h" |
| 22 #include "content/browser/appcache/appcache_service_impl.h" |
| 23 #include "content/browser/appcache/appcache_storage_impl.h" |
| 14 #include "net/base/completion_callback.h" | 24 #include "net/base/completion_callback.h" |
| 15 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
| 16 #include "webkit/browser/appcache/appcache.h" | |
| 17 #include "webkit/browser/appcache/appcache_backend_impl.h" | |
| 18 #include "webkit/browser/appcache/appcache_entry.h" | |
| 19 #include "webkit/browser/appcache/appcache_executable_handler.h" | |
| 20 #include "webkit/browser/appcache/appcache_histograms.h" | |
| 21 #include "webkit/browser/appcache/appcache_policy.h" | |
| 22 #include "webkit/browser/appcache/appcache_quota_client.h" | |
| 23 #include "webkit/browser/appcache/appcache_response.h" | |
| 24 #include "webkit/browser/appcache/appcache_service_impl.h" | |
| 25 #include "webkit/browser/appcache/appcache_storage_impl.h" | |
| 26 #include "webkit/browser/quota/special_storage_policy.h" | 26 #include "webkit/browser/quota/special_storage_policy.h" |
| 27 | 27 |
| 28 namespace appcache { | 28 namespace content { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 void DeferredCallback(const net::CompletionCallback& callback, int rv) { | 32 void DeferredCallback(const net::CompletionCallback& callback, int rv) { |
| 33 callback.Run(rv); | 33 callback.Run(rv); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 AppCacheInfoCollection::AppCacheInfoCollection() {} | 38 AppCacheInfoCollection::AppCacheInfoCollection() {} |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 : AsyncHelper(service, callback), manifest_url_(manifest_url) { | 136 : AsyncHelper(service, callback), manifest_url_(manifest_url) { |
| 137 } | 137 } |
| 138 | 138 |
| 139 virtual void Start() OVERRIDE { | 139 virtual void Start() OVERRIDE { |
| 140 service_->storage()->LoadOrCreateGroup(manifest_url_, this); | 140 service_->storage()->LoadOrCreateGroup(manifest_url_, this); |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 // AppCacheStorage::Delegate implementation. | 144 // AppCacheStorage::Delegate implementation. |
| 145 virtual void OnGroupLoaded( | 145 virtual void OnGroupLoaded( |
| 146 appcache::AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; | 146 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; |
| 147 virtual void OnGroupMadeObsolete(appcache::AppCacheGroup* group, | 147 virtual void OnGroupMadeObsolete(AppCacheGroup* group, |
| 148 bool success, | 148 bool success, |
| 149 int response_code) OVERRIDE; | 149 int response_code) OVERRIDE; |
| 150 | 150 |
| 151 GURL manifest_url_; | 151 GURL manifest_url_; |
| 152 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); | 152 DISALLOW_COPY_AND_ASSIGN(DeleteHelper); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 void AppCacheServiceImpl::DeleteHelper::OnGroupLoaded( | 155 void AppCacheServiceImpl::DeleteHelper::OnGroupLoaded( |
| 156 appcache::AppCacheGroup* group, const GURL& manifest_url) { | 156 AppCacheGroup* group, const GURL& manifest_url) { |
| 157 if (group) { | 157 if (group) { |
| 158 group->set_being_deleted(true); | 158 group->set_being_deleted(true); |
| 159 group->CancelUpdate(); | 159 group->CancelUpdate(); |
| 160 service_->storage()->MakeGroupObsolete(group, this, 0); | 160 service_->storage()->MakeGroupObsolete(group, this, 0); |
| 161 } else { | 161 } else { |
| 162 CallCallback(net::ERR_FAILED); | 162 CallCallback(net::ERR_FAILED); |
| 163 delete this; | 163 delete this; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void AppCacheServiceImpl::DeleteHelper::OnGroupMadeObsolete( | 167 void AppCacheServiceImpl::DeleteHelper::OnGroupMadeObsolete( |
| 168 appcache::AppCacheGroup* group, | 168 AppCacheGroup* group, |
| 169 bool success, | 169 bool success, |
| 170 int response_code) { | 170 int response_code) { |
| 171 CallCallback(success ? net::OK : net::ERR_FAILED); | 171 CallCallback(success ? net::OK : net::ERR_FAILED); |
| 172 delete this; | 172 delete this; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // DeleteOriginHelper ------- | 175 // DeleteOriginHelper ------- |
| 176 | 176 |
| 177 class AppCacheServiceImpl::DeleteOriginHelper : public AsyncHelper { | 177 class AppCacheServiceImpl::DeleteOriginHelper : public AsyncHelper { |
| 178 public: | 178 public: |
| 179 DeleteOriginHelper( | 179 DeleteOriginHelper( |
| 180 AppCacheServiceImpl* service, const GURL& origin, | 180 AppCacheServiceImpl* service, const GURL& origin, |
| 181 const net::CompletionCallback& callback) | 181 const net::CompletionCallback& callback) |
| 182 : AsyncHelper(service, callback), origin_(origin), | 182 : AsyncHelper(service, callback), origin_(origin), |
| 183 num_caches_to_delete_(0), successes_(0), failures_(0) { | 183 num_caches_to_delete_(0), successes_(0), failures_(0) { |
| 184 } | 184 } |
| 185 | 185 |
| 186 virtual void Start() OVERRIDE { | 186 virtual void Start() OVERRIDE { |
| 187 // We start by listing all caches, continues in OnAllInfo(). | 187 // We start by listing all caches, continues in OnAllInfo(). |
| 188 service_->storage()->GetAllInfo(this); | 188 service_->storage()->GetAllInfo(this); |
| 189 } | 189 } |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 // AppCacheStorage::Delegate implementation. | 192 // AppCacheStorage::Delegate implementation. |
| 193 virtual void OnAllInfo(AppCacheInfoCollection* collection) OVERRIDE; | 193 virtual void OnAllInfo(AppCacheInfoCollection* collection) OVERRIDE; |
| 194 virtual void OnGroupLoaded( | 194 virtual void OnGroupLoaded( |
| 195 appcache::AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; | 195 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE; |
| 196 virtual void OnGroupMadeObsolete(appcache::AppCacheGroup* group, | 196 virtual void OnGroupMadeObsolete(AppCacheGroup* group, |
| 197 bool success, | 197 bool success, |
| 198 int response_code) OVERRIDE; | 198 int response_code) OVERRIDE; |
| 199 | 199 |
| 200 void CacheCompleted(bool success); | 200 void CacheCompleted(bool success); |
| 201 | 201 |
| 202 GURL origin_; | 202 GURL origin_; |
| 203 int num_caches_to_delete_; | 203 int num_caches_to_delete_; |
| 204 int successes_; | 204 int successes_; |
| 205 int failures_; | 205 int failures_; |
| 206 | 206 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 230 successes_ = 0; | 230 successes_ = 0; |
| 231 failures_ = 0; | 231 failures_ = 0; |
| 232 num_caches_to_delete_ = static_cast<int>(caches_to_delete.size()); | 232 num_caches_to_delete_ = static_cast<int>(caches_to_delete.size()); |
| 233 for (AppCacheInfoVector::const_iterator iter = caches_to_delete.begin(); | 233 for (AppCacheInfoVector::const_iterator iter = caches_to_delete.begin(); |
| 234 iter != caches_to_delete.end(); ++iter) { | 234 iter != caches_to_delete.end(); ++iter) { |
| 235 service_->storage()->LoadOrCreateGroup(iter->manifest_url, this); | 235 service_->storage()->LoadOrCreateGroup(iter->manifest_url, this); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 void AppCacheServiceImpl::DeleteOriginHelper::OnGroupLoaded( | 239 void AppCacheServiceImpl::DeleteOriginHelper::OnGroupLoaded( |
| 240 appcache::AppCacheGroup* group, const GURL& manifest_url) { | 240 AppCacheGroup* group, const GURL& manifest_url) { |
| 241 if (group) { | 241 if (group) { |
| 242 group->set_being_deleted(true); | 242 group->set_being_deleted(true); |
| 243 group->CancelUpdate(); | 243 group->CancelUpdate(); |
| 244 service_->storage()->MakeGroupObsolete(group, this, 0); | 244 service_->storage()->MakeGroupObsolete(group, this, 0); |
| 245 } else { | 245 } else { |
| 246 CacheCompleted(false); | 246 CacheCompleted(false); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 void AppCacheServiceImpl::DeleteOriginHelper::OnGroupMadeObsolete( | 250 void AppCacheServiceImpl::DeleteOriginHelper::OnGroupMadeObsolete( |
| 251 appcache::AppCacheGroup* group, | 251 AppCacheGroup* group, |
| 252 bool success, | 252 bool success, |
| 253 int response_code) { | 253 int response_code) { |
| 254 CacheCompleted(success); | 254 CacheCompleted(success); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void AppCacheServiceImpl::DeleteOriginHelper::CacheCompleted(bool success) { | 257 void AppCacheServiceImpl::DeleteOriginHelper::CacheCompleted(bool success) { |
| 258 if (success) | 258 if (success) |
| 259 ++successes_; | 259 ++successes_; |
| 260 else | 260 else |
| 261 ++failures_; | 261 ++failures_; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); | 568 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); |
| 569 backends_.insert( | 569 backends_.insert( |
| 570 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 570 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void AppCacheServiceImpl::UnregisterBackend( | 573 void AppCacheServiceImpl::UnregisterBackend( |
| 574 AppCacheBackendImpl* backend_impl) { | 574 AppCacheBackendImpl* backend_impl) { |
| 575 backends_.erase(backend_impl->process_id()); | 575 backends_.erase(backend_impl->process_id()); |
| 576 } | 576 } |
| 577 | 577 |
| 578 } // namespace appcache | 578 } // namespace content |
| OLD | NEW |