OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_cache_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
6 | 6 |
7 #include "build/build_config.h" // For OS_POSIX | 7 #include "build/build_config.h" // For OS_POSIX |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 | 161 |
162 //----------------------------------------------------------------------------- | 162 //----------------------------------------------------------------------------- |
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 created_entry_(false), | |
171 new_response_(NULL), | 172 new_response_(NULL), |
172 mode_(NONE), | 173 mode_(NONE), |
174 original_mode_(NONE), | |
173 reading_(false), | 175 reading_(false), |
174 invalid_range_(false), | 176 invalid_range_(false), |
175 truncated_(false), | 177 truncated_(false), |
176 is_sparse_(false), | 178 is_sparse_(false), |
177 range_requested_(false), | 179 range_requested_(false), |
178 handling_206_(false), | 180 handling_206_(false), |
179 cache_pending_(false), | 181 cache_pending_(false), |
180 done_reading_(false), | 182 done_reading_(false), |
181 vary_mismatch_(false), | 183 vary_mismatch_(false), |
182 couldnt_conditionalize_request_(false), | 184 couldnt_conditionalize_request_(false), |
183 bypass_lock_for_test_(false), | 185 bypass_lock_for_test_(false), |
184 fail_conditionalization_for_test_(false), | 186 fail_conditionalization_for_test_(false), |
187 validating_cannot_proceed_(false), | |
185 io_buf_len_(0), | 188 io_buf_len_(0), |
186 read_offset_(0), | 189 read_offset_(0), |
187 effective_load_flags_(0), | 190 effective_load_flags_(0), |
188 write_len_(0), | 191 write_len_(0), |
189 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), | 192 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), |
190 validation_cause_(VALIDATION_CAUSE_UNDEFINED), | 193 validation_cause_(VALIDATION_CAUSE_UNDEFINED), |
191 total_received_bytes_(0), | 194 total_received_bytes_(0), |
192 total_sent_bytes_(0), | 195 total_sent_bytes_(0), |
193 websocket_handshake_stream_base_create_helper_(NULL), | 196 websocket_handshake_stream_base_create_helper_(NULL), |
194 in_do_loop_(false), | 197 in_do_loop_(false), |
195 weak_factory_(this) { | 198 weak_factory_(this) { |
196 TRACE_EVENT0("io", "HttpCacheTransaction::Transaction"); | 199 TRACE_EVENT0("io", "HttpCacheTransaction::Transaction"); |
197 static_assert(HttpCache::Transaction::kNumValidationHeaders == | 200 static_assert(HttpCache::Transaction::kNumValidationHeaders == |
198 arraysize(kValidationHeaders), | 201 arraysize(kValidationHeaders), |
199 "invalid number of validation headers"); | 202 "invalid number of validation headers"); |
200 | 203 |
201 io_callback_ = base::Bind(&Transaction::OnIOComplete, | 204 io_callback_ = base::Bind(&Transaction::OnIOComplete, |
202 weak_factory_.GetWeakPtr()); | 205 weak_factory_.GetWeakPtr()); |
203 } | 206 } |
204 | 207 |
205 HttpCache::Transaction::~Transaction() { | 208 HttpCache::Transaction::~Transaction() { |
206 TRACE_EVENT0("io", "HttpCacheTransaction::~Transaction"); | 209 TRACE_EVENT0("io", "HttpCacheTransaction::~Transaction"); |
207 // We may have to issue another IO, but we should never invoke the callback_ | 210 // We may have to issue another IO, but we should never invoke the callback_ |
208 // after this point. | 211 // after this point. |
209 callback_.Reset(); | 212 callback_.Reset(); |
210 | 213 |
211 if (cache_) { | 214 if (cache_) { |
212 if (entry_) { | 215 if (entry_) { |
213 bool cancel_request = reading_ && response_.headers.get(); | 216 // TODO(shivanisha): A lot of tests invoke Read on a HEAD request which |
217 // should not be allowed in the Read() method. Fix those tests and then | |
218 // the check for method below need not exist. | |
219 bool cancel_request = reading_ && response_.headers.get() && | |
220 (request_ && request_->method != "HEAD"); | |
214 if (cancel_request) { | 221 if (cancel_request) { |
215 if (partial_) { | 222 if (partial_) { |
216 entry_->disk_entry->CancelSparseIO(); | 223 entry_->disk_entry->CancelSparseIO(); |
217 } else { | 224 } else { |
218 cancel_request &= (response_.headers->response_code() == 200); | 225 cancel_request &= (response_.headers->response_code() == 200); |
219 } | 226 } |
220 } | 227 } |
221 | 228 |
229 // If this transaction created the entry and not yet started the response | |
230 // body phase, then it is a cancellation. | |
231 if (!cancel_request) | |
jkarlin
2017/03/23 18:37:38
Looks like cancel_request can't be true if !readin
shivanisha
2017/03/29 03:39:30
N/A after the changes
| |
232 cancel_request = !reading_ && created_entry_ && | |
jkarlin
2017/03/23 18:37:38
I find cancel_request hinging on whether we create
shivanisha
2017/03/29 03:39:30
Removed cancel_request and changed the conditional
shivanisha
2017/03/29 03:41:42
*Removed created_request ...
| |
233 (request_ && request_->method != "HEAD"); | |
234 | |
222 cache_->DoneWithEntry(entry_, this, cancel_request); | 235 cache_->DoneWithEntry(entry_, this, cancel_request); |
223 } else if (cache_pending_) { | 236 } else if (cache_pending_) { |
224 cache_->RemovePendingTransaction(this); | 237 cache_->RemovePendingTransaction(this); |
225 } | 238 } |
226 } | 239 } |
227 } | 240 } |
228 | 241 |
229 int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len, | 242 int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len, |
230 const CompletionCallback& callback) { | 243 const CompletionCallback& callback) { |
231 DCHECK(buf); | 244 DCHECK(buf); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 ConnectionAttempts* out) const { | 585 ConnectionAttempts* out) const { |
573 ConnectionAttempts new_connection_attempts; | 586 ConnectionAttempts new_connection_attempts; |
574 if (network_trans_) | 587 if (network_trans_) |
575 network_trans_->GetConnectionAttempts(&new_connection_attempts); | 588 network_trans_->GetConnectionAttempts(&new_connection_attempts); |
576 | 589 |
577 out->swap(new_connection_attempts); | 590 out->swap(new_connection_attempts); |
578 out->insert(out->begin(), old_connection_attempts_.begin(), | 591 out->insert(out->begin(), old_connection_attempts_.begin(), |
579 old_connection_attempts_.end()); | 592 old_connection_attempts_.end()); |
580 } | 593 } |
581 | 594 |
595 void HttpCache::Transaction::SetValidatingCannotProceed() { | |
596 validating_cannot_proceed_ = true; | |
597 entry_ = nullptr; | |
598 } | |
599 | |
582 size_t HttpCache::Transaction::EstimateMemoryUsage() const { | 600 size_t HttpCache::Transaction::EstimateMemoryUsage() const { |
583 // TODO(xunjieli): Consider improving the coverage. crbug.com/669108. | 601 // TODO(xunjieli): Consider improving the coverage. crbug.com/669108. |
584 return 0; | 602 return 0; |
585 } | 603 } |
586 | 604 |
587 //----------------------------------------------------------------------------- | 605 //----------------------------------------------------------------------------- |
588 | 606 |
589 // A few common patterns: (Foo* means Foo -> FooComplete) | 607 // A few common patterns: (Foo* means Foo -> FooComplete) |
590 // | 608 // |
591 // 1. Not-cached entry: | 609 // 1. Not-cached entry: |
592 // Start(): | 610 // Start(): |
593 // GetBackend* -> InitEntry -> OpenEntry* -> CreateEntry* -> AddToEntry* -> | 611 // GetBackend* -> InitEntry -> OpenEntry* -> CreateEntry* -> AddToEntry* -> |
594 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> | 612 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> |
595 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> | 613 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> |
596 // PartialHeadersReceived | 614 // PartialHeadersReceived |
597 // | 615 // |
598 // Read(): | 616 // Read(): |
599 // NetworkRead* -> CacheWriteData* | 617 // NetworkRead* -> CacheWriteData* |
600 // | 618 // |
601 // 2. Cached entry, no validation: | 619 // 2. Cached entry, no validation: |
602 // Start(): | 620 // Start(): |
603 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 621 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
604 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> | 622 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> |
605 // BeginCacheValidation() -> SetupEntryForRead() | 623 // BeginCacheValidation() -> SetupEntryForRead() -> WaitBeforeRead* |
606 // | 624 // |
607 // Read(): | 625 // Read(): |
608 // CacheReadData* | 626 // CacheReadData* |
609 // | 627 // |
610 // 3. Cached entry, validation (304): | 628 // 3. Cached entry, validation (304): |
611 // Start(): | 629 // Start(): |
612 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 630 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
613 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> | 631 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> |
614 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> | 632 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> |
615 // UpdateCachedResponse -> CacheWriteUpdatedResponse* -> | 633 // UpdateCachedResponse -> CacheWriteUpdatedResponse* -> |
616 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> | 634 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> |
617 // PartialHeadersReceived | 635 // PartialHeadersReceived -> WaitBeforeRead* |
618 // | 636 // |
619 // Read(): | 637 // Read(): |
620 // CacheReadData* | 638 // CacheReadData* |
621 // | 639 // |
622 // 4. Cached entry, validation and replace (200): | 640 // 4. Cached entry, validation and replace (200): |
623 // Start(): | 641 // Start(): |
624 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 642 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
625 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> | 643 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> |
626 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> | 644 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> |
627 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* -> | 645 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* -> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 // | 730 // |
713 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true: | 731 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true: |
714 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between | 732 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between |
715 // CacheReadResponse* and CacheDispatchValidation. | 733 // CacheReadResponse* and CacheDispatchValidation. |
716 int HttpCache::Transaction::DoLoop(int result) { | 734 int HttpCache::Transaction::DoLoop(int result) { |
717 DCHECK_NE(STATE_UNSET, next_state_); | 735 DCHECK_NE(STATE_UNSET, next_state_); |
718 DCHECK_NE(STATE_NONE, next_state_); | 736 DCHECK_NE(STATE_NONE, next_state_); |
719 DCHECK(!in_do_loop_); | 737 DCHECK(!in_do_loop_); |
720 | 738 |
721 int rv = result; | 739 int rv = result; |
740 State state = next_state_; | |
722 do { | 741 do { |
723 State state = next_state_; | 742 state = next_state_; |
724 next_state_ = STATE_UNSET; | 743 next_state_ = STATE_UNSET; |
725 base::AutoReset<bool> scoped_in_do_loop(&in_do_loop_, true); | 744 base::AutoReset<bool> scoped_in_do_loop(&in_do_loop_, true); |
726 | 745 |
727 switch (state) { | 746 switch (state) { |
728 case STATE_GET_BACKEND: | 747 case STATE_GET_BACKEND: |
729 DCHECK_EQ(OK, rv); | 748 DCHECK_EQ(OK, rv); |
730 rv = DoGetBackend(); | 749 rv = DoGetBackend(); |
731 break; | 750 break; |
732 case STATE_GET_BACKEND_COMPLETE: | 751 case STATE_GET_BACKEND_COMPLETE: |
733 rv = DoGetBackendComplete(rv); | 752 rv = DoGetBackendComplete(rv); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 DCHECK_EQ(OK, rv); | 869 DCHECK_EQ(OK, rv); |
851 rv = DoPartialHeadersReceived(); | 870 rv = DoPartialHeadersReceived(); |
852 break; | 871 break; |
853 case STATE_CACHE_READ_METADATA: | 872 case STATE_CACHE_READ_METADATA: |
854 DCHECK_EQ(OK, rv); | 873 DCHECK_EQ(OK, rv); |
855 rv = DoCacheReadMetadata(); | 874 rv = DoCacheReadMetadata(); |
856 break; | 875 break; |
857 case STATE_CACHE_READ_METADATA_COMPLETE: | 876 case STATE_CACHE_READ_METADATA_COMPLETE: |
858 rv = DoCacheReadMetadataComplete(rv); | 877 rv = DoCacheReadMetadataComplete(rv); |
859 break; | 878 break; |
879 case STATE_WAIT_BEFORE_READ: | |
880 DCHECK_EQ(OK, rv); | |
881 rv = DoWaitBeforeRead(); | |
882 break; | |
883 case STATE_WAIT_BEFORE_READ_COMPLETE: | |
884 rv = DoWaitBeforeReadComplete(rv); | |
885 break; | |
860 case STATE_NETWORK_READ: | 886 case STATE_NETWORK_READ: |
861 DCHECK_EQ(OK, rv); | 887 DCHECK_EQ(OK, rv); |
862 rv = DoNetworkRead(); | 888 rv = DoNetworkRead(); |
863 break; | 889 break; |
864 case STATE_NETWORK_READ_COMPLETE: | 890 case STATE_NETWORK_READ_COMPLETE: |
865 rv = DoNetworkReadComplete(rv); | 891 rv = DoNetworkReadComplete(rv); |
866 break; | 892 break; |
867 case STATE_CACHE_READ_DATA: | 893 case STATE_CACHE_READ_DATA: |
868 DCHECK_EQ(OK, rv); | 894 DCHECK_EQ(OK, rv); |
869 rv = DoCacheReadData(); | 895 rv = DoCacheReadData(); |
(...skipping 16 matching lines...) Expand all Loading... | |
886 break; | 912 break; |
887 default: | 913 default: |
888 NOTREACHED() << "bad state " << state; | 914 NOTREACHED() << "bad state " << state; |
889 rv = ERR_FAILED; | 915 rv = ERR_FAILED; |
890 break; | 916 break; |
891 } | 917 } |
892 DCHECK(next_state_ != STATE_UNSET) << "Previous state was " << state; | 918 DCHECK(next_state_ != STATE_UNSET) << "Previous state was " << state; |
893 | 919 |
894 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 920 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
895 | 921 |
922 // Assert Start() state machine allowed exit state. | |
923 if (!reading_ && rv == OK) { | |
924 DCHECK(!entry_ || state == STATE_WAIT_BEFORE_READ_COMPLETE); | |
925 } | |
926 | |
896 if (rv != ERR_IO_PENDING && !callback_.is_null()) { | 927 if (rv != ERR_IO_PENDING && !callback_.is_null()) { |
897 read_buf_ = NULL; // Release the buffer before invoking the callback. | 928 read_buf_ = nullptr; // Release the buffer before invoking the callback. |
898 base::ResetAndReturn(&callback_).Run(rv); | 929 base::ResetAndReturn(&callback_).Run(rv); |
899 } | 930 } |
900 | 931 |
901 return rv; | 932 return rv; |
902 } | 933 } |
903 | 934 |
904 int HttpCache::Transaction::DoGetBackend() { | 935 int HttpCache::Transaction::DoGetBackend() { |
905 cache_pending_ = true; | 936 cache_pending_ = true; |
906 TransitionToState(STATE_GET_BACKEND_COMPLETE); | 937 TransitionToState(STATE_GET_BACKEND_COMPLETE); |
907 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND); | 938 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
969 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1000 partial_->RestoreHeaders(&custom_request_->extra_headers); |
970 partial_.reset(); | 1001 partial_.reset(); |
971 } | 1002 } |
972 TransitionToState(STATE_SEND_REQUEST); | 1003 TransitionToState(STATE_SEND_REQUEST); |
973 } else { | 1004 } else { |
974 TransitionToState(STATE_INIT_ENTRY); | 1005 TransitionToState(STATE_INIT_ENTRY); |
975 } | 1006 } |
976 | 1007 |
977 // This is only set if we have something to do with the response. | 1008 // This is only set if we have something to do with the response. |
978 range_requested_ = (partial_.get() != NULL); | 1009 range_requested_ = (partial_.get() != NULL); |
979 | 1010 original_mode_ = mode_; |
980 return OK; | 1011 return OK; |
981 } | 1012 } |
982 | 1013 |
983 int HttpCache::Transaction::DoInitEntry() { | 1014 int HttpCache::Transaction::DoInitEntry() { |
984 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); | 1015 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); |
985 DCHECK(!new_entry_); | 1016 DCHECK(!new_entry_); |
986 | 1017 |
987 if (!cache_.get()) { | 1018 if (!cache_.get()) { |
988 TransitionToState(STATE_NONE); | 1019 TransitionToState(STATE_NONE); |
989 return ERR_UNEXPECTED; | 1020 return ERR_UNEXPECTED; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1084 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 1115 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
1085 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete"); | 1116 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete"); |
1086 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 1117 // 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 | 1118 // OK, otherwise the cache will end up with an active entry without any |
1088 // transaction attached. | 1119 // transaction attached. |
1089 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, | 1120 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, |
1090 result); | 1121 result); |
1091 cache_pending_ = false; | 1122 cache_pending_ = false; |
1092 switch (result) { | 1123 switch (result) { |
1093 case OK: | 1124 case OK: |
1125 created_entry_ = true; | |
1094 TransitionToState(STATE_ADD_TO_ENTRY); | 1126 TransitionToState(STATE_ADD_TO_ENTRY); |
1095 break; | 1127 break; |
1096 | 1128 |
1097 case ERR_CACHE_RACE: | 1129 case ERR_CACHE_RACE: |
1098 TransitionToState(STATE_INIT_ENTRY); | 1130 TransitionToState(STATE_INIT_ENTRY); |
1099 break; | 1131 break; |
1100 | 1132 |
1101 default: | 1133 default: |
1102 // We have a race here: Maybe we failed to open the entry and decided to | 1134 // 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 | 1135 // create one, but by the time we called create, another transaction |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1347 TransitionToState(STATE_NONE); | 1379 TransitionToState(STATE_NONE); |
1348 return ERR_UNEXPECTED; | 1380 return ERR_UNEXPECTED; |
1349 } | 1381 } |
1350 | 1382 |
1351 return ValidateEntryHeadersAndContinue(); | 1383 return ValidateEntryHeadersAndContinue(); |
1352 } | 1384 } |
1353 | 1385 |
1354 // We may end up here multiple times for a given request. | 1386 // We may end up here multiple times for a given request. |
1355 int HttpCache::Transaction::DoStartPartialCacheValidation() { | 1387 int HttpCache::Transaction::DoStartPartialCacheValidation() { |
1356 if (mode_ == NONE) { | 1388 if (mode_ == NONE) { |
1357 TransitionToState(STATE_NONE); | 1389 if (!reading_) |
1390 TransitionToState(STATE_WAIT_BEFORE_READ); | |
1391 else | |
1392 TransitionToState(STATE_NONE); | |
1358 return OK; | 1393 return OK; |
1359 } | 1394 } |
1360 | 1395 |
1361 TransitionToState(STATE_COMPLETE_PARTIAL_CACHE_VALIDATION); | 1396 TransitionToState(STATE_COMPLETE_PARTIAL_CACHE_VALIDATION); |
1362 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); | 1397 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); |
1363 } | 1398 } |
1364 | 1399 |
1365 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { | 1400 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { |
1366 if (!result) { | 1401 if (!result) { |
1367 // This is the end of the request. | 1402 // This is the end of the request. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 // We received the response headers and there is no error. | 1497 // We received the response headers and there is no error. |
1463 int HttpCache::Transaction::DoSuccessfulSendRequest() { | 1498 int HttpCache::Transaction::DoSuccessfulSendRequest() { |
1464 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest"); | 1499 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest"); |
1465 DCHECK(!new_response_); | 1500 DCHECK(!new_response_); |
1466 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 1501 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
1467 | 1502 |
1468 if (new_response->headers->response_code() == 401 || | 1503 if (new_response->headers->response_code() == 401 || |
1469 new_response->headers->response_code() == 407) { | 1504 new_response->headers->response_code() == 407) { |
1470 SetAuthResponse(*new_response); | 1505 SetAuthResponse(*new_response); |
1471 if (!reading_) { | 1506 if (!reading_) { |
1472 TransitionToState(STATE_NONE); | 1507 TransitionToState(STATE_WAIT_BEFORE_READ); |
1473 return OK; | 1508 return OK; |
1474 } | 1509 } |
1475 | 1510 |
1476 // We initiated a second request the caller doesn't know about. We should be | 1511 // 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 | 1512 // able to authenticate this request because we should have authenticated |
1478 // this URL moments ago. | 1513 // this URL moments ago. |
1479 if (IsReadyToRestartForAuth()) { | 1514 if (IsReadyToRestartForAuth()) { |
1480 DCHECK(!response_.auth_challenge.get()); | 1515 DCHECK(!response_.auth_challenge.get()); |
1481 TransitionToState(STATE_SEND_REQUEST_COMPLETE); | 1516 TransitionToState(STATE_SEND_REQUEST_COMPLETE); |
1482 // In theory we should check to see if there are new cookies, but there | 1517 // In theory we should check to see if there are new cookies, but there |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1525 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_NOT_IN_CACHE); | 1560 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_NOT_IN_CACHE); |
1526 } | 1561 } |
1527 | 1562 |
1528 // Invalidate any cached GET with a successful PUT or DELETE. | 1563 // Invalidate any cached GET with a successful PUT or DELETE. |
1529 if (mode_ == WRITE && | 1564 if (mode_ == WRITE && |
1530 (request_->method == "PUT" || request_->method == "DELETE")) { | 1565 (request_->method == "PUT" || request_->method == "DELETE")) { |
1531 if (NonErrorResponse(new_response->headers->response_code())) { | 1566 if (NonErrorResponse(new_response->headers->response_code())) { |
1532 int ret = cache_->DoomEntry(cache_key_, NULL); | 1567 int ret = cache_->DoomEntry(cache_key_, NULL); |
1533 DCHECK_EQ(OK, ret); | 1568 DCHECK_EQ(OK, ret); |
1534 } | 1569 } |
1535 cache_->DoneWritingToEntry(entry_, true); | 1570 cache_->DoneWritingToEntry(entry_, true, this); |
1536 entry_ = NULL; | 1571 entry_ = NULL; |
1537 mode_ = NONE; | 1572 mode_ = NONE; |
1538 } | 1573 } |
1539 | 1574 |
1540 // Invalidate any cached GET with a successful POST. | 1575 // Invalidate any cached GET with a successful POST. |
1541 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) && | 1576 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) && |
1542 request_->method == "POST" && | 1577 request_->method == "POST" && |
1543 NonErrorResponse(new_response->headers->response_code())) { | 1578 NonErrorResponse(new_response->headers->response_code())) { |
1544 cache_->DoomMainEntryForUrl(request_->url); | 1579 cache_->DoomMainEntryForUrl(request_->url); |
1545 } | 1580 } |
1546 | 1581 |
1547 RecordNoStoreHeaderHistogram(request_->load_flags, new_response); | 1582 RecordNoStoreHeaderHistogram(request_->load_flags, new_response); |
1548 | 1583 |
1549 if (new_response_->headers->response_code() == 416 && | 1584 if (new_response_->headers->response_code() == 416 && |
1550 (request_->method == "GET" || request_->method == "POST")) { | 1585 (request_->method == "GET" || request_->method == "POST")) { |
1551 // If there is an active entry it may be destroyed with this transaction. | 1586 // If there is an active entry it may be destroyed with this transaction. |
1552 SetResponse(*new_response_); | 1587 SetResponse(*new_response_); |
1553 TransitionToState(STATE_NONE); | 1588 if (!reading_) |
jkarlin
2017/03/23 18:37:38
prefer ternay here and the other cases like this:
shivanisha
2017/03/29 03:39:30
Done
| |
1589 TransitionToState(STATE_WAIT_BEFORE_READ); | |
1590 else | |
1591 TransitionToState(STATE_NONE); | |
1554 return OK; | 1592 return OK; |
1555 } | 1593 } |
1556 | 1594 |
1557 // Are we expecting a response to a conditional query? | 1595 // Are we expecting a response to a conditional query? |
1558 if (mode_ == READ_WRITE || mode_ == UPDATE) { | 1596 if (mode_ == READ_WRITE || mode_ == UPDATE) { |
1559 if (new_response->headers->response_code() == 304 || handling_206_) { | 1597 if (new_response->headers->response_code() == 304 || handling_206_) { |
1560 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED); | 1598 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED); |
1561 TransitionToState(STATE_UPDATE_CACHED_RESPONSE); | 1599 TransitionToState(STATE_UPDATE_CACHED_RESPONSE); |
1562 return OK; | 1600 return OK; |
1563 } | 1601 } |
1564 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); | 1602 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); |
1565 mode_ = WRITE; | 1603 mode_ = WRITE; |
1566 } | 1604 } |
1567 | 1605 |
1568 TransitionToState(STATE_OVERWRITE_CACHED_RESPONSE); | 1606 TransitionToState(STATE_OVERWRITE_CACHED_RESPONSE); |
1607 | |
1608 if (!entry_) | |
1609 return OK; | |
1610 | |
1611 // Invalidate any current entry with a successful response if this transaction | |
1612 // cannot write to this entry. | |
1613 if (new_response->headers->response_code() != 304 && | |
jkarlin
2017/03/23 18:37:38
How do we know this transaction can't write to thi
shivanisha
2017/03/29 03:39:30
It cannot write to the entry because either a writ
| |
1614 (entry_->writer || !entry_->readers.empty())) { | |
1615 DCHECK_EQ(entry_->headers_transaction, this); | |
1616 cache_->DoneResponseHeaders(entry_, this, false); | |
1617 entry_ = nullptr; | |
1618 mode_ = NONE; | |
1619 return OK; | |
1620 } | |
1621 | |
1569 return OK; | 1622 return OK; |
1570 } | 1623 } |
1571 | 1624 |
1572 // We received 304 or 206 and we want to update the cached response headers. | 1625 // We received 304 or 206 and we want to update the cached response headers. |
1573 int HttpCache::Transaction::DoUpdateCachedResponse() { | 1626 int HttpCache::Transaction::DoUpdateCachedResponse() { |
1574 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse"); | 1627 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse"); |
1575 int rv = OK; | 1628 int rv = OK; |
1576 // Update the cached response based on the headers and properties of | 1629 // Update the cached response based on the headers and properties of |
1577 // new_response_. | 1630 // new_response_. |
1578 response_.headers->Update(*new_response_->headers.get()); | 1631 response_.headers->Update(*new_response_->headers.get()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1631 DCHECK(!handling_206_); | 1684 DCHECK(!handling_206_); |
1632 // We got a "not modified" response and already updated the corresponding | 1685 // We got a "not modified" response and already updated the corresponding |
1633 // cache entry above. | 1686 // cache entry above. |
1634 // | 1687 // |
1635 // By closing the cached entry now, we make sure that the 304 rather than | 1688 // 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. | 1689 // the cached 200 response, is what will be returned to the user. |
1637 DoneWritingToEntry(true); | 1690 DoneWritingToEntry(true); |
1638 } else if (entry_ && !handling_206_) { | 1691 } else if (entry_ && !handling_206_) { |
1639 DCHECK_EQ(READ_WRITE, mode_); | 1692 DCHECK_EQ(READ_WRITE, mode_); |
1640 if (!partial_ || partial_->IsLastRange()) { | 1693 if (!partial_ || partial_->IsLastRange()) { |
1641 cache_->ConvertWriterToReader(entry_); | |
1642 mode_ = READ; | 1694 mode_ = READ; |
1643 } | 1695 } |
1644 // We no longer need the network transaction, so destroy it. | 1696 // We no longer need the network transaction, so destroy it. |
1645 ResetNetworkTransaction(); | 1697 ResetNetworkTransaction(); |
1646 } else if (entry_ && handling_206_ && truncated_ && | 1698 } else if (entry_ && handling_206_ && truncated_ && |
1647 partial_->initial_validation()) { | 1699 partial_->initial_validation()) { |
1648 // We just finished the validation of a truncated entry, and the server | 1700 // 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 | 1701 // is willing to resume the operation. Now we go back and start serving |
1650 // the first part to the user. | 1702 // the first part to the user. |
1651 ResetNetworkTransaction(); | 1703 ResetNetworkTransaction(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1751 } | 1803 } |
1752 | 1804 |
1753 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); | 1805 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); |
1754 return OK; | 1806 return OK; |
1755 } | 1807 } |
1756 | 1808 |
1757 int HttpCache::Transaction::DoPartialHeadersReceived() { | 1809 int HttpCache::Transaction::DoPartialHeadersReceived() { |
1758 new_response_ = NULL; | 1810 new_response_ = NULL; |
1759 | 1811 |
1760 if (!partial_) { | 1812 if (!partial_) { |
1761 if (entry_ && entry_->disk_entry->GetDataSize(kMetadataIndex)) | 1813 if (entry_ && entry_->disk_entry->GetDataSize(kMetadataIndex)) { |
1762 TransitionToState(STATE_CACHE_READ_METADATA); | 1814 TransitionToState(STATE_CACHE_READ_METADATA); |
1763 else | 1815 } else { |
1764 TransitionToState(STATE_NONE); | 1816 DCHECK(!reading_); |
1817 TransitionToState(STATE_WAIT_BEFORE_READ); | |
1818 } | |
1765 return OK; | 1819 return OK; |
1766 } | 1820 } |
1767 | 1821 |
1768 if (reading_) { | 1822 if (reading_) { |
1769 if (network_trans_.get()) { | 1823 if (network_trans_.get()) { |
1770 TransitionToState(STATE_NETWORK_READ); | 1824 TransitionToState(STATE_NETWORK_READ); |
1771 } else { | 1825 } else { |
1772 TransitionToState(STATE_CACHE_READ_DATA); | 1826 TransitionToState(STATE_CACHE_READ_DATA); |
1773 } | 1827 } |
1774 } else if (mode_ != NONE) { | 1828 } else if (mode_ != NONE) { |
1775 // We are about to return the headers for a byte-range request to the user, | 1829 // We are about to return the headers for a byte-range request to the user, |
1776 // so let's fix them. | 1830 // so let's fix them. |
1777 partial_->FixResponseHeaders(response_.headers.get(), true); | 1831 partial_->FixResponseHeaders(response_.headers.get(), true); |
1778 TransitionToState(STATE_NONE); | 1832 TransitionToState(STATE_WAIT_BEFORE_READ); |
1779 } else { | 1833 } else { |
1780 TransitionToState(STATE_NONE); | 1834 TransitionToState(STATE_WAIT_BEFORE_READ); |
1781 } | 1835 } |
1782 return OK; | 1836 return OK; |
1783 } | 1837 } |
1784 | 1838 |
1839 int HttpCache::Transaction::DoWaitBeforeRead() { | |
1840 if (!entry_) { | |
1841 TransitionToState(STATE_NONE); | |
1842 return OK; | |
1843 } | |
1844 | |
1845 // A transaction comes here between the completion of headers phase and the | |
1846 // start of response body phase, thus it should never be the active writer at | |
1847 // this point. | |
1848 DCHECK_NE(entry_->writer, this); | |
1849 | |
1850 TransitionToState(STATE_WAIT_BEFORE_READ_COMPLETE); | |
1851 | |
1852 // If it was an auth failure or 416, this transaction should continue to be | |
1853 // headers_transaction till consumer takes an action, so no need to do | |
1854 // anything now. | |
1855 if (auth_response_.headers.get() || | |
1856 (new_response_ && new_response_->headers && | |
1857 new_response_->headers->response_code() == 416)) | |
1858 return OK; | |
1859 | |
1860 // If there is no response body to be written or read, it does not need to | |
1861 // wait. | |
1862 if (request_->method == "HEAD") | |
1863 return OK; | |
1864 | |
1865 // Proceed only if |this| completed the headers phase. For read-only | |
1866 // transactions since they do not have a headers phase, they would have | |
1867 // already been added to entry_->readers, so do nothing. | |
1868 if (entry_->headers_transaction == this) | |
1869 return cache_->DoneResponseHeaders(entry_, this, true); | |
1870 | |
1871 return OK; | |
1872 } | |
1873 | |
1874 int HttpCache::Transaction::DoWaitBeforeReadComplete(int rv) { | |
1875 if (rv == ERR_CACHE_RACE) { | |
1876 RestartAfterValidationStarted(); | |
1877 return OK; | |
1878 } | |
1879 | |
1880 TransitionToState(STATE_NONE); | |
1881 if (rv != OK) | |
1882 return rv; | |
1883 | |
1884 // If successful then this must be either be the writer or a reader as the | |
1885 // response must have completely been written to the cache. | |
1886 if (entry_->writer == this) | |
1887 return OK; | |
1888 | |
1889 // If it was an auth failure or 416, this transaction should continue to be | |
1890 // headers_transaction, so no need to do anything now. | |
1891 if (auth_response_.headers.get() || | |
1892 (new_response_ && new_response_->headers && | |
1893 new_response_->headers->response_code() == 416)) { | |
1894 DCHECK_EQ(entry_->headers_transaction, this); | |
1895 return OK; | |
1896 } | |
1897 | |
1898 mode_ = READ; | |
1899 if (network_trans_) | |
1900 ResetNetworkTransaction(); | |
1901 return OK; | |
1902 } | |
1903 | |
1904 void HttpCache::Transaction::RestartAfterValidationStarted() { | |
1905 DCHECK(!reading_); | |
1906 next_state_ = STATE_INIT_ENTRY; | |
1907 cache_entry_status_ = CacheEntryStatus::ENTRY_UNDEFINED; | |
1908 entry_ = nullptr; | |
1909 mode_ = original_mode_; | |
1910 if (network_trans_) | |
1911 network_trans_.reset(); | |
1912 } | |
1913 | |
1785 int HttpCache::Transaction::DoCacheReadMetadata() { | 1914 int HttpCache::Transaction::DoCacheReadMetadata() { |
1786 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); | 1915 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); |
1787 DCHECK(entry_); | 1916 DCHECK(entry_); |
1788 DCHECK(!response_.metadata.get()); | 1917 DCHECK(!response_.metadata.get()); |
1789 TransitionToState(STATE_CACHE_READ_METADATA_COMPLETE); | 1918 TransitionToState(STATE_CACHE_READ_METADATA_COMPLETE); |
1790 | 1919 |
1791 response_.metadata = | 1920 response_.metadata = |
1792 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1921 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
1793 | 1922 |
1794 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1923 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
1795 return entry_->disk_entry->ReadData(kMetadataIndex, 0, | 1924 return entry_->disk_entry->ReadData(kMetadataIndex, 0, |
1796 response_.metadata.get(), | 1925 response_.metadata.get(), |
1797 response_.metadata->size(), | 1926 response_.metadata->size(), |
1798 io_callback_); | 1927 io_callback_); |
1799 } | 1928 } |
1800 | 1929 |
1801 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1930 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
1802 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete"); | 1931 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete"); |
1803 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, | 1932 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, |
1804 result); | 1933 result); |
1805 if (result != response_.metadata->size()) | 1934 if (result != response_.metadata->size()) |
1806 return OnCacheReadError(result, false); | 1935 return OnCacheReadError(result, false); |
1807 TransitionToState(STATE_NONE); | 1936 |
1937 if (!reading_) | |
1938 TransitionToState(STATE_WAIT_BEFORE_READ); | |
1939 else | |
1940 TransitionToState(STATE_NONE); | |
1808 return OK; | 1941 return OK; |
1809 } | 1942 } |
1810 | 1943 |
1811 int HttpCache::Transaction::DoNetworkRead() { | 1944 int HttpCache::Transaction::DoNetworkRead() { |
1812 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead"); | 1945 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead"); |
1813 TransitionToState(STATE_NETWORK_READ_COMPLETE); | 1946 TransitionToState(STATE_NETWORK_READ_COMPLETE); |
1814 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); | 1947 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); |
1815 } | 1948 } |
1816 | 1949 |
1817 int HttpCache::Transaction::DoNetworkReadComplete(int result) { | 1950 int HttpCache::Transaction::DoNetworkReadComplete(int result) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2114 if (RequiresValidation() != VALIDATION_NONE) { | 2247 if (RequiresValidation() != VALIDATION_NONE) { |
2115 TransitionToState(STATE_NONE); | 2248 TransitionToState(STATE_NONE); |
2116 return ERR_CACHE_MISS; | 2249 return ERR_CACHE_MISS; |
2117 } | 2250 } |
2118 | 2251 |
2119 if (request_->method == "HEAD") | 2252 if (request_->method == "HEAD") |
2120 FixHeadersForHead(); | 2253 FixHeadersForHead(); |
2121 | 2254 |
2122 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) | 2255 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
2123 TransitionToState(STATE_CACHE_READ_METADATA); | 2256 TransitionToState(STATE_CACHE_READ_METADATA); |
2257 else if (!reading_) | |
2258 TransitionToState(STATE_WAIT_BEFORE_READ); | |
2124 else | 2259 else |
2125 TransitionToState(STATE_NONE); | 2260 TransitionToState(STATE_NONE); |
2126 | 2261 |
2127 return OK; | 2262 return OK; |
2128 } | 2263 } |
2129 | 2264 |
2130 int HttpCache::Transaction::BeginCacheValidation() { | 2265 int HttpCache::Transaction::BeginCacheValidation() { |
2131 DCHECK_EQ(mode_, READ_WRITE); | 2266 DCHECK_EQ(mode_, READ_WRITE); |
2132 | 2267 |
2133 ValidationType required_validation = RequiresValidation(); | 2268 ValidationType required_validation = RequiresValidation(); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2628 if (partial_) { | 2763 if (partial_) { |
2629 if (truncated_ || is_sparse_ || !invalid_range_) { | 2764 if (truncated_ || is_sparse_ || !invalid_range_) { |
2630 // We are going to return the saved response headers to the caller, so | 2765 // We are going to return the saved response headers to the caller, so |
2631 // we may need to adjust them first. | 2766 // we may need to adjust them first. |
2632 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); | 2767 TransitionToState(STATE_PARTIAL_HEADERS_RECEIVED); |
2633 return OK; | 2768 return OK; |
2634 } else { | 2769 } else { |
2635 partial_.reset(); | 2770 partial_.reset(); |
2636 } | 2771 } |
2637 } | 2772 } |
2638 cache_->ConvertWriterToReader(entry_); | 2773 |
2774 // This might or might not be able to add it as an active reader based on | |
2775 // whether this is the active writer or not. If not, it will be added to a | |
2776 // wait queue in DoWaitBeforeRead. | |
2639 mode_ = READ; | 2777 mode_ = READ; |
2640 | 2778 |
2641 if (request_->method == "HEAD") | 2779 if (request_->method == "HEAD") |
2642 FixHeadersForHead(); | 2780 FixHeadersForHead(); |
2643 | 2781 |
2644 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) | 2782 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
2645 TransitionToState(STATE_CACHE_READ_METADATA); | 2783 TransitionToState(STATE_CACHE_READ_METADATA); |
2784 else if (!reading_) | |
2785 TransitionToState(STATE_WAIT_BEFORE_READ); | |
2646 else | 2786 else |
2647 TransitionToState(STATE_NONE); | 2787 TransitionToState(STATE_NONE); |
2648 return OK; | 2788 return OK; |
2649 } | 2789 } |
2650 | 2790 |
2651 int HttpCache::Transaction::WriteToEntry(int index, int offset, | 2791 int HttpCache::Transaction::WriteToEntry(int index, int offset, |
2652 IOBuffer* data, int data_len, | 2792 IOBuffer* data, int data_len, |
2653 const CompletionCallback& callback) { | 2793 const CompletionCallback& callback) { |
2654 if (!entry_) | 2794 if (!entry_) |
2655 return data_len; | 2795 return data_len; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2716 } | 2856 } |
2717 return OK; | 2857 return OK; |
2718 } | 2858 } |
2719 | 2859 |
2720 void HttpCache::Transaction::DoneWritingToEntry(bool success) { | 2860 void HttpCache::Transaction::DoneWritingToEntry(bool success) { |
2721 if (!entry_) | 2861 if (!entry_) |
2722 return; | 2862 return; |
2723 | 2863 |
2724 RecordHistograms(); | 2864 RecordHistograms(); |
2725 | 2865 |
2726 cache_->DoneWritingToEntry(entry_, success); | 2866 cache_->DoneWritingToEntry(entry_, success, this); |
2727 entry_ = NULL; | 2867 entry_ = NULL; |
2728 mode_ = NONE; // switch to 'pass through' mode | 2868 mode_ = NONE; // switch to 'pass through' mode |
2729 } | 2869 } |
2730 | 2870 |
2731 int HttpCache::Transaction::OnCacheReadError(int result, bool restart) { | 2871 int HttpCache::Transaction::OnCacheReadError(int result, bool restart) { |
2732 DLOG(ERROR) << "ReadData failed: " << result; | 2872 DLOG(ERROR) << "ReadData failed: " << result; |
2733 const int result_for_histogram = std::max(0, -result); | 2873 const int result_for_histogram = std::max(0, -result); |
2734 if (restart) { | 2874 if (restart) { |
2735 UMA_HISTOGRAM_SPARSE_SLOWLY("HttpCache.ReadErrorRestartable", | 2875 UMA_HISTOGRAM_SPARSE_SLOWLY("HttpCache.ReadErrorRestartable", |
2736 result_for_histogram); | 2876 result_for_histogram); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3073 UMA_HISTOGRAM_PERCENTAGE("HttpCache.PercentBeforeSend.Updated", | 3213 UMA_HISTOGRAM_PERCENTAGE("HttpCache.PercentBeforeSend.Updated", |
3074 before_send_sample); | 3214 before_send_sample); |
3075 break; | 3215 break; |
3076 } | 3216 } |
3077 default: | 3217 default: |
3078 NOTREACHED(); | 3218 NOTREACHED(); |
3079 } | 3219 } |
3080 } | 3220 } |
3081 | 3221 |
3082 void HttpCache::Transaction::OnIOComplete(int result) { | 3222 void HttpCache::Transaction::OnIOComplete(int result) { |
3223 // If its the Start state machine and it cannot proceed due to failure by | |
3224 // another transaction in writing the response, restart this transaction. | |
3225 if (!reading_ && validating_cannot_proceed_) { | |
3226 validating_cannot_proceed_ = false; | |
3227 RestartAfterValidationStarted(); | |
3228 } | |
3229 | |
3083 DoLoop(result); | 3230 DoLoop(result); |
3084 } | 3231 } |
3085 | 3232 |
3086 void HttpCache::Transaction::TransitionToState(State state) { | 3233 void HttpCache::Transaction::TransitionToState(State state) { |
3087 // Ensure that the state is only set once per Do* state. | 3234 // Ensure that the state is only set once per Do* state. |
3088 DCHECK(in_do_loop_); | 3235 DCHECK(in_do_loop_); |
3089 DCHECK_EQ(STATE_UNSET, next_state_) << "Next state is " << state; | 3236 DCHECK_EQ(STATE_UNSET, next_state_) << "Next state is " << state; |
3090 next_state_ = state; | 3237 next_state_ = state; |
3091 } | 3238 } |
3092 | 3239 |
3093 } // namespace net | 3240 } // namespace net |
OLD | NEW |