| 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/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/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "content/browser/appcache/appcache.h" | 17 #include "content/browser/appcache/appcache.h" |
| 17 #include "content/browser/appcache/appcache_backend_impl.h" | 18 #include "content/browser/appcache/appcache_backend_impl.h" |
| 18 #include "content/browser/appcache/appcache_entry.h" | 19 #include "content/browser/appcache/appcache_entry.h" |
| 19 #include "content/browser/appcache/appcache_executable_handler.h" | 20 #include "content/browser/appcache/appcache_executable_handler.h" |
| 20 #include "content/browser/appcache/appcache_histograms.h" | 21 #include "content/browser/appcache/appcache_histograms.h" |
| 21 #include "content/browser/appcache/appcache_policy.h" | 22 #include "content/browser/appcache/appcache_policy.h" |
| 22 #include "content/browser/appcache/appcache_quota_client.h" | 23 #include "content/browser/appcache/appcache_quota_client.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (collection) | 249 if (collection) |
| 249 collection->infos_by_origin.swap(collection_->infos_by_origin); | 250 collection->infos_by_origin.swap(collection_->infos_by_origin); |
| 250 CallCallback(collection ? net::OK : net::ERR_FAILED); | 251 CallCallback(collection ? net::OK : net::ERR_FAILED); |
| 251 delete this; | 252 delete this; |
| 252 } | 253 } |
| 253 | 254 |
| 254 // CheckResponseHelper ------- | 255 // CheckResponseHelper ------- |
| 255 | 256 |
| 256 class AppCacheServiceImpl::CheckResponseHelper : AsyncHelper { | 257 class AppCacheServiceImpl::CheckResponseHelper : AsyncHelper { |
| 257 public: | 258 public: |
| 258 CheckResponseHelper( | 259 CheckResponseHelper(AppCacheServiceImpl* service, |
| 259 AppCacheServiceImpl* service, const GURL& manifest_url, int64 cache_id, | 260 const GURL& manifest_url, |
| 260 int64 response_id) | 261 int64_t cache_id, |
| 262 int64_t response_id) |
| 261 : AsyncHelper(service, net::CompletionCallback()), | 263 : AsyncHelper(service, net::CompletionCallback()), |
| 262 manifest_url_(manifest_url), | 264 manifest_url_(manifest_url), |
| 263 cache_id_(cache_id), | 265 cache_id_(cache_id), |
| 264 response_id_(response_id), | 266 response_id_(response_id), |
| 265 kIOBufferSize(32 * 1024), | 267 kIOBufferSize(32 * 1024), |
| 266 expected_total_size_(0), | 268 expected_total_size_(0), |
| 267 amount_headers_read_(0), | 269 amount_headers_read_(0), |
| 268 amount_data_read_(0) { | 270 amount_data_read_(0) {} |
| 269 } | |
| 270 | 271 |
| 271 void Start() override { | 272 void Start() override { |
| 272 service_->storage()->LoadOrCreateGroup(manifest_url_, this); | 273 service_->storage()->LoadOrCreateGroup(manifest_url_, this); |
| 273 } | 274 } |
| 274 | 275 |
| 275 void Cancel() override { | 276 void Cancel() override { |
| 276 AppCacheHistograms::CountCheckResponseResult( | 277 AppCacheHistograms::CountCheckResponseResult( |
| 277 AppCacheHistograms::CHECK_CANCELED); | 278 AppCacheHistograms::CHECK_CANCELED); |
| 278 response_reader_.reset(); | 279 response_reader_.reset(); |
| 279 AsyncHelper::Cancel(); | 280 AsyncHelper::Cancel(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 private: | 283 private: |
| 283 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) override; | 284 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) override; |
| 284 void OnReadInfoComplete(int result); | 285 void OnReadInfoComplete(int result); |
| 285 void OnReadDataComplete(int result); | 286 void OnReadDataComplete(int result); |
| 286 | 287 |
| 287 // Inputs describing what to check. | 288 // Inputs describing what to check. |
| 288 GURL manifest_url_; | 289 GURL manifest_url_; |
| 289 int64 cache_id_; | 290 int64_t cache_id_; |
| 290 int64 response_id_; | 291 int64_t response_id_; |
| 291 | 292 |
| 292 // Internals used to perform the checks. | 293 // Internals used to perform the checks. |
| 293 const int kIOBufferSize; | 294 const int kIOBufferSize; |
| 294 scoped_refptr<AppCache> cache_; | 295 scoped_refptr<AppCache> cache_; |
| 295 scoped_ptr<AppCacheResponseReader> response_reader_; | 296 scoped_ptr<AppCacheResponseReader> response_reader_; |
| 296 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 297 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
| 297 scoped_refptr<net::IOBuffer> data_buffer_; | 298 scoped_refptr<net::IOBuffer> data_buffer_; |
| 298 int64 expected_total_size_; | 299 int64_t expected_total_size_; |
| 299 int amount_headers_read_; | 300 int amount_headers_read_; |
| 300 int amount_data_read_; | 301 int amount_data_read_; |
| 301 DISALLOW_COPY_AND_ASSIGN(CheckResponseHelper); | 302 DISALLOW_COPY_AND_ASSIGN(CheckResponseHelper); |
| 302 }; | 303 }; |
| 303 | 304 |
| 304 void AppCacheServiceImpl::CheckResponseHelper::OnGroupLoaded( | 305 void AppCacheServiceImpl::CheckResponseHelper::OnGroupLoaded( |
| 305 AppCacheGroup* group, const GURL& manifest_url) { | 306 AppCacheGroup* group, const GURL& manifest_url) { |
| 306 DCHECK_EQ(manifest_url_, manifest_url); | 307 DCHECK_EQ(manifest_url_, manifest_url); |
| 307 if (!group || !group->newest_complete_cache() || group->is_being_deleted() || | 308 if (!group || !group->newest_complete_cache() || group->is_being_deleted() || |
| 308 group->is_obsolete()) { | 309 group->is_obsolete()) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 helper->Start(); | 492 helper->Start(); |
| 492 } | 493 } |
| 493 | 494 |
| 494 void AppCacheServiceImpl::DeleteAppCachesForOrigin( | 495 void AppCacheServiceImpl::DeleteAppCachesForOrigin( |
| 495 const GURL& origin, const net::CompletionCallback& callback) { | 496 const GURL& origin, const net::CompletionCallback& callback) { |
| 496 DeleteOriginHelper* helper = new DeleteOriginHelper(this, origin, callback); | 497 DeleteOriginHelper* helper = new DeleteOriginHelper(this, origin, callback); |
| 497 helper->Start(); | 498 helper->Start(); |
| 498 } | 499 } |
| 499 | 500 |
| 500 void AppCacheServiceImpl::CheckAppCacheResponse(const GURL& manifest_url, | 501 void AppCacheServiceImpl::CheckAppCacheResponse(const GURL& manifest_url, |
| 501 int64 cache_id, | 502 int64_t cache_id, |
| 502 int64 response_id) { | 503 int64_t response_id) { |
| 503 CheckResponseHelper* helper = new CheckResponseHelper( | 504 CheckResponseHelper* helper = new CheckResponseHelper( |
| 504 this, manifest_url, cache_id, response_id); | 505 this, manifest_url, cache_id, response_id); |
| 505 helper->Start(); | 506 helper->Start(); |
| 506 } | 507 } |
| 507 | 508 |
| 508 void AppCacheServiceImpl::set_special_storage_policy( | 509 void AppCacheServiceImpl::set_special_storage_policy( |
| 509 storage::SpecialStoragePolicy* policy) { | 510 storage::SpecialStoragePolicy* policy) { |
| 510 special_storage_policy_ = policy; | 511 special_storage_policy_ = policy; |
| 511 } | 512 } |
| 512 | 513 |
| 513 void AppCacheServiceImpl::RegisterBackend( | 514 void AppCacheServiceImpl::RegisterBackend( |
| 514 AppCacheBackendImpl* backend_impl) { | 515 AppCacheBackendImpl* backend_impl) { |
| 515 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); | 516 DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); |
| 516 backends_.insert( | 517 backends_.insert( |
| 517 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 518 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
| 518 } | 519 } |
| 519 | 520 |
| 520 void AppCacheServiceImpl::UnregisterBackend( | 521 void AppCacheServiceImpl::UnregisterBackend( |
| 521 AppCacheBackendImpl* backend_impl) { | 522 AppCacheBackendImpl* backend_impl) { |
| 522 backends_.erase(backend_impl->process_id()); | 523 backends_.erase(backend_impl->process_id()); |
| 523 } | 524 } |
| 524 | 525 |
| 525 } // namespace content | 526 } // namespace content |
| OLD | NEW |