diff options
Diffstat (limited to 'net/http/http_cache.cc')
-rw-r--r-- | net/http/http_cache.cc | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 4de8080..338a323 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -34,9 +34,6 @@ using base::Time; -// Uncomment this to enable experimental byte-range support. -// #define ENABLE_RANGE_SUPPORT - namespace net { // disk cache entry data indices. @@ -170,7 +167,7 @@ HttpCache::ActiveEntry::~ActiveEntry() { class HttpCache::Transaction : public HttpTransaction, public RevocableStore::Revocable { public: - explicit Transaction(HttpCache* cache) + Transaction(HttpCache* cache, bool enable_range_support) : RevocableStore::Revocable(&cache->transactions_), request_(NULL), cache_(cache), @@ -180,6 +177,7 @@ class HttpCache::Transaction mode_(NONE), reading_(false), invalid_range_(false), + enable_range_support_(enable_range_support), read_offset_(0), effective_load_flags_(0), final_upload_progress_(0), @@ -386,6 +384,7 @@ class HttpCache::Transaction Mode mode_; bool reading_; // We are already reading. bool invalid_range_; // We may bypass the cache for this request. + bool enable_range_support_; scoped_refptr<IOBuffer> read_buf_; int read_buf_len_; int read_offset_; @@ -777,12 +776,12 @@ void HttpCache::Transaction::SetRequest(LoadLog* load_log, new_extra_headers.append(it.name_begin(), it.values_end()); new_extra_headers.append("\r\n"); } else { -#ifdef ENABLE_RANGE_SUPPORT - range_found = true; -#else - effective_load_flags_ |= LOAD_DISABLE_CACHE; - continue; -#endif + if (enable_range_support_) { + range_found = true; + } else { + effective_load_flags_ |= LOAD_DISABLE_CACHE; + continue; + } } for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSpecialHeaders); ++i) { if (HeaderMatches(it, kSpecialHeaders[i].search)) { @@ -907,9 +906,8 @@ int HttpCache::Transaction::BeginPartialCacheValidation() { if (response_.headers->response_code() != 206 && !partial_.get()) return BeginCacheValidation(); -#if !defined(ENABLE_RANGE_SUPPORT) - return BeginCacheValidation(); -#endif + if (!enable_range_support_) + return BeginCacheValidation(); bool byte_range_requested = partial_.get() != NULL; if (!byte_range_requested) { @@ -1070,11 +1068,10 @@ bool HttpCache::Transaction::RequiresValidation() { bool HttpCache::Transaction::ConditionalizeRequest() { DCHECK(response_.headers); -#if !defined(ENABLE_RANGE_SUPPORT) - // This only makes sense for cached 200 responses. - if (response_.headers->response_code() != 200) + if (!enable_range_support_ && response_.headers->response_code() != 200) { + // This only makes sense for cached 200 responses. return false; -#endif + } // This only makes sense for cached 200 or 206 responses. if (response_.headers->response_code() != 200 && @@ -1147,12 +1144,8 @@ bool HttpCache::Transaction::ConditionalizeRequest() { // course, maybe we already returned the headers. bool HttpCache::Transaction::ValidatePartialResponse( const HttpResponseHeaders* headers) { - int response_code = headers->response_code(); -#ifdef ENABLE_RANGE_SUPPORT - bool partial_content = response_code == 206; -#else - bool partial_content = false; -#endif + int response_code = headers->response_code(); + bool partial_content = enable_range_support_ ? response_code == 206 : false; if (invalid_range_) { // We gave up trying to match this request with the stored data. If the @@ -1546,6 +1539,7 @@ HttpCache::HttpCache(HostResolver* host_resolver, ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), in_memory_cache_(false), deleted_(false), + enable_range_support_(false), cache_size_(cache_size) { } @@ -1559,6 +1553,7 @@ HttpCache::HttpCache(HttpNetworkSession* session, ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), in_memory_cache_(false), deleted_(false), + enable_range_support_(false), cache_size_(cache_size) { } @@ -1573,6 +1568,7 @@ HttpCache::HttpCache(HostResolver* host_resolver, ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), in_memory_cache_(true), deleted_(false), + enable_range_support_(false), cache_size_(cache_size) { } @@ -1585,6 +1581,7 @@ HttpCache::HttpCache(HttpTransactionFactory* network_layer, ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), in_memory_cache_(false), deleted_(false), + enable_range_support_(false), cache_size_(0) { } @@ -1625,7 +1622,7 @@ HttpTransaction* HttpCache::CreateTransaction() { disk_cache_dir_.clear(); // Reclaim memory. } } - return new HttpCache::Transaction(this); + return new HttpCache::Transaction(this, enable_range_support_); } HttpCache* HttpCache::GetCache() { |