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

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

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Feedback addressed. Created 3 years, 8 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" // 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 HttpCache::Transaction::Transaction(RequestPriority priority, HttpCache* cache) 164 HttpCache::Transaction::Transaction(RequestPriority priority, HttpCache* cache)
165 : next_state_(STATE_NONE), 165 : next_state_(STATE_NONE),
166 request_(NULL), 166 request_(NULL),
167 priority_(priority), 167 priority_(priority),
168 cache_(cache->GetWeakPtr()), 168 cache_(cache->GetWeakPtr()),
169 entry_(NULL), 169 entry_(NULL),
170 new_entry_(NULL), 170 new_entry_(NULL),
171 new_response_(NULL), 171 new_response_(NULL),
172 mode_(NONE), 172 mode_(NONE),
173 original_mode_(NONE),
173 reading_(false), 174 reading_(false),
174 invalid_range_(false), 175 invalid_range_(false),
175 truncated_(false), 176 truncated_(false),
176 is_sparse_(false), 177 is_sparse_(false),
177 range_requested_(false), 178 range_requested_(false),
178 handling_206_(false), 179 handling_206_(false),
179 cache_pending_(false), 180 cache_pending_(false),
180 done_reading_(false), 181 done_reading_(false),
181 vary_mismatch_(false), 182 vary_mismatch_(false),
182 couldnt_conditionalize_request_(false), 183 couldnt_conditionalize_request_(false),
(...skipping 20 matching lines...) Expand all
203 } 204 }
204 205
205 HttpCache::Transaction::~Transaction() { 206 HttpCache::Transaction::~Transaction() {
206 TRACE_EVENT0("io", "HttpCacheTransaction::~Transaction"); 207 TRACE_EVENT0("io", "HttpCacheTransaction::~Transaction");
207 // We may have to issue another IO, but we should never invoke the callback_ 208 // We may have to issue another IO, but we should never invoke the callback_
208 // after this point. 209 // after this point.
209 callback_.Reset(); 210 callback_.Reset();
210 211
211 if (cache_) { 212 if (cache_) {
212 if (entry_) { 213 if (entry_) {
213 bool cancel_request = reading_ && response_.headers.get(); 214 bool cancel_response = cache_->IsTransactionCurrentOrFutureWriter(
214 if (cancel_request) { 215 entry_, this, request_->method);
215 if (partial_) { 216 if (cancel_response && partial_)
216 entry_->disk_entry->CancelSparseIO(); 217 entry_->disk_entry->CancelSparseIO();
217 } else {
218 cancel_request &= (response_.headers->response_code() == 200);
219 }
220 }
221 218
222 cache_->DoneWithEntry(entry_, this, cancel_request); 219 cache_->DoneWithEntry(entry_, this, cancel_response);
223 } else if (cache_pending_) { 220 } else if (cache_pending_) {
224 cache_->RemovePendingTransaction(this); 221 cache_->RemovePendingTransaction(this);
225 } 222 }
226 } 223 }
227 } 224 }
228 225
229 int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len, 226 int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len,
230 const CompletionCallback& callback) { 227 const CompletionCallback& callback) {
231 DCHECK(buf); 228 DCHECK(buf);
232 DCHECK_GT(buf_len, 0); 229 DCHECK_GT(buf_len, 0);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 ConnectionAttempts* out) const { 569 ConnectionAttempts* out) const {
573 ConnectionAttempts new_connection_attempts; 570 ConnectionAttempts new_connection_attempts;
574 if (network_trans_) 571 if (network_trans_)
575 network_trans_->GetConnectionAttempts(&new_connection_attempts); 572 network_trans_->GetConnectionAttempts(&new_connection_attempts);
576 573
577 out->swap(new_connection_attempts); 574 out->swap(new_connection_attempts);
578 out->insert(out->begin(), old_connection_attempts_.begin(), 575 out->insert(out->begin(), old_connection_attempts_.begin(),
579 old_connection_attempts_.end()); 576 old_connection_attempts_.end());
580 } 577 }
581 578
579 void HttpCache::Transaction::SetValidatingCannotProceed() {
580 DCHECK(!reading_);
581 next_state_ = STATE_HEADERS_PHASE_CANNOT_PROCEED;
582 entry_ = nullptr;
583 }
584
582 size_t HttpCache::Transaction::EstimateMemoryUsage() const { 585 size_t HttpCache::Transaction::EstimateMemoryUsage() const {
583 // TODO(xunjieli): Consider improving the coverage. crbug.com/669108. 586 // TODO(xunjieli): Consider improving the coverage. crbug.com/669108.
584 return 0; 587 return 0;
585 } 588 }
586 589
587 //----------------------------------------------------------------------------- 590 //-----------------------------------------------------------------------------
588 591
589 // A few common patterns: (Foo* means Foo -> FooComplete) 592 // A few common patterns: (Foo* means Foo -> FooComplete)
590 // 593 //
591 // 1. Not-cached entry: 594 // 1. Not-cached entry:
592 // Start(): 595 // Start():
593 // GetBackend* -> InitEntry -> OpenEntry* -> CreateEntry* -> AddToEntry* -> 596 // GetBackend* -> InitEntry -> OpenEntry* -> CreateEntry* -> AddToEntry* ->
594 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> 597 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse ->
595 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> 598 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* ->
596 // PartialHeadersReceived 599 // PartialHeadersReceived -> FinishHeaders*
597 // 600 //
598 // Read(): 601 // Read():
599 // NetworkRead* -> CacheWriteData* 602 // NetworkRead* -> CacheWriteData*
600 // 603 //
601 // 2. Cached entry, no validation: 604 // 2. Cached entry, no validation:
602 // Start(): 605 // Start():
603 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 606 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
604 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 607 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
605 // BeginCacheValidation() -> SetupEntryForRead() 608 // BeginCacheValidation() -> SetupEntryForRead() -> FinishHeaders*
606 // 609 //
607 // Read(): 610 // Read():
608 // CacheReadData* 611 // CacheReadData*
609 // 612 //
610 // 3. Cached entry, validation (304): 613 // 3. Cached entry, validation (304):
611 // Start(): 614 // Start():
612 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 615 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
613 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 616 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
614 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> 617 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
615 // UpdateCachedResponse -> CacheWriteUpdatedResponse* -> 618 // UpdateCachedResponse -> CacheWriteUpdatedResponse* ->
616 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> 619 // UpdateCachedResponseComplete -> OverwriteCachedResponse ->
617 // PartialHeadersReceived 620 // PartialHeadersReceived -> FinishHeaders*
618 // 621 //
619 // Read(): 622 // Read():
620 // CacheReadData* 623 // CacheReadData*
621 // 624 //
622 // 4. Cached entry, validation and replace (200): 625 // 4. Cached entry, validation and replace (200):
623 // Start(): 626 // Start():
624 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 627 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
625 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 628 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
626 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> 629 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
627 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* -> 630 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* ->
628 // TruncateCachedMetadata* -> PartialHeadersReceived 631 // TruncateCachedMetadata* -> PartialHeadersReceived -> FinishHeaders*
629 // 632 //
630 // Read(): 633 // Read():
631 // NetworkRead* -> CacheWriteData* 634 // NetworkRead* -> CacheWriteData*
632 // 635 //
633 // 5. Sparse entry, partially cached, byte range request: 636 // 5. Sparse entry, partially cached, byte range request:
634 // Start(): 637 // Start():
635 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 638 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
636 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 639 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
637 // CacheQueryData* -> ValidateEntryHeadersAndContinue() -> 640 // CacheQueryData* -> ValidateEntryHeadersAndContinue() ->
638 // StartPartialCacheValidation -> CompletePartialCacheValidation -> 641 // StartPartialCacheValidation -> CompletePartialCacheValidation ->
639 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> 642 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
640 // UpdateCachedResponse -> CacheWriteUpdatedResponse* -> 643 // UpdateCachedResponse -> CacheWriteUpdatedResponse* ->
641 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> 644 // UpdateCachedResponseComplete -> OverwriteCachedResponse ->
642 // PartialHeadersReceived 645 // PartialHeadersReceived -> FinishHeaders*
643 // 646 //
644 // Read() 1: 647 // Read() 1:
645 // NetworkRead* -> CacheWriteData* 648 // NetworkRead* -> CacheWriteData*
646 // 649 //
647 // Read() 2: 650 // Read() 2:
648 // NetworkRead* -> CacheWriteData* -> StartPartialCacheValidation -> 651 // NetworkRead* -> CacheWriteData* -> StartPartialCacheValidation ->
649 // CompletePartialCacheValidation -> CacheReadData* -> 652 // CompletePartialCacheValidation -> CacheReadData* ->
650 // 653 //
651 // Read() 3: 654 // Read() 3:
652 // CacheReadData* -> StartPartialCacheValidation -> 655 // CacheReadData* -> StartPartialCacheValidation ->
(...skipping 20 matching lines...) Expand all
673 // Read(): 676 // Read():
674 // CacheReadData (returns 0) 677 // CacheReadData (returns 0)
675 // 678 //
676 // 9. HEAD. Cached entry, validation and replace (200): 679 // 9. HEAD. Cached entry, validation and replace (200):
677 // Pass through. The request dooms the old entry, as a HEAD won't be stored by 680 // Pass through. The request dooms the old entry, as a HEAD won't be stored by
678 // itself. 681 // itself.
679 // Start(): 682 // Start():
680 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 683 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
681 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 684 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
682 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> 685 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
683 // OverwriteCachedResponse 686 // OverwriteCachedResponse -> FinishHeaders*
684 // 687 //
685 // 10. HEAD. Sparse entry, partially cached: 688 // 10. HEAD. Sparse entry, partially cached:
686 // Serve the request from the cache, as long as it doesn't require 689 // Serve the request from the cache, as long as it doesn't require
687 // revalidation. Ignore missing ranges when deciding to revalidate. If the 690 // revalidation. Ignore missing ranges when deciding to revalidate. If the
688 // entry requires revalidation, ignore the whole request and go to full pass 691 // entry requires revalidation, ignore the whole request and go to full pass
689 // through (the result of the HEAD request will NOT update the entry). 692 // through (the result of the HEAD request will NOT update the entry).
690 // 693 //
691 // Start(): Basically the same as example 7, as we never create a partial_ 694 // Start(): Basically the same as example 7, as we never create a partial_
692 // object for this request. 695 // object for this request.
693 // 696 //
694 // 11. Prefetch, not-cached entry: 697 // 11. Prefetch, not-cached entry:
695 // The same as example 1. The "unused_since_prefetch" bit is stored as true in 698 // The same as example 1. The "unused_since_prefetch" bit is stored as true in
696 // UpdateCachedResponse. 699 // UpdateCachedResponse.
697 // 700 //
698 // 12. Prefetch, cached entry: 701 // 12. Prefetch, cached entry:
699 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between 702 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between
700 // CacheReadResponse* and CacheDispatchValidation if the unused_since_prefetch 703 // CacheReadResponse* and CacheDispatchValidation if the unused_since_prefetch
701 // bit is unset. 704 // bit is unset.
702 // 705 //
703 // 13. Cached entry less than 5 minutes old, unused_since_prefetch is true: 706 // 13. Cached entry less than 5 minutes old, unused_since_prefetch is true:
704 // Skip validation, similar to example 2. 707 // Skip validation, similar to example 2.
705 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 708 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
706 // -> CacheToggleUnusedSincePrefetch* -> CacheDispatchValidation -> 709 // -> CacheToggleUnusedSincePrefetch* -> CacheDispatchValidation ->
707 // BeginPartialCacheValidation() -> BeginCacheValidation() -> 710 // BeginPartialCacheValidation() -> BeginCacheValidation() ->
708 // SetupEntryForRead() 711 // SetupEntryForRead() -> FinishHeaders*
709 // 712 //
710 // Read(): 713 // Read():
711 // CacheReadData* 714 // CacheReadData*
712 // 715 //
713 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true: 716 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true:
714 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between 717 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between
715 // CacheReadResponse* and CacheDispatchValidation. 718 // CacheReadResponse* and CacheDispatchValidation.
716 int HttpCache::Transaction::DoLoop(int result) { 719 int HttpCache::Transaction::DoLoop(int result) {
717 DCHECK_NE(STATE_UNSET, next_state_); 720 DCHECK_NE(STATE_UNSET, next_state_);
718 DCHECK_NE(STATE_NONE, next_state_); 721 DCHECK_NE(STATE_NONE, next_state_);
719 DCHECK(!in_do_loop_); 722 DCHECK(!in_do_loop_);
720 723
721 int rv = result; 724 int rv = result;
725 State state = next_state_;
722 do { 726 do {
723 State state = next_state_; 727 state = next_state_;
724 next_state_ = STATE_UNSET; 728 next_state_ = STATE_UNSET;
725 base::AutoReset<bool> scoped_in_do_loop(&in_do_loop_, true); 729 base::AutoReset<bool> scoped_in_do_loop(&in_do_loop_, true);
726 730
727 switch (state) { 731 switch (state) {
728 case STATE_GET_BACKEND: 732 case STATE_GET_BACKEND:
729 DCHECK_EQ(OK, rv); 733 DCHECK_EQ(OK, rv);
730 rv = DoGetBackend(); 734 rv = DoGetBackend();
731 break; 735 break;
732 case STATE_GET_BACKEND_COMPLETE: 736 case STATE_GET_BACKEND_COMPLETE:
733 rv = DoGetBackendComplete(rv); 737 rv = DoGetBackendComplete(rv);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 DCHECK_EQ(OK, rv); 854 DCHECK_EQ(OK, rv);
851 rv = DoPartialHeadersReceived(); 855 rv = DoPartialHeadersReceived();
852 break; 856 break;
853 case STATE_CACHE_READ_METADATA: 857 case STATE_CACHE_READ_METADATA:
854 DCHECK_EQ(OK, rv); 858 DCHECK_EQ(OK, rv);
855 rv = DoCacheReadMetadata(); 859 rv = DoCacheReadMetadata();
856 break; 860 break;
857 case STATE_CACHE_READ_METADATA_COMPLETE: 861 case STATE_CACHE_READ_METADATA_COMPLETE:
858 rv = DoCacheReadMetadataComplete(rv); 862 rv = DoCacheReadMetadataComplete(rv);
859 break; 863 break;
864 case STATE_HEADERS_PHASE_CANNOT_PROCEED:
865 rv = DoHeadersPhaseCannotProceed();
866 break;
867 case STATE_FINISH_HEADERS:
868 rv = DoFinishHeaders(rv);
869 break;
870 case STATE_FINISH_HEADERS_COMPLETE:
871 rv = DoFinishHeadersComplete(rv);
872 break;
860 case STATE_NETWORK_READ: 873 case STATE_NETWORK_READ:
861 DCHECK_EQ(OK, rv); 874 DCHECK_EQ(OK, rv);
862 rv = DoNetworkRead(); 875 rv = DoNetworkRead();
863 break; 876 break;
864 case STATE_NETWORK_READ_COMPLETE: 877 case STATE_NETWORK_READ_COMPLETE:
865 rv = DoNetworkReadComplete(rv); 878 rv = DoNetworkReadComplete(rv);
866 break; 879 break;
867 case STATE_CACHE_READ_DATA: 880 case STATE_CACHE_READ_DATA:
868 DCHECK_EQ(OK, rv); 881 DCHECK_EQ(OK, rv);
869 rv = DoCacheReadData(); 882 rv = DoCacheReadData();
(...skipping 16 matching lines...) Expand all
886 break; 899 break;
887 default: 900 default:
888 NOTREACHED() << "bad state " << state; 901 NOTREACHED() << "bad state " << state;
889 rv = ERR_FAILED; 902 rv = ERR_FAILED;
890 break; 903 break;
891 } 904 }
892 DCHECK(next_state_ != STATE_UNSET) << "Previous state was " << state; 905 DCHECK(next_state_ != STATE_UNSET) << "Previous state was " << state;
893 906
894 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 907 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
895 908
909 // Assert Start() state machine's allowed last state in successful cases when
910 // caching is happening.
911 DCHECK(reading_ || rv != OK || !entry_ ||
912 state == STATE_FINISH_HEADERS_COMPLETE);
913
896 if (rv != ERR_IO_PENDING && !callback_.is_null()) { 914 if (rv != ERR_IO_PENDING && !callback_.is_null()) {
897 read_buf_ = NULL; // Release the buffer before invoking the callback. 915 read_buf_ = nullptr; // Release the buffer before invoking the callback.
898 base::ResetAndReturn(&callback_).Run(rv); 916 base::ResetAndReturn(&callback_).Run(rv);
899 } 917 }
900 918
901 return rv; 919 return rv;
902 } 920 }
903 921
904 int HttpCache::Transaction::DoGetBackend() { 922 int HttpCache::Transaction::DoGetBackend() {
905 cache_pending_ = true; 923 cache_pending_ = true;
906 TransitionToState(STATE_GET_BACKEND_COMPLETE); 924 TransitionToState(STATE_GET_BACKEND_COMPLETE);
907 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND); 925 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND);
908 return cache_->GetBackendForTransaction(this); 926 return cache_->GetBackendForTransaction(this);
909 } 927 }
910 928
911 int HttpCache::Transaction::DoGetBackendComplete(int result) { 929 int HttpCache::Transaction::DoGetBackendComplete(int result) {
912 DCHECK(result == OK || result == ERR_FAILED); 930 DCHECK(result == OK || result == ERR_FAILED);
913 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_GET_BACKEND, 931 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_GET_BACKEND,
914 result); 932 result);
915 cache_pending_ = false; 933 cache_pending_ = false;
916 934
917 if (!ShouldPassThrough()) { 935 if (!ShouldPassThrough()) {
918 cache_key_ = cache_->GenerateCacheKey(request_); 936 cache_key_ = cache_->GenerateCacheKey(request_);
919 937
920 // Requested cache access mode. 938 // Requested cache access mode.
921 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { 939 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) {
922 if (effective_load_flags_ & LOAD_BYPASS_CACHE) { 940 if (effective_load_flags_ & LOAD_BYPASS_CACHE) {
923 // The client has asked for nonsense. 941 // The client has asked for nonsense.
924 TransitionToState(STATE_NONE); 942 TransitionToState(STATE_FINISH_HEADERS);
925 return ERR_CACHE_MISS; 943 return ERR_CACHE_MISS;
926 } 944 }
927 mode_ = READ; 945 mode_ = READ;
928 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { 946 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) {
929 mode_ = WRITE; 947 mode_ = WRITE;
930 } else { 948 } else {
931 mode_ = READ_WRITE; 949 mode_ = READ_WRITE;
932 } 950 }
933 951
934 // Downgrade to UPDATE if the request has been externally conditionalized. 952 // Downgrade to UPDATE if the request has been externally conditionalized.
(...skipping 18 matching lines...) Expand all
953 // transaction behaves the same for GET and HEAD requests at this point: if it 971 // transaction behaves the same for GET and HEAD requests at this point: if it
954 // was not modified, the entry is updated and a response is not returned from 972 // was not modified, the entry is updated and a response is not returned from
955 // the cache. If we receive 200, it doesn't matter if there was a validation 973 // the cache. If we receive 200, it doesn't matter if there was a validation
956 // header or not. 974 // header or not.
957 if (request_->method == "HEAD" && mode_ == WRITE) 975 if (request_->method == "HEAD" && mode_ == WRITE)
958 mode_ = NONE; 976 mode_ = NONE;
959 977
960 // If must use cache, then we must fail. This can happen for back/forward 978 // If must use cache, then we must fail. This can happen for back/forward
961 // navigations to a page generated via a form post. 979 // navigations to a page generated via a form post.
962 if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { 980 if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) {
963 TransitionToState(STATE_NONE); 981 TransitionToState(STATE_FINISH_HEADERS);
964 return ERR_CACHE_MISS; 982 return ERR_CACHE_MISS;
965 } 983 }
966 984
967 if (mode_ == NONE) { 985 if (mode_ == NONE) {
968 if (partial_) { 986 if (partial_) {
969 partial_->RestoreHeaders(&custom_request_->extra_headers); 987 partial_->RestoreHeaders(&custom_request_->extra_headers);
970 partial_.reset(); 988 partial_.reset();
971 } 989 }
972 TransitionToState(STATE_SEND_REQUEST); 990 TransitionToState(STATE_SEND_REQUEST);
973 } else { 991 } else {
974 TransitionToState(STATE_INIT_ENTRY); 992 TransitionToState(STATE_INIT_ENTRY);
975 } 993 }
976 994
977 // This is only set if we have something to do with the response. 995 // This is only set if we have something to do with the response.
978 range_requested_ = (partial_.get() != NULL); 996 range_requested_ = (partial_.get() != NULL);
979 997
998 // mode_ may change later, save the initial mode in case we need to restart
999 // this request.
1000 original_mode_ = mode_;
980 return OK; 1001 return OK;
981 } 1002 }
982 1003
983 int HttpCache::Transaction::DoInitEntry() { 1004 int HttpCache::Transaction::DoInitEntry() {
984 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); 1005 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry");
985 DCHECK(!new_entry_); 1006 DCHECK(!new_entry_);
986 1007
987 if (!cache_.get()) { 1008 if (!cache_.get()) {
988 TransitionToState(STATE_NONE); 1009 TransitionToState(STATE_FINISH_HEADERS);
989 return ERR_UNEXPECTED; 1010 return ERR_UNEXPECTED;
990 } 1011 }
991 1012
992 if (mode_ == WRITE) { 1013 if (mode_ == WRITE) {
993 TransitionToState(STATE_DOOM_ENTRY); 1014 TransitionToState(STATE_DOOM_ENTRY);
994 return OK; 1015 return OK;
995 } 1016 }
996 1017
997 TransitionToState(STATE_OPEN_ENTRY); 1018 TransitionToState(STATE_OPEN_ENTRY);
998 return OK; 1019 return OK;
(...skipping 16 matching lines...) Expand all
1015 // transaction attached. 1036 // transaction attached.
1016 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, 1037 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY,
1017 result); 1038 result);
1018 cache_pending_ = false; 1039 cache_pending_ = false;
1019 if (result == OK) { 1040 if (result == OK) {
1020 TransitionToState(STATE_ADD_TO_ENTRY); 1041 TransitionToState(STATE_ADD_TO_ENTRY);
1021 return OK; 1042 return OK;
1022 } 1043 }
1023 1044
1024 if (result == ERR_CACHE_RACE) { 1045 if (result == ERR_CACHE_RACE) {
1025 TransitionToState(STATE_INIT_ENTRY); 1046 TransitionToState(STATE_HEADERS_PHASE_CANNOT_PROCEED);
1026 return OK; 1047 return OK;
1027 } 1048 }
1028 1049
1029 if (request_->method == "PUT" || request_->method == "DELETE" || 1050 if (request_->method == "PUT" || request_->method == "DELETE" ||
1030 (request_->method == "HEAD" && mode_ == READ_WRITE)) { 1051 (request_->method == "HEAD" && mode_ == READ_WRITE)) {
1031 DCHECK(mode_ == READ_WRITE || mode_ == WRITE || request_->method == "HEAD"); 1052 DCHECK(mode_ == READ_WRITE || mode_ == WRITE || request_->method == "HEAD");
1032 mode_ = NONE; 1053 mode_ = NONE;
1033 TransitionToState(STATE_SEND_REQUEST); 1054 TransitionToState(STATE_SEND_REQUEST);
1034 return OK; 1055 return OK;
1035 } 1056 }
1036 1057
1037 if (mode_ == READ_WRITE) { 1058 if (mode_ == READ_WRITE) {
1038 mode_ = WRITE; 1059 mode_ = WRITE;
1039 TransitionToState(STATE_CREATE_ENTRY); 1060 TransitionToState(STATE_CREATE_ENTRY);
1040 return OK; 1061 return OK;
1041 } 1062 }
1042 if (mode_ == UPDATE) { 1063 if (mode_ == UPDATE) {
1043 // There is no cache entry to update; proceed without caching. 1064 // There is no cache entry to update; proceed without caching.
1044 mode_ = NONE; 1065 mode_ = NONE;
1045 TransitionToState(STATE_SEND_REQUEST); 1066 TransitionToState(STATE_SEND_REQUEST);
1046 return OK; 1067 return OK;
1047 } 1068 }
1048 1069
1049 // The entry does not exist, and we are not permitted to create a new entry, 1070 // The entry does not exist, and we are not permitted to create a new entry,
1050 // so we must fail. 1071 // so we must fail.
1051 TransitionToState(STATE_NONE); 1072 TransitionToState(STATE_FINISH_HEADERS);
1052 return ERR_CACHE_MISS; 1073 return ERR_CACHE_MISS;
1053 } 1074 }
1054 1075
1055 int HttpCache::Transaction::DoDoomEntry() { 1076 int HttpCache::Transaction::DoDoomEntry() {
1056 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntry"); 1077 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntry");
1057 TransitionToState(STATE_DOOM_ENTRY_COMPLETE); 1078 TransitionToState(STATE_DOOM_ENTRY_COMPLETE);
1058 cache_pending_ = true; 1079 cache_pending_ = true;
1059 if (first_cache_access_since_.is_null()) 1080 if (first_cache_access_since_.is_null())
1060 first_cache_access_since_ = TimeTicks::Now(); 1081 first_cache_access_since_ = TimeTicks::Now();
1061 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); 1082 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY);
1062 return cache_->DoomEntry(cache_key_, this); 1083 return cache_->DoomEntry(cache_key_, this);
1063 } 1084 }
1064 1085
1065 int HttpCache::Transaction::DoDoomEntryComplete(int result) { 1086 int HttpCache::Transaction::DoDoomEntryComplete(int result) {
1066 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntryComplete"); 1087 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntryComplete");
1067 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, 1088 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY,
1068 result); 1089 result);
1069 cache_pending_ = false; 1090 cache_pending_ = false;
1070 TransitionToState(result == ERR_CACHE_RACE ? STATE_INIT_ENTRY 1091 TransitionToState(result == ERR_CACHE_RACE
1071 : STATE_CREATE_ENTRY); 1092 ? STATE_HEADERS_PHASE_CANNOT_PROCEED
1093 : STATE_CREATE_ENTRY);
1072 return OK; 1094 return OK;
1073 } 1095 }
1074 1096
1075 int HttpCache::Transaction::DoCreateEntry() { 1097 int HttpCache::Transaction::DoCreateEntry() {
1076 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntry"); 1098 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntry");
1077 DCHECK(!new_entry_); 1099 DCHECK(!new_entry_);
1078 TransitionToState(STATE_CREATE_ENTRY_COMPLETE); 1100 TransitionToState(STATE_CREATE_ENTRY_COMPLETE);
1079 cache_pending_ = true; 1101 cache_pending_ = true;
1080 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); 1102 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY);
1081 return cache_->CreateEntry(cache_key_, &new_entry_, this); 1103 return cache_->CreateEntry(cache_key_, &new_entry_, this);
1082 } 1104 }
1083 1105
1084 int HttpCache::Transaction::DoCreateEntryComplete(int result) { 1106 int HttpCache::Transaction::DoCreateEntryComplete(int result) {
1085 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete"); 1107 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete");
1086 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is 1108 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is
1087 // OK, otherwise the cache will end up with an active entry without any 1109 // OK, otherwise the cache will end up with an active entry without any
1088 // transaction attached. 1110 // transaction attached.
1089 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, 1111 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY,
1090 result); 1112 result);
1091 cache_pending_ = false; 1113 cache_pending_ = false;
1092 switch (result) { 1114 switch (result) {
1093 case OK: 1115 case OK:
1094 TransitionToState(STATE_ADD_TO_ENTRY); 1116 TransitionToState(STATE_ADD_TO_ENTRY);
1095 break; 1117 break;
1096 1118
1097 case ERR_CACHE_RACE: 1119 case ERR_CACHE_RACE:
1098 TransitionToState(STATE_INIT_ENTRY); 1120 TransitionToState(STATE_HEADERS_PHASE_CANNOT_PROCEED);
1099 break; 1121 break;
1100 1122
1101 default: 1123 default:
1102 // We have a race here: Maybe we failed to open the entry and decided to 1124 // We have a race here: Maybe we failed to open the entry and decided to
1103 // create one, but by the time we called create, another transaction 1125 // create one, but by the time we called create, another transaction
1104 // already created the entry. If we want to eliminate this issue, we 1126 // already created the entry. If we want to eliminate this issue, we
1105 // need an atomic OpenOrCreate() method exposed by the disk cache. 1127 // need an atomic OpenOrCreate() method exposed by the disk cache.
1106 DLOG(WARNING) << "Unable to create cache entry"; 1128 DLOG(WARNING) << "Unable to create cache entry";
1107 mode_ = NONE; 1129 mode_ = NONE;
1108 if (partial_) 1130 if (partial_)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 DCHECK(new_entry_); 1191 DCHECK(new_entry_);
1170 cache_pending_ = false; 1192 cache_pending_ = false;
1171 1193
1172 if (result == OK) 1194 if (result == OK)
1173 entry_ = new_entry_; 1195 entry_ = new_entry_;
1174 1196
1175 // If there is a failure, the cache should have taken care of new_entry_. 1197 // If there is a failure, the cache should have taken care of new_entry_.
1176 new_entry_ = NULL; 1198 new_entry_ = NULL;
1177 1199
1178 if (result == ERR_CACHE_RACE) { 1200 if (result == ERR_CACHE_RACE) {
1179 TransitionToState(STATE_INIT_ENTRY); 1201 TransitionToState(STATE_HEADERS_PHASE_CANNOT_PROCEED);
1180 return OK; 1202 return OK;
1181 } 1203 }
1182 1204
1183 if (result == ERR_CACHE_LOCK_TIMEOUT) { 1205 if (result == ERR_CACHE_LOCK_TIMEOUT) {
1184 if (mode_ == READ) { 1206 if (mode_ == READ) {
1185 TransitionToState(STATE_NONE); 1207 TransitionToState(STATE_FINISH_HEADERS);
1186 return ERR_CACHE_MISS; 1208 return ERR_CACHE_MISS;
1187 } 1209 }
1188 1210
1189 // The cache is busy, bypass it for this transaction. 1211 // The cache is busy, bypass it for this transaction.
1190 mode_ = NONE; 1212 mode_ = NONE;
1191 TransitionToState(STATE_SEND_REQUEST); 1213 TransitionToState(STATE_SEND_REQUEST);
1192 if (partial_) { 1214 if (partial_) {
1193 partial_->RestoreHeaders(&custom_request_->extra_headers); 1215 partial_->RestoreHeaders(&custom_request_->extra_headers);
1194 partial_.reset(); 1216 partial_.reset();
1195 } 1217 }
1196 return OK; 1218 return OK;
1197 } 1219 }
1198 1220
1199 open_entry_last_used_ = entry_->disk_entry->GetLastUsed(); 1221 open_entry_last_used_ = entry_->disk_entry->GetLastUsed();
1200 1222
1201 // TODO(jkarlin): We should either handle the case or DCHECK. 1223 // TODO(jkarlin): We should either handle the case or DCHECK.
1202 if (result != OK) { 1224 if (result != OK) {
1203 NOTREACHED(); 1225 NOTREACHED();
1204 TransitionToState(STATE_NONE); 1226 TransitionToState(STATE_FINISH_HEADERS);
1205 return result; 1227 return result;
1206 } 1228 }
1207 1229
1208 if (mode_ == WRITE) { 1230 if (mode_ == WRITE) {
1209 if (partial_) 1231 if (partial_)
1210 partial_->RestoreHeaders(&custom_request_->extra_headers); 1232 partial_->RestoreHeaders(&custom_request_->extra_headers);
1211 TransitionToState(STATE_SEND_REQUEST); 1233 TransitionToState(STATE_SEND_REQUEST);
1212 } else { 1234 } else {
1213 // We have to read the headers from the cached entry. 1235 // We have to read the headers from the cached entry.
1214 DCHECK(mode_ & READ_META); 1236 DCHECK(mode_ & READ_META);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 } 1359 }
1338 1360
1339 int HttpCache::Transaction::DoCacheQueryData() { 1361 int HttpCache::Transaction::DoCacheQueryData() {
1340 TransitionToState(STATE_CACHE_QUERY_DATA_COMPLETE); 1362 TransitionToState(STATE_CACHE_QUERY_DATA_COMPLETE);
1341 return entry_->disk_entry->ReadyForSparseIO(io_callback_); 1363 return entry_->disk_entry->ReadyForSparseIO(io_callback_);
1342 } 1364 }
1343 1365
1344 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { 1366 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) {
1345 DCHECK_EQ(OK, result); 1367 DCHECK_EQ(OK, result);
1346 if (!cache_.get()) { 1368 if (!cache_.get()) {
1347 TransitionToState(STATE_NONE); 1369 TransitionToState(STATE_FINISH_HEADERS);
1348 return ERR_UNEXPECTED; 1370 return ERR_UNEXPECTED;
1349 } 1371 }
1350 1372
1351 return ValidateEntryHeadersAndContinue(); 1373 return ValidateEntryHeadersAndContinue();
1352 } 1374 }
1353 1375
1354 // We may end up here multiple times for a given request. 1376 // We may end up here multiple times for a given request.
1355 int HttpCache::Transaction::DoStartPartialCacheValidation() { 1377 int HttpCache::Transaction::DoStartPartialCacheValidation() {
1356 if (mode_ == NONE) { 1378 if (mode_ == NONE) {
1357 TransitionToState(STATE_NONE); 1379 TransitionToState(STATE_FINISH_HEADERS);
1358 return OK; 1380 return OK;
1359 } 1381 }
1360 1382
1361 TransitionToState(STATE_COMPLETE_PARTIAL_CACHE_VALIDATION); 1383 TransitionToState(STATE_COMPLETE_PARTIAL_CACHE_VALIDATION);
1362 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); 1384 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_);
1363 } 1385 }
1364 1386
1365 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { 1387 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) {
1366 if (!result) { 1388 if (!result) {
1367 // This is the end of the request. 1389 // This is the end of the request.
1368 if (mode_ & WRITE) { 1390 if (mode_ & WRITE) {
1369 DoneWritingToEntry(true); 1391 DoneWritingToEntry(true);
1370 } else { 1392 } else {
1371 cache_->DoneReadingFromEntry(entry_, this); 1393 cache_->DoneReadingFromEntry(entry_, this);
1372 entry_ = NULL; 1394 entry_ = NULL;
1373 } 1395 }
1374 TransitionToState(STATE_NONE); 1396 TransitionToState(STATE_FINISH_HEADERS);
1375 return result; 1397 return result;
1376 } 1398 }
1377 1399
1378 if (result < 0) { 1400 if (result < 0) {
1379 TransitionToState(STATE_NONE); 1401 TransitionToState(STATE_FINISH_HEADERS);
1380 return result; 1402 return result;
1381 } 1403 }
1382 1404
1383 partial_->PrepareCacheValidation(entry_->disk_entry, 1405 partial_->PrepareCacheValidation(entry_->disk_entry,
1384 &custom_request_->extra_headers); 1406 &custom_request_->extra_headers);
1385 1407
1386 if (reading_ && partial_->IsCurrentRangeCached()) { 1408 if (reading_ && partial_->IsCurrentRangeCached()) {
1387 TransitionToState(STATE_CACHE_READ_DATA); 1409 TransitionToState(STATE_CACHE_READ_DATA);
1388 return OK; 1410 return OK;
1389 } 1411 }
1390 1412
1391 return BeginCacheValidation(); 1413 return BeginCacheValidation();
1392 } 1414 }
1393 1415
1394 int HttpCache::Transaction::DoSendRequest() { 1416 int HttpCache::Transaction::DoSendRequest() {
1395 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequest"); 1417 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequest");
1396 DCHECK(mode_ & WRITE || mode_ == NONE); 1418 DCHECK(mode_ & WRITE || mode_ == NONE);
1397 DCHECK(!network_trans_.get()); 1419 DCHECK(!network_trans_.get());
1398 1420
1399 send_request_since_ = TimeTicks::Now(); 1421 send_request_since_ = TimeTicks::Now();
1400 1422
1401 // Create a network transaction. 1423 // Create a network transaction.
1402 int rv = 1424 int rv =
1403 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); 1425 cache_->network_layer_->CreateTransaction(priority_, &network_trans_);
1404 if (rv != OK) { 1426 if (rv != OK) {
1405 TransitionToState(STATE_NONE); 1427 TransitionToState(STATE_FINISH_HEADERS);
1406 return rv; 1428 return rv;
1407 } 1429 }
1408 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); 1430 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_);
1409 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); 1431 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_);
1410 1432
1411 // Old load timing information, if any, is now obsolete. 1433 // Old load timing information, if any, is now obsolete.
1412 old_network_trans_load_timing_.reset(); 1434 old_network_trans_load_timing_.reset();
1413 old_remote_endpoint_ = IPEndPoint(); 1435 old_remote_endpoint_ = IPEndPoint();
1414 1436
1415 if (websocket_handshake_stream_base_create_helper_) 1437 if (websocket_handshake_stream_base_create_helper_)
1416 network_trans_->SetWebSocketHandshakeStreamCreateHelper( 1438 network_trans_->SetWebSocketHandshakeStreamCreateHelper(
1417 websocket_handshake_stream_base_create_helper_); 1439 websocket_handshake_stream_base_create_helper_);
1418 1440
1419 TransitionToState(STATE_SEND_REQUEST_COMPLETE); 1441 TransitionToState(STATE_SEND_REQUEST_COMPLETE);
1420 rv = network_trans_->Start(request_, io_callback_, net_log_); 1442 rv = network_trans_->Start(request_, io_callback_, net_log_);
1421 return rv; 1443 return rv;
1422 } 1444 }
1423 1445
1424 int HttpCache::Transaction::DoSendRequestComplete(int result) { 1446 int HttpCache::Transaction::DoSendRequestComplete(int result) {
1425 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequestComplete"); 1447 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequestComplete");
1426 if (!cache_.get()) { 1448 if (!cache_.get()) {
1427 TransitionToState(STATE_NONE); 1449 TransitionToState(STATE_FINISH_HEADERS);
1428 return ERR_UNEXPECTED; 1450 return ERR_UNEXPECTED;
1429 } 1451 }
1430 1452
1431 // If we tried to conditionalize the request and failed, we know 1453 // If we tried to conditionalize the request and failed, we know
1432 // we won't be reading from the cache after this point. 1454 // we won't be reading from the cache after this point.
1433 if (couldnt_conditionalize_request_) 1455 if (couldnt_conditionalize_request_)
1434 mode_ = WRITE; 1456 mode_ = WRITE;
1435 1457
1436 if (result == OK) { 1458 if (result == OK) {
1437 TransitionToState(STATE_SUCCESSFUL_SEND_REQUEST); 1459 TransitionToState(STATE_SUCCESSFUL_SEND_REQUEST);
(...skipping 10 matching lines...) Expand all
1448 // so GetResponseInfo() should never return NULL here. 1470 // so GetResponseInfo() should never return NULL here.
1449 DCHECK(response); 1471 DCHECK(response);
1450 response_.ssl_info = response->ssl_info; 1472 response_.ssl_info = response->ssl_info;
1451 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { 1473 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
1452 DCHECK(response); 1474 DCHECK(response);
1453 response_.cert_request_info = response->cert_request_info; 1475 response_.cert_request_info = response->cert_request_info;
1454 } else if (response_.was_cached) { 1476 } else if (response_.was_cached) {
1455 DoneWritingToEntry(true); 1477 DoneWritingToEntry(true);
1456 } 1478 }
1457 1479
1458 TransitionToState(STATE_NONE); 1480 TransitionToState(STATE_FINISH_HEADERS);
1459 return result; 1481 return result;
1460 } 1482 }
1461 1483
1462 // We received the response headers and there is no error. 1484 // We received the response headers and there is no error.
1463 int HttpCache::Transaction::DoSuccessfulSendRequest() { 1485 int HttpCache::Transaction::DoSuccessfulSendRequest() {
1464 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest"); 1486 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest");
1465 DCHECK(!new_response_); 1487 DCHECK(!new_response_);
1466 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); 1488 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo();
1467 1489
1468 if (new_response->headers->response_code() == 401 || 1490 if (new_response->headers->response_code() == 401 ||
1469 new_response->headers->response_code() == 407) { 1491 new_response->headers->response_code() == 407) {
1470 SetAuthResponse(*new_response); 1492 SetAuthResponse(*new_response);
1471 if (!reading_) { 1493 if (!reading_) {
1472 TransitionToState(STATE_NONE); 1494 TransitionToState(STATE_FINISH_HEADERS);
1473 return OK; 1495 return OK;
1474 } 1496 }
1475 1497
1476 // We initiated a second request the caller doesn't know about. We should be 1498 // We initiated a second request the caller doesn't know about. We should be
1477 // able to authenticate this request because we should have authenticated 1499 // able to authenticate this request because we should have authenticated
1478 // this URL moments ago. 1500 // this URL moments ago.
1479 if (IsReadyToRestartForAuth()) { 1501 if (IsReadyToRestartForAuth()) {
1480 DCHECK(!response_.auth_challenge.get()); 1502 DCHECK(!response_.auth_challenge.get());
1481 TransitionToState(STATE_SEND_REQUEST_COMPLETE); 1503 TransitionToState(STATE_SEND_REQUEST_COMPLETE);
1482 // In theory we should check to see if there are new cookies, but there 1504 // In theory we should check to see if there are new cookies, but there
1483 // is no way to do that from here. 1505 // is no way to do that from here.
1484 return network_trans_->RestartWithAuth(AuthCredentials(), io_callback_); 1506 return network_trans_->RestartWithAuth(AuthCredentials(), io_callback_);
1485 } 1507 }
1486 1508
1487 // We have to perform cleanup at this point so that at least the next 1509 // We have to perform cleanup at this point so that at least the next
1488 // request can succeed. We do not retry at this point, because data 1510 // request can succeed. We do not retry at this point, because data
1489 // has been read and we have no way to gather credentials. We would 1511 // has been read and we have no way to gather credentials. We would
1490 // fail again, and potentially loop. This can happen if the credentials 1512 // fail again, and potentially loop. This can happen if the credentials
1491 // expire while chrome is suspended. 1513 // expire while chrome is suspended.
1492 if (entry_) 1514 if (entry_)
1493 DoomPartialEntry(false); 1515 DoomPartialEntry(false);
1494 mode_ = NONE; 1516 mode_ = NONE;
1495 partial_.reset(); 1517 partial_.reset();
1496 ResetNetworkTransaction(); 1518 ResetNetworkTransaction();
1497 TransitionToState(STATE_NONE); 1519 TransitionToState(STATE_FINISH_HEADERS);
1498 return ERR_CACHE_AUTH_FAILURE_AFTER_READ; 1520 return ERR_CACHE_AUTH_FAILURE_AFTER_READ;
1499 } 1521 }
1500 1522
1501 new_response_ = new_response; 1523 new_response_ = new_response;
1502 if (!ValidatePartialResponse() && !auth_response_.headers.get()) { 1524 if (!ValidatePartialResponse() && !auth_response_.headers.get()) {
1503 // Something went wrong with this request and we have to restart it. 1525 // Something went wrong with this request and we have to restart it.
1504 // If we have an authentication response, we are exposed to weird things 1526 // If we have an authentication response, we are exposed to weird things
1505 // hapenning if the user cancels the authentication before we receive 1527 // hapenning if the user cancels the authentication before we receive
1506 // the new response. 1528 // the new response.
1507 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST); 1529 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST);
(...skipping 17 matching lines...) Expand all
1525 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_NOT_IN_CACHE); 1547 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_NOT_IN_CACHE);
1526 } 1548 }
1527 1549
1528 // Invalidate any cached GET with a successful PUT or DELETE. 1550 // Invalidate any cached GET with a successful PUT or DELETE.
1529 if (mode_ == WRITE && 1551 if (mode_ == WRITE &&
1530 (request_->method == "PUT" || request_->method == "DELETE")) { 1552 (request_->method == "PUT" || request_->method == "DELETE")) {
1531 if (NonErrorResponse(new_response->headers->response_code())) { 1553 if (NonErrorResponse(new_response->headers->response_code())) {
1532 int ret = cache_->DoomEntry(cache_key_, NULL); 1554 int ret = cache_->DoomEntry(cache_key_, NULL);
1533 DCHECK_EQ(OK, ret); 1555 DCHECK_EQ(OK, ret);
1534 } 1556 }
1535 cache_->DoneWritingToEntry(entry_, true); 1557 cache_->DoneWritingToEntry(entry_, true, this);
1536 entry_ = NULL; 1558 entry_ = NULL;
1537 mode_ = NONE; 1559 mode_ = NONE;
1538 } 1560 }
1539 1561
1540 // Invalidate any cached GET with a successful POST. 1562 // Invalidate any cached GET with a successful POST.
1541 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) && 1563 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) &&
1542 request_->method == "POST" && 1564 request_->method == "POST" &&
1543 NonErrorResponse(new_response->headers->response_code())) { 1565 NonErrorResponse(new_response->headers->response_code())) {
1544 cache_->DoomMainEntryForUrl(request_->url); 1566 cache_->DoomMainEntryForUrl(request_->url);
1545 } 1567 }
1546 1568
1547 RecordNoStoreHeaderHistogram(request_->load_flags, new_response); 1569 RecordNoStoreHeaderHistogram(request_->load_flags, new_response);
1548 1570
1549 if (new_response_->headers->response_code() == 416 && 1571 if (new_response_->headers->response_code() == 416 &&
1550 (request_->method == "GET" || request_->method == "POST")) { 1572 (request_->method == "GET" || request_->method == "POST")) {
1551 // If there is an active entry it may be destroyed with this transaction. 1573 // If there is an active entry it may be destroyed with this transaction.
1552 SetResponse(*new_response_); 1574 SetResponse(*new_response_);
1553 TransitionToState(STATE_NONE); 1575 TransitionToState(STATE_FINISH_HEADERS);
1554 return OK; 1576 return OK;
1555 } 1577 }
1556 1578
1557 // Are we expecting a response to a conditional query? 1579 // Are we expecting a response to a conditional query?
1558 if (mode_ == READ_WRITE || mode_ == UPDATE) { 1580 if (mode_ == READ_WRITE || mode_ == UPDATE) {
1559 if (new_response->headers->response_code() == 304 || handling_206_) { 1581 if (new_response->headers->response_code() == 304 || handling_206_) {
1560 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED); 1582 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED);
1561 TransitionToState(STATE_UPDATE_CACHED_RESPONSE); 1583 TransitionToState(STATE_UPDATE_CACHED_RESPONSE);
1562 return OK; 1584 return OK;
1563 } 1585 }
1564 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); 1586 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED);
1565 mode_ = WRITE; 1587 mode_ = WRITE;
1566 } 1588 }
1567 1589
1568 TransitionToState(STATE_OVERWRITE_CACHED_RESPONSE); 1590 TransitionToState(STATE_OVERWRITE_CACHED_RESPONSE);
1591
1592 if (!entry_)
1593 return OK;
1594
1595 // Invalidate any current entry with a successful response if this transaction
1596 // cannot write to this entry.
1597 if (new_response->headers->response_code() != 304 &&
1598 !cache_->IsTransactionCurrentOrFutureWriter(entry_, this,
jkarlin 2017/04/04 16:49:55 I don't think the HCT should be aware of ActiveEnt
shivanisha 2017/04/04 20:33:15 Created CanTransactionWriteResponseHeaders for thi
1599 request_->method)) {
1600 cache_->DoneWritingToEntry(entry_, false, this);
1601 entry_ = nullptr;
1602 mode_ = NONE;
1603 }
1604
1569 return OK; 1605 return OK;
1570 } 1606 }
1571 1607
1572 // We received 304 or 206 and we want to update the cached response headers. 1608 // We received 304 or 206 and we want to update the cached response headers.
1573 int HttpCache::Transaction::DoUpdateCachedResponse() { 1609 int HttpCache::Transaction::DoUpdateCachedResponse() {
1574 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse"); 1610 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse");
1575 int rv = OK; 1611 int rv = OK;
1576 // Update the cached response based on the headers and properties of 1612 // Update the cached response based on the headers and properties of
1577 // new_response_. 1613 // new_response_.
1578 response_.headers->Update(*new_response_->headers.get()); 1614 response_.headers->Update(*new_response_->headers.get());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 DCHECK(!handling_206_); 1667 DCHECK(!handling_206_);
1632 // We got a "not modified" response and already updated the corresponding 1668 // We got a "not modified" response and already updated the corresponding
1633 // cache entry above. 1669 // cache entry above.
1634 // 1670 //
1635 // By closing the cached entry now, we make sure that the 304 rather than 1671 // By closing the cached entry now, we make sure that the 304 rather than
1636 // the cached 200 response, is what will be returned to the user. 1672 // the cached 200 response, is what will be returned to the user.
1637 DoneWritingToEntry(true); 1673 DoneWritingToEntry(true);
1638 } else if (entry_ && !handling_206_) { 1674 } else if (entry_ && !handling_206_) {
1639 DCHECK_EQ(READ_WRITE, mode_); 1675 DCHECK_EQ(READ_WRITE, mode_);
1640 if (!partial_ || partial_->IsLastRange()) { 1676 if (!partial_ || partial_->IsLastRange()) {
1641 cache_->ConvertWriterToReader(entry_);
1642 mode_ = READ; 1677 mode_ = READ;
1643 } 1678 }
1644 // We no longer need the network transaction, so destroy it. 1679 // We no longer need the network transaction, so destroy it.
1645 ResetNetworkTransaction(); 1680 ResetNetworkTransaction();
1646 } else if (entry_ && handling_206_ && truncated_ && 1681 } else if (entry_ && handling_206_ && truncated_ &&
1647 partial_->initial_validation()) { 1682 partial_->initial_validation()) {
1648 // We just finished the validation of a truncated entry, and the server 1683 // We just finished the validation of a truncated entry, and the server
1649 // is willing to resume the operation. Now we go back and start serving 1684 // is willing to resume the operation. Now we go back and start serving
1650 // the first part to the user. 1685 // the first part to the user.
1651 ResetNetworkTransaction(); 1686 ResetNetworkTransaction();
(...skipping 17 matching lines...) Expand all
1669 if (handling_206_ && partial_) 1704 if (handling_206_ && partial_)
1670 partial_->FixContentLength(new_response_->headers.get()); 1705 partial_->FixContentLength(new_response_->headers.get());
1671 1706
1672 SetResponse(*new_response_); 1707 SetResponse(*new_response_);
1673 1708
1674 if (request_->method == "HEAD") { 1709 if (request_->method == "HEAD") {
1675 // This response is replacing the cached one. 1710 // This response is replacing the cached one.
1676 DoneWritingToEntry(false); 1711 DoneWritingToEntry(false);
1677 mode_ = NONE; 1712 mode_ = NONE;
1678 new_response_ = NULL; 1713 new_response_ = NULL;
1679 TransitionToState(STATE_NONE); 1714 TransitionToState(STATE_FINISH_HEADERS);
1680 return OK; 1715 return OK;
1681 } 1716 }
1682 1717
1683 if (handling_206_ && !CanResume(false)) { 1718 if (handling_206_ && !CanResume(false)) {
1684 // There is no point in storing this resource because it will never be used. 1719 // There is no point in storing this resource because it will never be used.
1685 // This may change if we support LOAD_ONLY_FROM_CACHE with sparse entries. 1720 // This may change if we support LOAD_ONLY_FROM_CACHE with sparse entries.
1686 DoneWritingToEntry(false); 1721 DoneWritingToEntry(false);
1687 if (partial_) 1722 if (partial_)
1688 partial_->FixResponseHeaders(response_.headers.get(), true); 1723 partial_->FixResponseHeaders(response_.headers.get(), true);
1689 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); 1724 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 } 1786 }
1752 1787
1753 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); 1788 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED);
1754 return OK; 1789 return OK;
1755 } 1790 }
1756 1791
1757 int HttpCache::Transaction::DoPartialHeadersReceived() { 1792 int HttpCache::Transaction::DoPartialHeadersReceived() {
1758 new_response_ = NULL; 1793 new_response_ = NULL;
1759 1794
1760 if (!partial_) { 1795 if (!partial_) {
1761 if (entry_ && entry_->disk_entry->GetDataSize(kMetadataIndex)) 1796 if (entry_ && entry_->disk_entry->GetDataSize(kMetadataIndex)) {
1762 TransitionToState(STATE_CACHE_READ_METADATA); 1797 TransitionToState(STATE_CACHE_READ_METADATA);
1763 else 1798 } else {
1764 TransitionToState(STATE_NONE); 1799 DCHECK(!reading_);
1800 TransitionToState(STATE_FINISH_HEADERS);
1801 }
1765 return OK; 1802 return OK;
1766 } 1803 }
1767 1804
1768 if (reading_) { 1805 if (reading_) {
1769 if (network_trans_.get()) { 1806 if (network_trans_.get()) {
1770 TransitionToState(STATE_NETWORK_READ); 1807 TransitionToState(STATE_NETWORK_READ);
1771 } else { 1808 } else {
1772 TransitionToState(STATE_CACHE_READ_DATA); 1809 TransitionToState(STATE_CACHE_READ_DATA);
1773 } 1810 }
1774 } else if (mode_ != NONE) { 1811 } else if (mode_ != NONE) {
1775 // We are about to return the headers for a byte-range request to the user, 1812 // We are about to return the headers for a byte-range request to the user,
1776 // so let's fix them. 1813 // so let's fix them.
1777 partial_->FixResponseHeaders(response_.headers.get(), true); 1814 partial_->FixResponseHeaders(response_.headers.get(), true);
1778 TransitionToState(STATE_NONE); 1815 TransitionToState(STATE_FINISH_HEADERS);
1779 } else { 1816 } else {
1780 TransitionToState(STATE_NONE); 1817 TransitionToState(STATE_FINISH_HEADERS);
1781 } 1818 }
1782 return OK; 1819 return OK;
1783 } 1820 }
1784 1821
1822 int HttpCache::Transaction::DoHeadersPhaseCannotProceed() {
1823 // If its the Start state machine and it cannot proceed due to a failure,
1824 // restart this transaction.
1825 DCHECK(!reading_);
1826 TransitionToState(STATE_INIT_ENTRY);
1827 cache_entry_status_ = CacheEntryStatus::ENTRY_UNDEFINED;
1828 entry_ = nullptr;
1829 mode_ = original_mode_;
1830 if (network_trans_)
1831 network_trans_.reset();
1832 return OK;
1833 }
1834
1835 int HttpCache::Transaction::DoFinishHeaders(int result) {
1836 if (!entry_ || result != OK) {
1837 TransitionToState(STATE_NONE);
1838 return result;
1839 }
1840
1841 TransitionToState(STATE_FINISH_HEADERS_COMPLETE);
1842
1843 // If it was an auth failure or 416, this transaction should continue to be
1844 // headers_transaction till consumer takes an action, so no need to do
1845 // anything now.
1846 if (auth_response_.headers.get() ||
1847 (new_response_ && new_response_->headers &&
1848 new_response_->headers->response_code() == 416))
1849 return OK;
1850
1851 // If there is no response body to be written or read, it does not need to
1852 // wait.
1853 if (request_->method == "HEAD")
1854 return OK;
1855
1856 return cache_->DoneWithResponseHeaders(entry_, this);
1857 }
1858
1859 int HttpCache::Transaction::DoFinishHeadersComplete(int rv) {
1860 if (rv == ERR_CACHE_RACE) {
1861 TransitionToState(STATE_HEADERS_PHASE_CANNOT_PROCEED);
1862 return OK;
1863 }
1864
1865 TransitionToState(STATE_NONE);
1866 return rv;
1867 }
1868
1785 int HttpCache::Transaction::DoCacheReadMetadata() { 1869 int HttpCache::Transaction::DoCacheReadMetadata() {
1786 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); 1870 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata");
1787 DCHECK(entry_); 1871 DCHECK(entry_);
1788 DCHECK(!response_.metadata.get()); 1872 DCHECK(!response_.metadata.get());
1789 TransitionToState(STATE_CACHE_READ_METADATA_COMPLETE); 1873 TransitionToState(STATE_CACHE_READ_METADATA_COMPLETE);
1790 1874
1791 response_.metadata = 1875 response_.metadata =
1792 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); 1876 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex));
1793 1877
1794 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); 1878 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO);
1795 return entry_->disk_entry->ReadData(kMetadataIndex, 0, 1879 return entry_->disk_entry->ReadData(kMetadataIndex, 0,
1796 response_.metadata.get(), 1880 response_.metadata.get(),
1797 response_.metadata->size(), 1881 response_.metadata->size(),
1798 io_callback_); 1882 io_callback_);
1799 } 1883 }
1800 1884
1801 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { 1885 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) {
1802 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete"); 1886 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete");
1803 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, 1887 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO,
1804 result); 1888 result);
1805 if (result != response_.metadata->size()) 1889 if (result != response_.metadata->size())
1806 return OnCacheReadError(result, false); 1890 return OnCacheReadError(result, false);
1807 TransitionToState(STATE_NONE); 1891
1892 TransitionToState(STATE_FINISH_HEADERS);
1808 return OK; 1893 return OK;
1809 } 1894 }
1810 1895
1811 int HttpCache::Transaction::DoNetworkRead() { 1896 int HttpCache::Transaction::DoNetworkRead() {
1812 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead"); 1897 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead");
1813 TransitionToState(STATE_NETWORK_READ_COMPLETE); 1898 TransitionToState(STATE_NETWORK_READ_COMPLETE);
1814 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); 1899 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_);
1815 } 1900 }
1816 1901
1817 int HttpCache::Transaction::DoNetworkReadComplete(int result) { 1902 int HttpCache::Transaction::DoNetworkReadComplete(int result) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 return false; 2179 return false;
2095 2180
2096 return true; 2181 return true;
2097 } 2182 }
2098 2183
2099 int HttpCache::Transaction::BeginCacheRead() { 2184 int HttpCache::Transaction::BeginCacheRead() {
2100 // We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges. 2185 // We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges.
2101 // TODO(jkarlin): Either handle this case or DCHECK. 2186 // TODO(jkarlin): Either handle this case or DCHECK.
2102 if (response_.headers->response_code() == 206 || partial_) { 2187 if (response_.headers->response_code() == 206 || partial_) {
2103 NOTREACHED(); 2188 NOTREACHED();
2104 TransitionToState(STATE_NONE); 2189 TransitionToState(STATE_FINISH_HEADERS);
2105 return ERR_CACHE_MISS; 2190 return ERR_CACHE_MISS;
2106 } 2191 }
2107 2192
2108 // We don't have the whole resource. 2193 // We don't have the whole resource.
2109 if (truncated_) { 2194 if (truncated_) {
2110 TransitionToState(STATE_NONE); 2195 TransitionToState(STATE_FINISH_HEADERS);
2111 return ERR_CACHE_MISS; 2196 return ERR_CACHE_MISS;
2112 } 2197 }
2113 2198
2114 if (RequiresValidation() != VALIDATION_NONE) { 2199 if (RequiresValidation() != VALIDATION_NONE) {
2115 TransitionToState(STATE_NONE); 2200 TransitionToState(STATE_FINISH_HEADERS);
2116 return ERR_CACHE_MISS; 2201 return ERR_CACHE_MISS;
2117 } 2202 }
2118 2203
2119 if (request_->method == "HEAD") 2204 if (request_->method == "HEAD")
2120 FixHeadersForHead(); 2205 FixHeadersForHead();
2121 2206
2122 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) 2207 if (entry_->disk_entry->GetDataSize(kMetadataIndex))
2123 TransitionToState(STATE_CACHE_READ_METADATA); 2208 TransitionToState(STATE_CACHE_READ_METADATA);
2124 else 2209 else
2125 TransitionToState(STATE_NONE); 2210 TransitionToState(STATE_FINISH_HEADERS);
2126 2211
2127 return OK; 2212 return OK;
2128 } 2213 }
2129 2214
2130 int HttpCache::Transaction::BeginCacheValidation() { 2215 int HttpCache::Transaction::BeginCacheValidation() {
2131 DCHECK_EQ(mode_, READ_WRITE); 2216 DCHECK_EQ(mode_, READ_WRITE);
2132 2217
2133 ValidationType required_validation = RequiresValidation(); 2218 ValidationType required_validation = RequiresValidation();
2134 2219
2135 bool skip_validation = (required_validation == VALIDATION_NONE); 2220 bool skip_validation = (required_validation == VALIDATION_NONE);
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 if (partial_) { 2713 if (partial_) {
2629 if (truncated_ || is_sparse_ || !invalid_range_) { 2714 if (truncated_ || is_sparse_ || !invalid_range_) {
2630 // We are going to return the saved response headers to the caller, so 2715 // We are going to return the saved response headers to the caller, so
2631 // we may need to adjust them first. 2716 // we may need to adjust them first.
2632 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); 2717 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED);
2633 return OK; 2718 return OK;
2634 } else { 2719 } else {
2635 partial_.reset(); 2720 partial_.reset();
2636 } 2721 }
2637 } 2722 }
2638 cache_->ConvertWriterToReader(entry_); 2723
2639 mode_ = READ; 2724 mode_ = READ;
2640 2725
2641 if (request_->method == "HEAD") 2726 if (request_->method == "HEAD")
2642 FixHeadersForHead(); 2727 FixHeadersForHead();
2643 2728
2644 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) 2729 if (entry_->disk_entry->GetDataSize(kMetadataIndex))
2645 TransitionToState(STATE_CACHE_READ_METADATA); 2730 TransitionToState(STATE_CACHE_READ_METADATA);
2646 else 2731 else
2647 TransitionToState(STATE_NONE); 2732 TransitionToState(STATE_FINISH_HEADERS);
2648 return OK; 2733 return OK;
2649 } 2734 }
2650 2735
2651 int HttpCache::Transaction::WriteToEntry(int index, int offset, 2736 int HttpCache::Transaction::WriteToEntry(int index, int offset,
2652 IOBuffer* data, int data_len, 2737 IOBuffer* data, int data_len,
2653 const CompletionCallback& callback) { 2738 const CompletionCallback& callback) {
2654 if (!entry_) 2739 if (!entry_)
2655 return data_len; 2740 return data_len;
2656 2741
2657 int rv = 0; 2742 int rv = 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2716 } 2801 }
2717 return OK; 2802 return OK;
2718 } 2803 }
2719 2804
2720 void HttpCache::Transaction::DoneWritingToEntry(bool success) { 2805 void HttpCache::Transaction::DoneWritingToEntry(bool success) {
2721 if (!entry_) 2806 if (!entry_)
2722 return; 2807 return;
2723 2808
2724 RecordHistograms(); 2809 RecordHistograms();
2725 2810
2726 cache_->DoneWritingToEntry(entry_, success); 2811 cache_->DoneWritingToEntry(entry_, success, this);
2727 entry_ = NULL; 2812 entry_ = NULL;
2728 mode_ = NONE; // switch to 'pass through' mode 2813 mode_ = NONE; // switch to 'pass through' mode
2729 } 2814 }
2730 2815
2731 int HttpCache::Transaction::OnCacheReadError(int result, bool restart) { 2816 int HttpCache::Transaction::OnCacheReadError(int result, bool restart) {
2732 DLOG(ERROR) << "ReadData failed: " << result; 2817 DLOG(ERROR) << "ReadData failed: " << result;
2733 const int result_for_histogram = std::max(0, -result); 2818 const int result_for_histogram = std::max(0, -result);
2734 if (restart) { 2819 if (restart) {
2735 UMA_HISTOGRAM_SPARSE_SLOWLY("HttpCache.ReadErrorRestartable", 2820 UMA_HISTOGRAM_SPARSE_SLOWLY("HttpCache.ReadErrorRestartable",
2736 result_for_histogram); 2821 result_for_histogram);
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 } 3169 }
3085 3170
3086 void HttpCache::Transaction::TransitionToState(State state) { 3171 void HttpCache::Transaction::TransitionToState(State state) {
3087 // Ensure that the state is only set once per Do* state. 3172 // Ensure that the state is only set once per Do* state.
3088 DCHECK(in_do_loop_); 3173 DCHECK(in_do_loop_);
3089 DCHECK_EQ(STATE_UNSET, next_state_) << "Next state is " << state; 3174 DCHECK_EQ(STATE_UNSET, next_state_) << "Next state is " << state;
3090 next_state_ = state; 3175 next_state_ = state;
3091 } 3176 }
3092 3177
3093 } // namespace net 3178 } // 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