| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/http_cache_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" // For OS_POSIX | 7 #include "build/build_config.h" // For OS_POSIX |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 1966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1977 return true; | 1977 return true; |
| 1978 } | 1978 } |
| 1979 | 1979 |
| 1980 int HttpCache::Transaction::BeginCacheRead() { | 1980 int HttpCache::Transaction::BeginCacheRead() { |
| 1981 // We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges. | 1981 // We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges. |
| 1982 if (response_.headers->response_code() == 206 || partial_) { | 1982 if (response_.headers->response_code() == 206 || partial_) { |
| 1983 NOTREACHED(); | 1983 NOTREACHED(); |
| 1984 return ERR_CACHE_MISS; | 1984 return ERR_CACHE_MISS; |
| 1985 } | 1985 } |
| 1986 | 1986 |
| 1987 if (request_->method == "HEAD") | |
| 1988 FixHeadersForHead(); | |
| 1989 | |
| 1990 // We don't have the whole resource. | 1987 // We don't have the whole resource. |
| 1991 if (truncated_) | 1988 if (truncated_) |
| 1992 return ERR_CACHE_MISS; | 1989 return ERR_CACHE_MISS; |
| 1993 | 1990 |
| 1991 if (RequiresValidation() != VALIDATION_NONE) |
| 1992 return ERR_CACHE_MISS; |
| 1993 |
| 1994 if (request_->method == "HEAD") |
| 1995 FixHeadersForHead(); |
| 1996 |
| 1994 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) | 1997 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
| 1995 next_state_ = STATE_CACHE_READ_METADATA; | 1998 next_state_ = STATE_CACHE_READ_METADATA; |
| 1996 | 1999 |
| 1997 return OK; | 2000 return OK; |
| 1998 } | 2001 } |
| 1999 | 2002 |
| 2000 int HttpCache::Transaction::BeginCacheValidation() { | 2003 int HttpCache::Transaction::BeginCacheValidation() { |
| 2001 DCHECK_EQ(mode_, READ_WRITE); | 2004 DCHECK_EQ(mode_, READ_WRITE); |
| 2002 | 2005 |
| 2003 ValidationType required_validation = RequiresValidation(); | 2006 ValidationType required_validation = RequiresValidation(); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2197 // - watch out for cached responses that depend on authentication | 2200 // - watch out for cached responses that depend on authentication |
| 2198 | 2201 |
| 2199 if (response_.vary_data.is_valid() && | 2202 if (response_.vary_data.is_valid() && |
| 2200 !response_.vary_data.MatchesRequest(*request_, | 2203 !response_.vary_data.MatchesRequest(*request_, |
| 2201 *response_.headers.get())) { | 2204 *response_.headers.get())) { |
| 2202 vary_mismatch_ = true; | 2205 vary_mismatch_ = true; |
| 2203 validation_cause_ = VALIDATION_CAUSE_VARY_MISMATCH; | 2206 validation_cause_ = VALIDATION_CAUSE_VARY_MISMATCH; |
| 2204 return VALIDATION_SYNCHRONOUS; | 2207 return VALIDATION_SYNCHRONOUS; |
| 2205 } | 2208 } |
| 2206 | 2209 |
| 2207 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) | 2210 if (effective_load_flags_ & LOAD_SKIP_CACHE_VALIDATION) |
| 2208 return VALIDATION_NONE; | 2211 return VALIDATION_NONE; |
| 2209 | 2212 |
| 2210 if (response_.unused_since_prefetch && | 2213 if (response_.unused_since_prefetch && |
| 2211 !(effective_load_flags_ & LOAD_PREFETCH) && | 2214 !(effective_load_flags_ & LOAD_PREFETCH) && |
| 2212 response_.headers->GetCurrentAge( | 2215 response_.headers->GetCurrentAge( |
| 2213 response_.request_time, response_.response_time, | 2216 response_.request_time, response_.response_time, |
| 2214 cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { | 2217 cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { |
| 2215 // The first use of a resource after prefetch within a short window skips | 2218 // The first use of a resource after prefetch within a short window skips |
| 2216 // validation. | 2219 // validation. |
| 2217 return VALIDATION_NONE; | 2220 return VALIDATION_NONE; |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2939 default: | 2942 default: |
| 2940 NOTREACHED(); | 2943 NOTREACHED(); |
| 2941 } | 2944 } |
| 2942 } | 2945 } |
| 2943 | 2946 |
| 2944 void HttpCache::Transaction::OnIOComplete(int result) { | 2947 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2945 DoLoop(result); | 2948 DoLoop(result); |
| 2946 } | 2949 } |
| 2947 | 2950 |
| 2948 } // namespace net | 2951 } // namespace net |
| OLD | NEW |