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

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

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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_transaction.h ('k') | net/http/http_cache_unittest.cc » ('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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 while (v.GetNext()) { 300 while (v.GetNext()) {
301 if (LowerCaseEqualsASCII(v.value_begin(), v.value_end(), search->value)) 301 if (LowerCaseEqualsASCII(v.value_begin(), v.value_end(), search->value))
302 return true; 302 return true;
303 } 303 }
304 } 304 }
305 return false; 305 return false;
306 } 306 }
307 307
308 //----------------------------------------------------------------------------- 308 //-----------------------------------------------------------------------------
309 309
310 HttpCache::Transaction::Transaction( 310 HttpCache::Transaction::Transaction(RequestPriority priority, HttpCache* cache)
311 RequestPriority priority,
312 HttpCache* cache)
313 : next_state_(STATE_NONE), 311 : next_state_(STATE_NONE),
314 request_(NULL), 312 request_(NULL),
315 priority_(priority), 313 priority_(priority),
316 cache_(cache->GetWeakPtr()), 314 cache_(cache->GetWeakPtr()),
317 entry_(NULL), 315 entry_(NULL),
318 new_entry_(NULL), 316 new_entry_(NULL),
319 new_response_(NULL), 317 new_response_(NULL),
320 mode_(NONE), 318 mode_(NONE),
321 target_state_(STATE_NONE), 319 target_state_(STATE_NONE),
322 reading_(false), 320 reading_(false),
323 invalid_range_(false), 321 invalid_range_(false),
324 truncated_(false), 322 truncated_(false),
325 is_sparse_(false), 323 is_sparse_(false),
326 range_requested_(false), 324 range_requested_(false),
327 handling_206_(false), 325 handling_206_(false),
328 cache_pending_(false), 326 cache_pending_(false),
329 done_reading_(false), 327 done_reading_(false),
330 vary_mismatch_(false), 328 vary_mismatch_(false),
331 couldnt_conditionalize_request_(false), 329 couldnt_conditionalize_request_(false),
332 bypass_lock_for_test_(false), 330 bypass_lock_for_test_(false),
331 fail_conditionalization_for_test_(false),
333 io_buf_len_(0), 332 io_buf_len_(0),
334 read_offset_(0), 333 read_offset_(0),
335 effective_load_flags_(0), 334 effective_load_flags_(0),
336 write_len_(0), 335 write_len_(0),
337 transaction_pattern_(PATTERN_UNDEFINED), 336 transaction_pattern_(PATTERN_UNDEFINED),
338 total_received_bytes_(0), 337 total_received_bytes_(0),
339 websocket_handshake_stream_base_create_helper_(NULL), 338 websocket_handshake_stream_base_create_helper_(NULL),
340 weak_factory_(this) { 339 weak_factory_(this) {
341 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == 340 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders ==
342 arraysize(kValidationHeaders), 341 arraysize(kValidationHeaders),
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 partial_.reset(); 1211 partial_.reset();
1213 } 1212 }
1214 1213
1215 new_response_ = new_response; 1214 new_response_ = new_response;
1216 if (authentication_failure || 1215 if (authentication_failure ||
1217 (!ValidatePartialResponse() && !auth_response_.headers.get())) { 1216 (!ValidatePartialResponse() && !auth_response_.headers.get())) {
1218 // Something went wrong with this request and we have to restart it. 1217 // Something went wrong with this request and we have to restart it.
1219 // If we have an authentication response, we are exposed to weird things 1218 // If we have an authentication response, we are exposed to weird things
1220 // hapenning if the user cancels the authentication before we receive 1219 // hapenning if the user cancels the authentication before we receive
1221 // the new response. 1220 // the new response.
1221 net_log_.AddEvent(NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST);
1222 UpdateTransactionPattern(PATTERN_NOT_COVERED); 1222 UpdateTransactionPattern(PATTERN_NOT_COVERED);
1223 response_ = HttpResponseInfo(); 1223 response_ = HttpResponseInfo();
1224 ResetNetworkTransaction(); 1224 ResetNetworkTransaction();
1225 new_response_ = NULL; 1225 new_response_ = NULL;
1226 next_state_ = STATE_SEND_REQUEST; 1226 next_state_ = STATE_SEND_REQUEST;
1227 return OK; 1227 return OK;
1228 } 1228 }
1229 1229
1230 if (handling_206_ && mode_ == READ_WRITE && !truncated_ && !is_sparse_) { 1230 if (handling_206_ && mode_ == READ_WRITE && !truncated_ && !is_sparse_) {
1231 // We have stored the full entry, but it changed and the server is 1231 // We have stored the full entry, but it changed and the server is
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 response_ = *new_response_; 1703 response_ = *new_response_;
1704 1704
1705 if (request_->method == "HEAD") { 1705 if (request_->method == "HEAD") {
1706 // This response is replacing the cached one. 1706 // This response is replacing the cached one.
1707 DoneWritingToEntry(false); 1707 DoneWritingToEntry(false);
1708 mode_ = NONE; 1708 mode_ = NONE;
1709 new_response_ = NULL; 1709 new_response_ = NULL;
1710 return OK; 1710 return OK;
1711 } 1711 }
1712 1712
1713 if (handling_206_ && !CanResume(false)) {
1714 // There is no point in storing this resource because it will never be used.
1715 // This may change if we support LOAD_ONLY_FROM_CACHE with sparse entries.
1716 DoneWritingToEntry(false);
1717 if (partial_.get())
1718 partial_->FixResponseHeaders(response_.headers.get(), true);
1719 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
1720 return OK;
1721 }
1722
1713 target_state_ = STATE_TRUNCATE_CACHED_DATA; 1723 target_state_ = STATE_TRUNCATE_CACHED_DATA;
1714 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : 1724 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE :
1715 STATE_CACHE_WRITE_RESPONSE; 1725 STATE_CACHE_WRITE_RESPONSE;
1716 return OK; 1726 return OK;
1717 } 1727 }
1718 1728
1719 int HttpCache::Transaction::DoTruncateCachedData() { 1729 int HttpCache::Transaction::DoTruncateCachedData() {
1720 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 1730 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
1721 tracked_objects::ScopedTracker tracking_profile( 1731 tracked_objects::ScopedTracker tracking_profile(
1722 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1732 FROM_HERE_WITH_EXPLICIT_FUNCTION(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; 1979 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE;
1970 return entry_->disk_entry->ReadyForSparseIO(io_callback_); 1980 return entry_->disk_entry->ReadyForSparseIO(io_callback_);
1971 } 1981 }
1972 1982
1973 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { 1983 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) {
1974 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 1984 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
1975 tracked_objects::ScopedTracker tracking_profile( 1985 tracked_objects::ScopedTracker tracking_profile(
1976 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1986 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1977 "422516 HttpCache::Transaction::DoCacheQueryDataComplete")); 1987 "422516 HttpCache::Transaction::DoCacheQueryDataComplete"));
1978 1988
1979 if (result == ERR_NOT_IMPLEMENTED) {
1980 // Restart the request overwriting the cache entry.
1981 // TODO(pasko): remove this workaround as soon as the SimpleBackendImpl
1982 // supports Sparse IO.
1983 return DoRestartPartialRequest();
1984 }
1985 DCHECK_EQ(OK, result); 1989 DCHECK_EQ(OK, result);
1986 if (!cache_.get()) 1990 if (!cache_.get())
1987 return ERR_UNEXPECTED; 1991 return ERR_UNEXPECTED;
1988 1992
1989 return ValidateEntryHeadersAndContinue(); 1993 return ValidateEntryHeadersAndContinue();
1990 } 1994 }
1991 1995
1992 int HttpCache::Transaction::DoCacheReadData() { 1996 int HttpCache::Transaction::DoCacheReadData() {
1993 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 1997 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
1994 tracked_objects::ScopedTracker tracking_profile( 1998 tracked_objects::ScopedTracker tracking_profile(
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 const HeaderNameAndValue* search; 2208 const HeaderNameAndValue* search;
2205 int load_flag; 2209 int load_flag;
2206 } kSpecialHeaders[] = { 2210 } kSpecialHeaders[] = {
2207 { kPassThroughHeaders, LOAD_DISABLE_CACHE }, 2211 { kPassThroughHeaders, LOAD_DISABLE_CACHE },
2208 { kForceFetchHeaders, LOAD_BYPASS_CACHE }, 2212 { kForceFetchHeaders, LOAD_BYPASS_CACHE },
2209 { kForceValidateHeaders, LOAD_VALIDATE_CACHE }, 2213 { kForceValidateHeaders, LOAD_VALIDATE_CACHE },
2210 }; 2214 };
2211 2215
2212 bool range_found = false; 2216 bool range_found = false;
2213 bool external_validation_error = false; 2217 bool external_validation_error = false;
2218 bool special_headers = false;
2214 2219
2215 if (request_->extra_headers.HasHeader(HttpRequestHeaders::kRange)) 2220 if (request_->extra_headers.HasHeader(HttpRequestHeaders::kRange))
2216 range_found = true; 2221 range_found = true;
2217 2222
2218 for (size_t i = 0; i < arraysize(kSpecialHeaders); ++i) { 2223 for (size_t i = 0; i < arraysize(kSpecialHeaders); ++i) {
2219 if (HeaderMatches(request_->extra_headers, kSpecialHeaders[i].search)) { 2224 if (HeaderMatches(request_->extra_headers, kSpecialHeaders[i].search)) {
2220 effective_load_flags_ |= kSpecialHeaders[i].load_flag; 2225 effective_load_flags_ |= kSpecialHeaders[i].load_flag;
2226 special_headers = true;
2221 break; 2227 break;
2222 } 2228 }
2223 } 2229 }
2224 2230
2225 // Check for conditionalization headers which may correspond with a 2231 // Check for conditionalization headers which may correspond with a
2226 // cache validation request. 2232 // cache validation request.
2227 for (size_t i = 0; i < arraysize(kValidationHeaders); ++i) { 2233 for (size_t i = 0; i < arraysize(kValidationHeaders); ++i) {
2228 const ValidationHeaderInfo& info = kValidationHeaders[i]; 2234 const ValidationHeaderInfo& info = kValidationHeaders[i];
2229 std::string validation_value; 2235 std::string validation_value;
2230 if (request_->extra_headers.GetHeader( 2236 if (request_->extra_headers.GetHeader(
2231 info.request_header_name, &validation_value)) { 2237 info.request_header_name, &validation_value)) {
2232 if (!external_validation_.values[i].empty() || 2238 if (!external_validation_.values[i].empty() ||
2233 validation_value.empty()) { 2239 validation_value.empty()) {
2234 external_validation_error = true; 2240 external_validation_error = true;
2235 } 2241 }
2236 external_validation_.values[i] = validation_value; 2242 external_validation_.values[i] = validation_value;
2237 external_validation_.initialized = true; 2243 external_validation_.initialized = true;
2238 } 2244 }
2239 } 2245 }
2240 2246
2247 if (range_found || special_headers || external_validation_.initialized) {
2248 // Log the headers before request_ is modified.
2249 std::string empty;
2250 net_log_.AddEvent(
2251 NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS,
2252 base::Bind(&HttpRequestHeaders::NetLogCallback,
2253 base::Unretained(&request_->extra_headers), &empty));
2254 }
2255
2241 // We don't support ranges and validation headers. 2256 // We don't support ranges and validation headers.
2242 if (range_found && external_validation_.initialized) { 2257 if (range_found && external_validation_.initialized) {
2243 LOG(WARNING) << "Byte ranges AND validation headers found."; 2258 LOG(WARNING) << "Byte ranges AND validation headers found.";
2244 effective_load_flags_ |= LOAD_DISABLE_CACHE; 2259 effective_load_flags_ |= LOAD_DISABLE_CACHE;
2245 } 2260 }
2246 2261
2247 // If there is more than one validation header, we can't treat this request as 2262 // If there is more than one validation header, we can't treat this request as
2248 // a cache validation, since we don't know for sure which header the server 2263 // a cache validation, since we don't know for sure which header the server
2249 // will give us a response for (and they could be contradictory). 2264 // will give us a response for (and they could be contradictory).
2250 if (external_validation_error) { 2265 if (external_validation_error) {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 2578
2564 if (request_->method == "PUT" || request_->method == "DELETE") 2579 if (request_->method == "PUT" || request_->method == "DELETE")
2565 return false; 2580 return false;
2566 2581
2567 // This only makes sense for cached 200 or 206 responses. 2582 // This only makes sense for cached 200 or 206 responses.
2568 if (response_.headers->response_code() != 200 && 2583 if (response_.headers->response_code() != 200 &&
2569 response_.headers->response_code() != 206) { 2584 response_.headers->response_code() != 206) {
2570 return false; 2585 return false;
2571 } 2586 }
2572 2587
2573 if (response_.headers->response_code() == 206 && 2588 if (fail_conditionalization_for_test_)
2574 !response_.headers->HasStrongValidators()) {
2575 return false; 2589 return false;
2576 } 2590
2591 DCHECK(response_.headers->response_code() != 206 ||
2592 response_.headers->HasStrongValidators());
2577 2593
2578 // Just use the first available ETag and/or Last-Modified header value. 2594 // Just use the first available ETag and/or Last-Modified header value.
2579 // TODO(darin): Or should we use the last? 2595 // TODO(darin): Or should we use the last?
2580 2596
2581 std::string etag_value; 2597 std::string etag_value;
2582 if (response_.headers->GetHttpVersion() >= HttpVersion(1, 1)) 2598 if (response_.headers->GetHttpVersion() >= HttpVersion(1, 1))
2583 response_.headers->EnumerateHeader(NULL, "etag", &etag_value); 2599 response_.headers->EnumerateHeader(NULL, "etag", &etag_value);
2584 2600
2585 std::string last_modified_value; 2601 std::string last_modified_value;
2586 if (!vary_mismatch_) { 2602 if (!vary_mismatch_) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 2721
2706 if (partial_->IsCurrentRangeCached()) { 2722 if (partial_->IsCurrentRangeCached()) {
2707 // We asked for "If-None-Match: " so a 206 means a new object. 2723 // We asked for "If-None-Match: " so a 206 means a new object.
2708 if (partial_response) 2724 if (partial_response)
2709 failure = true; 2725 failure = true;
2710 2726
2711 if (response_code == 304 && partial_->ResponseHeadersOK(headers)) 2727 if (response_code == 304 && partial_->ResponseHeadersOK(headers))
2712 return true; 2728 return true;
2713 } else { 2729 } else {
2714 // We asked for "If-Range: " so a 206 means just another range. 2730 // We asked for "If-Range: " so a 206 means just another range.
2715 if (partial_response && partial_->ResponseHeadersOK(headers)) { 2731 if (partial_response) {
2716 handling_206_ = true; 2732 if (partial_->ResponseHeadersOK(headers)) {
2717 return true; 2733 handling_206_ = true;
2734 return true;
2735 } else {
2736 failure = true;
2737 }
2718 } 2738 }
2719 2739
2720 if (!reading_ && !is_sparse_ && !partial_response) { 2740 if (!reading_ && !is_sparse_ && !partial_response) {
2721 // See if we can ignore the fact that we issued a byte range request. 2741 // See if we can ignore the fact that we issued a byte range request.
2722 // If the server sends 200, just store it. If it sends an error, redirect 2742 // If the server sends 200, just store it. If it sends an error, redirect
2723 // or something else, we may store the response as long as we didn't have 2743 // or something else, we may store the response as long as we didn't have
2724 // anything already stored. 2744 // anything already stored.
2725 if (response_code == 200 || 2745 if (response_code == 200 ||
2726 (!truncated_ && response_code != 304 && response_code != 416)) { 2746 (!truncated_ && response_code != 304 && response_code != 416)) {
2727 // The server is sending something else, and we can save it. 2747 // The server is sending something else, and we can save it.
2728 DCHECK((truncated_ && !partial_->IsLastRange()) || range_requested_); 2748 DCHECK((truncated_ && !partial_->IsLastRange()) || range_requested_);
2729 partial_.reset(); 2749 partial_.reset();
2730 truncated_ = false; 2750 truncated_ = false;
2731 return true; 2751 return true;
2732 } 2752 }
2733 } 2753 }
2734 2754
2735 // 304 is not expected here, but we'll spare the entry (unless it was 2755 // 304 is not expected here, but we'll spare the entry (unless it was
2736 // truncated). 2756 // truncated).
2737 if (truncated_) 2757 if (truncated_)
2738 failure = true; 2758 failure = true;
2739 } 2759 }
2740 2760
2741 if (failure) { 2761 if (failure) {
2742 // We cannot truncate this entry, it has to be deleted. 2762 // We cannot truncate this entry, it has to be deleted.
2743 UpdateTransactionPattern(PATTERN_NOT_COVERED); 2763 UpdateTransactionPattern(PATTERN_NOT_COVERED);
2744 DoomPartialEntry(false);
2745 mode_ = NONE; 2764 mode_ = NONE;
2746 if (!reading_ && !partial_->IsLastRange()) { 2765 if (is_sparse_ || truncated_) {
2747 // We'll attempt to issue another network request, this time without us 2766 // There was something cached to start with, either sparsed data (206), or
2748 // messing up the headers. 2767 // a truncated 200, which means that we probably modified the request,
2749 partial_->RestoreHeaders(&custom_request_->extra_headers); 2768 // adding a byte range or modifying the range requested by the caller.
2750 partial_.reset(); 2769 if (!reading_ && !partial_->IsLastRange()) {
2751 truncated_ = false; 2770 // We have not returned anything to the caller yet so it should be safe
2752 return false; 2771 // to issue another network request, this time without us messing up the
2772 // headers.
2773 ResetPartialState(true);
2774 return false;
2775 }
2776 LOG(WARNING) << "Failed to revalidate partial entry";
2753 } 2777 }
2754 LOG(WARNING) << "Failed to revalidate partial entry"; 2778 DoomPartialEntry(true);
2755 partial_.reset();
2756 return true; 2779 return true;
2757 } 2780 }
2758 2781
2759 IgnoreRangeRequest(); 2782 IgnoreRangeRequest();
2760 return true; 2783 return true;
2761 } 2784 }
2762 2785
2763 void HttpCache::Transaction::IgnoreRangeRequest() { 2786 void HttpCache::Transaction::IgnoreRangeRequest() {
2764 // We have a problem. We may or may not be reading already (in which case we 2787 // We have a problem. We may or may not be reading already (in which case we
2765 // returned the headers), but we'll just pretend that this request is not 2788 // returned the headers), but we'll just pretend that this request is not
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2972 OnIOComplete(ERR_CACHE_LOCK_TIMEOUT); 2995 OnIOComplete(ERR_CACHE_LOCK_TIMEOUT);
2973 } 2996 }
2974 2997
2975 void HttpCache::Transaction::DoomPartialEntry(bool delete_object) { 2998 void HttpCache::Transaction::DoomPartialEntry(bool delete_object) {
2976 DVLOG(2) << "DoomPartialEntry"; 2999 DVLOG(2) << "DoomPartialEntry";
2977 int rv = cache_->DoomEntry(cache_key_, NULL); 3000 int rv = cache_->DoomEntry(cache_key_, NULL);
2978 DCHECK_EQ(OK, rv); 3001 DCHECK_EQ(OK, rv);
2979 cache_->DoneWithEntry(entry_, this, false); 3002 cache_->DoneWithEntry(entry_, this, false);
2980 entry_ = NULL; 3003 entry_ = NULL;
2981 is_sparse_ = false; 3004 is_sparse_ = false;
3005 truncated_ = false;
2982 if (delete_object) 3006 if (delete_object)
2983 partial_.reset(NULL); 3007 partial_.reset(NULL);
2984 } 3008 }
2985 3009
2986 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) { 3010 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) {
2987 partial_->OnNetworkReadCompleted(result); 3011 partial_->OnNetworkReadCompleted(result);
2988 3012
2989 if (result == 0) { 3013 if (result == 0) {
2990 // We need to move on to the next range. 3014 // We need to move on to the next range.
2991 ResetNetworkTransaction(); 3015 ResetNetworkTransaction();
2992 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 3016 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
2993 } 3017 }
2994 return result; 3018 return result;
2995 } 3019 }
2996 3020
2997 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { 3021 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) {
2998 partial_->OnCacheReadCompleted(result); 3022 partial_->OnCacheReadCompleted(result);
2999 3023
3000 if (result == 0 && mode_ == READ_WRITE) { 3024 if (result == 0 && mode_ == READ_WRITE) {
3001 // We need to move on to the next range. 3025 // We need to move on to the next range.
3002 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 3026 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
3003 } else if (result < 0) { 3027 } else if (result < 0) {
3004 return OnCacheReadError(result, false); 3028 return OnCacheReadError(result, false);
3005 } 3029 }
3006 return result; 3030 return result;
3007 } 3031 }
3008 3032
3009 int HttpCache::Transaction::DoRestartPartialRequest() { 3033 int HttpCache::Transaction::DoRestartPartialRequest() {
3010 // The stored data cannot be used. Get rid of it and restart this request. 3034 // The stored data cannot be used. Get rid of it and restart this request.
3011 // We need to also reset the |truncated_| flag as a new entry is created. 3035 net_log_.AddEvent(NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST);
3012 DoomPartialEntry(!range_requested_); 3036
3037 // WRITE + Doom + STATE_INIT_ENTRY == STATE_CREATE_ENTRY (without an attempt
3038 // to Doom the entry again).
3013 mode_ = WRITE; 3039 mode_ = WRITE;
3014 truncated_ = false; 3040 ResetPartialState(!range_requested_);
3015 next_state_ = STATE_INIT_ENTRY; 3041 next_state_ = STATE_CREATE_ENTRY;
3016 return OK; 3042 return OK;
3017 } 3043 }
3018 3044
3045 void HttpCache::Transaction::ResetPartialState(bool delete_object) {
3046 partial_->RestoreHeaders(&custom_request_->extra_headers);
3047 DoomPartialEntry(delete_object);
3048
3049 if (!delete_object) {
3050 // The simplest way to re-initialize partial_ is to create a new object.
3051 partial_.reset(new PartialData());
3052 if (partial_->Init(request_->extra_headers))
3053 partial_->SetHeaders(custom_request_->extra_headers);
3054 else
3055 partial_.reset();
3056 }
3057 }
3058
3019 void HttpCache::Transaction::ResetNetworkTransaction() { 3059 void HttpCache::Transaction::ResetNetworkTransaction() {
3020 DCHECK(!old_network_trans_load_timing_); 3060 DCHECK(!old_network_trans_load_timing_);
3021 DCHECK(network_trans_); 3061 DCHECK(network_trans_);
3022 LoadTimingInfo load_timing; 3062 LoadTimingInfo load_timing;
3023 if (network_trans_->GetLoadTimingInfo(&load_timing)) 3063 if (network_trans_->GetLoadTimingInfo(&load_timing))
3024 old_network_trans_load_timing_.reset(new LoadTimingInfo(load_timing)); 3064 old_network_trans_load_timing_.reset(new LoadTimingInfo(load_timing));
3025 total_received_bytes_ += network_trans_->GetTotalReceivedBytes(); 3065 total_received_bytes_ += network_trans_->GetTotalReceivedBytes();
3026 network_trans_.reset(); 3066 network_trans_.reset();
3027 } 3067 }
3028 3068
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3147 3187
3148 void HttpCache::Transaction::OnIOComplete(int result) { 3188 void HttpCache::Transaction::OnIOComplete(int result) {
3149 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 3189 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
3150 tracked_objects::ScopedTracker tracking_profile( 3190 tracked_objects::ScopedTracker tracking_profile(
3151 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); 3191 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete"));
3152 3192
3153 DoLoop(result); 3193 DoLoop(result);
3154 } 3194 }
3155 3195
3156 } // namespace net 3196 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698