| 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/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_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" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "content/browser/cache_storage/cache_storage.pb.h" | 14 #include "content/browser/cache_storage/cache_storage.pb.h" |
| 15 #include "content/browser/cache_storage/cache_storage_scheduler.h" | 15 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/common/referrer.h" | 17 #include "content/public/common/referrer.h" |
| 18 #include "net/base/completion_callback.h" |
| 18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/disk_cache/disk_cache.h" | 21 #include "net/disk_cache/disk_cache.h" |
| 21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
| 22 #include "storage/browser/blob/blob_data_builder.h" | 23 #include "storage/browser/blob/blob_data_builder.h" |
| 23 #include "storage/browser/blob/blob_data_handle.h" | 24 #include "storage/browser/blob/blob_data_handle.h" |
| 24 #include "storage/browser/blob/blob_storage_context.h" | 25 #include "storage/browser/blob/blob_storage_context.h" |
| 25 #include "storage/browser/blob/blob_url_request_job_factory.h" | 26 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 26 #include "storage/browser/quota/quota_manager_proxy.h" | 27 #include "storage/browser/quota/quota_manager_proxy.h" |
| 27 #include "third_party/WebKit/public/platform/WebServiceWorkerResponseType.h" | 28 #include "third_party/WebKit/public/platform/WebServiceWorkerResponseType.h" |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 typedef base::Callback<void(bool)> BoolCallback; | |
| 34 typedef base::Callback<void(disk_cache::ScopedEntryPtr, bool)> | 34 typedef base::Callback<void(disk_cache::ScopedEntryPtr, bool)> |
| 35 EntryBoolCallback; | 35 EntryBoolCallback; |
| 36 typedef base::Callback<void(scoped_ptr<CacheMetadata>)> MetadataCallback; | 36 typedef base::Callback<void(scoped_ptr<CacheMetadata>)> MetadataCallback; |
| 37 | 37 |
| 38 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY }; | 38 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY }; |
| 39 | 39 |
| 40 // The maximum size of an individual cache. Ultimately cache size is controlled | 40 // The maximum size of an individual cache. Ultimately cache size is controlled |
| 41 // per-origin. | 41 // per-origin. |
| 42 const int kMaxCacheBytes = 512 * 1024 * 1024; | 42 const int kMaxCacheBytes = 512 * 1024 * 1024; |
| 43 | 43 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 int cache_entry_offset_; | 266 int cache_entry_offset_; |
| 267 disk_cache::ScopedEntryPtr entry_; | 267 disk_cache::ScopedEntryPtr entry_; |
| 268 scoped_ptr<net::URLRequest> blob_request_; | 268 scoped_ptr<net::URLRequest> blob_request_; |
| 269 EntryAndBoolCallback callback_; | 269 EntryAndBoolCallback callback_; |
| 270 scoped_refptr<net::IOBufferWithSize> buffer_; | 270 scoped_refptr<net::IOBufferWithSize> buffer_; |
| 271 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; | 271 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 // The state needed to pass between CacheStorageCache::Keys callbacks. | 274 // The state needed to pass between CacheStorageCache::Keys callbacks. |
| 275 struct CacheStorageCache::KeysContext { | 275 struct CacheStorageCache::KeysContext { |
| 276 KeysContext(const CacheStorageCache::RequestsCallback& callback) | 276 explicit KeysContext(const CacheStorageCache::RequestsCallback& callback) |
| 277 : original_callback(callback), | 277 : original_callback(callback), |
| 278 out_keys(new CacheStorageCache::Requests()), | 278 out_keys(new CacheStorageCache::Requests()), |
| 279 enumerated_entry(NULL) {} | 279 enumerated_entry(NULL) {} |
| 280 | 280 |
| 281 ~KeysContext() { | 281 ~KeysContext() { |
| 282 for (size_t i = 0, max = entries.size(); i < max; ++i) | 282 for (size_t i = 0, max = entries.size(); i < max; ++i) |
| 283 entries[i]->Close(); | 283 entries[i]->Close(); |
| 284 if (enumerated_entry) | 284 if (enumerated_entry) |
| 285 enumerated_entry->Close(); | 285 enumerated_entry->Close(); |
| 286 } | 286 } |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 ErrorType error, | 1219 ErrorType error, |
| 1220 scoped_ptr<Requests> requests) { | 1220 scoped_ptr<Requests> requests) { |
| 1221 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1221 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); |
| 1222 | 1222 |
| 1223 callback.Run(error, requests.Pass()); | 1223 callback.Run(error, requests.Pass()); |
| 1224 if (cache) | 1224 if (cache) |
| 1225 scheduler_->CompleteOperationAndRunNext(); | 1225 scheduler_->CompleteOperationAndRunNext(); |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 } // namespace content | 1228 } // namespace content |
| OLD | NEW |