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

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

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

Powered by Google App Engine
This is Rietveld 408576698