Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 1008723006: Remove HTTP cache Record/Playback support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_cache.cc ('k') | tools/valgrind/gtest_exclude/browser_tests.gtest-memcheck.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 mode_ = WRITE; 1414 mode_ = WRITE;
1415 next_state_ = STATE_CREATE_ENTRY; 1415 next_state_ = STATE_CREATE_ENTRY;
1416 return OK; 1416 return OK;
1417 } 1417 }
1418 if (mode_ == UPDATE) { 1418 if (mode_ == UPDATE) {
1419 // There is no cache entry to update; proceed without caching. 1419 // There is no cache entry to update; proceed without caching.
1420 mode_ = NONE; 1420 mode_ = NONE;
1421 next_state_ = STATE_SEND_REQUEST; 1421 next_state_ = STATE_SEND_REQUEST;
1422 return OK; 1422 return OK;
1423 } 1423 }
1424 if (cache_->mode() == PLAYBACK)
1425 DVLOG(1) << "Playback Cache Miss: " << request_->url;
1426 1424
1427 // The entry does not exist, and we are not permitted to create a new entry, 1425 // The entry does not exist, and we are not permitted to create a new entry,
1428 // so we must fail. 1426 // so we must fail.
1429 return ERR_CACHE_MISS; 1427 return ERR_CACHE_MISS;
1430 } 1428 }
1431 1429
1432 int HttpCache::Transaction::DoCreateEntry() { 1430 int HttpCache::Transaction::DoCreateEntry() {
1433 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 1431 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
1434 tracked_objects::ScopedTracker tracking_profile( 1432 tracked_objects::ScopedTracker tracking_profile(
1435 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1433 FROM_HERE_WITH_EXPLICIT_FUNCTION(
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 } 2248 }
2251 DCHECK_EQ(0, dist_from_root); 2249 DCHECK_EQ(0, dist_from_root);
2252 } 2250 }
2253 2251
2254 void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log, 2252 void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log,
2255 const HttpRequestInfo* request) { 2253 const HttpRequestInfo* request) {
2256 net_log_ = net_log; 2254 net_log_ = net_log;
2257 request_ = request; 2255 request_ = request;
2258 effective_load_flags_ = request_->load_flags; 2256 effective_load_flags_ = request_->load_flags;
2259 2257
2260 switch (cache_->mode()) { 2258 if (cache_->mode() == DISABLE)
2261 case NORMAL: 2259 effective_load_flags_ |= LOAD_DISABLE_CACHE;
2262 break;
2263 case RECORD:
2264 // When in record mode, we want to NEVER load from the cache.
2265 // The reason for this is because we save the Set-Cookie headers
2266 // (intentionally). If we read from the cache, we replay them
2267 // prematurely.
2268 effective_load_flags_ |= LOAD_BYPASS_CACHE;
2269 break;
2270 case PLAYBACK:
2271 // When in playback mode, we want to load exclusively from the cache.
2272 effective_load_flags_ |= LOAD_ONLY_FROM_CACHE;
2273 break;
2274 case DISABLE:
2275 effective_load_flags_ |= LOAD_DISABLE_CACHE;
2276 break;
2277 }
2278 2260
2279 // Some headers imply load flags. The order here is significant. 2261 // Some headers imply load flags. The order here is significant.
2280 // 2262 //
2281 // LOAD_DISABLE_CACHE : no cache read or write 2263 // LOAD_DISABLE_CACHE : no cache read or write
2282 // LOAD_BYPASS_CACHE : no cache read 2264 // LOAD_BYPASS_CACHE : no cache read
2283 // LOAD_VALIDATE_CACHE : no cache read unless validation 2265 // LOAD_VALIDATE_CACHE : no cache read unless validation
2284 // 2266 //
2285 // The former modes trump latter modes, so if we find a matching header we 2267 // The former modes trump latter modes, so if we find a matching header we
2286 // can stop iterating kSpecialHeaders. 2268 // can stop iterating kSpecialHeaders.
2287 // 2269 //
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 } 2348 }
2367 } 2349 }
2368 } 2350 }
2369 2351
2370 bool HttpCache::Transaction::ShouldPassThrough() { 2352 bool HttpCache::Transaction::ShouldPassThrough() {
2371 // We may have a null disk_cache if there is an error we cannot recover from, 2353 // We may have a null disk_cache if there is an error we cannot recover from,
2372 // like not enough disk space, or sharing violations. 2354 // like not enough disk space, or sharing violations.
2373 if (!cache_->disk_cache_.get()) 2355 if (!cache_->disk_cache_.get())
2374 return true; 2356 return true;
2375 2357
2376 // When using the record/playback modes, we always use the cache
2377 // and we never pass through.
2378 if (cache_->mode() == RECORD || cache_->mode() == PLAYBACK)
2379 return false;
2380
2381 if (effective_load_flags_ & LOAD_DISABLE_CACHE) 2358 if (effective_load_flags_ & LOAD_DISABLE_CACHE)
2382 return true; 2359 return true;
2383 2360
2384 if (request_->method == "GET" || request_->method == "HEAD") 2361 if (request_->method == "GET" || request_->method == "HEAD")
2385 return false; 2362 return false;
2386 2363
2387 if (request_->method == "POST" && request_->upload_data_stream && 2364 if (request_->method == "POST" && request_->upload_data_stream &&
2388 request_->upload_data_stream->identifier()) { 2365 request_->upload_data_stream->identifier()) {
2389 return false; 2366 return false;
2390 } 2367 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 if (rv != ERR_IO_PENDING) 2591 if (rv != ERR_IO_PENDING)
2615 return DoLoop(rv); 2592 return DoLoop(rv);
2616 return rv; 2593 return rv;
2617 } 2594 }
2618 2595
2619 ValidationType HttpCache::Transaction::RequiresValidation() { 2596 ValidationType HttpCache::Transaction::RequiresValidation() {
2620 // TODO(darin): need to do more work here: 2597 // TODO(darin): need to do more work here:
2621 // - make sure we have a matching request method 2598 // - make sure we have a matching request method
2622 // - watch out for cached responses that depend on authentication 2599 // - watch out for cached responses that depend on authentication
2623 2600
2624 // In playback mode, nothing requires validation.
2625 if (cache_->mode() == net::HttpCache::PLAYBACK)
2626 return VALIDATION_NONE;
2627
2628 if (response_.vary_data.is_valid() && 2601 if (response_.vary_data.is_valid() &&
2629 !response_.vary_data.MatchesRequest(*request_, 2602 !response_.vary_data.MatchesRequest(*request_,
2630 *response_.headers.get())) { 2603 *response_.headers.get())) {
2631 vary_mismatch_ = true; 2604 vary_mismatch_ = true;
2632 return VALIDATION_SYNCHRONOUS; 2605 return VALIDATION_SYNCHRONOUS;
2633 } 2606 }
2634 2607
2635 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) 2608 if (effective_load_flags_ & LOAD_PREFERRING_CACHE)
2636 return VALIDATION_NONE; 2609 return VALIDATION_NONE;
2637 2610
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback); 2952 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback);
2980 } 2953 }
2981 return rv; 2954 return rv;
2982 } 2955 }
2983 2956
2984 int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { 2957 int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) {
2985 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; 2958 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE;
2986 if (!entry_) 2959 if (!entry_)
2987 return OK; 2960 return OK;
2988 2961
2989 // Do not cache no-store content (unless we are record mode). Do not cache 2962 // Do not cache no-store content. Do not cache content with cert errors
2990 // content with cert errors either. This is to prevent not reporting net 2963 // either. This is to prevent not reporting net errors when loading a
2991 // errors when loading a resource from the cache. When we load a page over 2964 // resource from the cache. When we load a page over HTTPS with a cert error
2992 // HTTPS with a cert error we show an SSL blocking page. If the user clicks 2965 // we show an SSL blocking page. If the user clicks proceed we reload the
2993 // proceed we reload the resource ignoring the errors. The loaded resource 2966 // resource ignoring the errors. The loaded resource is then cached. If that
2994 // is then cached. If that resource is subsequently loaded from the cache, 2967 // resource is subsequently loaded from the cache, no net error is reported
2995 // no net error is reported (even though the cert status contains the actual 2968 // (even though the cert status contains the actual errors) and no SSL
2996 // errors) and no SSL blocking page is shown. An alternative would be to 2969 // blocking page is shown. An alternative would be to reverse-map the cert
2997 // reverse-map the cert status to a net error and replay the net error. 2970 // status to a net error and replay the net error.
2998 if ((cache_->mode() != RECORD && 2971 if ((response_.headers->HasHeaderValue("cache-control", "no-store")) ||
2999 response_.headers->HasHeaderValue("cache-control", "no-store")) ||
3000 net::IsCertStatusError(response_.ssl_info.cert_status)) { 2972 net::IsCertStatusError(response_.ssl_info.cert_status)) {
3001 DoneWritingToEntry(false); 2973 DoneWritingToEntry(false);
3002 if (net_log_.IsLogging()) 2974 if (net_log_.IsLogging())
3003 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 2975 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO);
3004 return OK; 2976 return OK;
3005 } 2977 }
3006 2978
3007 // cert_cache() will be null if the CertCacheTrial field trial is disabled. 2979 // cert_cache() will be null if the CertCacheTrial field trial is disabled.
3008 if (cache_->cert_cache() && response_.ssl_info.is_valid()) 2980 if (cache_->cert_cache() && response_.ssl_info.is_valid())
3009 WriteCertChain(); 2981 WriteCertChain();
3010 2982
3011 // When writing headers, we normally only write the non-transient
3012 // headers; when in record mode, record everything.
3013 bool skip_transient_headers = (cache_->mode() != RECORD);
3014
3015 if (truncated) 2983 if (truncated)
3016 DCHECK_EQ(200, response_.headers->response_code()); 2984 DCHECK_EQ(200, response_.headers->response_code());
3017 2985
2986 // When writing headers, we normally only write the non-transient headers.
2987 bool skip_transient_headers = true;
3018 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer()); 2988 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer());
3019 response_.Persist(data->pickle(), skip_transient_headers, truncated); 2989 response_.Persist(data->pickle(), skip_transient_headers, truncated);
3020 data->Done(); 2990 data->Done();
3021 2991
3022 io_buf_len_ = data->pickle()->size(); 2992 io_buf_len_ = data->pickle()->size();
3023 return entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data.get(), 2993 return entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data.get(),
3024 io_buf_len_, io_callback_, true); 2994 io_buf_len_, io_callback_, true);
3025 } 2995 }
3026 2996
3027 int HttpCache::Transaction::AppendResponseDataToEntry( 2997 int HttpCache::Transaction::AppendResponseDataToEntry(
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
3279 3249
3280 void HttpCache::Transaction::OnIOComplete(int result) { 3250 void HttpCache::Transaction::OnIOComplete(int result) {
3281 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 3251 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
3282 tracked_objects::ScopedTracker tracking_profile( 3252 tracked_objects::ScopedTracker tracking_profile(
3283 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); 3253 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete"));
3284 3254
3285 DoLoop(result); 3255 DoLoop(result);
3286 } 3256 }
3287 3257
3288 } // namespace net 3258 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | tools/valgrind/gtest_exclude/browser_tests.gtest-memcheck.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698