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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 // BeginPartialCacheValidation() -> BeginCacheValidation() -> | 705 // BeginPartialCacheValidation() -> BeginCacheValidation() -> |
706 // SetupEntryForRead() | 706 // SetupEntryForRead() |
707 // | 707 // |
708 // Read(): | 708 // Read(): |
709 // CacheReadData* | 709 // CacheReadData* |
710 // | 710 // |
711 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true: | 711 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true: |
712 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between | 712 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between |
713 // CacheReadResponse* and CacheDispatchValidation. | 713 // CacheReadResponse* and CacheDispatchValidation. |
714 int HttpCache::Transaction::DoLoop(int result) { | 714 int HttpCache::Transaction::DoLoop(int result) { |
715 DCHECK(next_state_ != STATE_UNSET); | |
715 DCHECK(next_state_ != STATE_NONE); | 716 DCHECK(next_state_ != STATE_NONE); |
Randy Smith (Not in Mondays)
2017/03/22 14:49:44
Suggestion: DCHECK_NE for both?
jkarlin
2017/03/22 15:04:26
Done.
| |
716 | 717 |
717 int rv = result; | 718 int rv = result; |
718 do { | 719 do { |
719 State state = next_state_; | 720 State state = next_state_; |
720 next_state_ = STATE_NONE; | 721 next_state_ = STATE_UNSET; |
721 switch (state) { | 722 switch (state) { |
722 case STATE_GET_BACKEND: | 723 case STATE_GET_BACKEND: |
723 DCHECK_EQ(OK, rv); | 724 DCHECK_EQ(OK, rv); |
724 rv = DoGetBackend(); | 725 rv = DoGetBackend(); |
725 break; | 726 break; |
726 case STATE_GET_BACKEND_COMPLETE: | 727 case STATE_GET_BACKEND_COMPLETE: |
727 rv = DoGetBackendComplete(rv); | 728 rv = DoGetBackendComplete(rv); |
728 break; | 729 break; |
729 case STATE_INIT_ENTRY: | 730 case STATE_INIT_ENTRY: |
730 DCHECK_EQ(OK, rv); | 731 DCHECK_EQ(OK, rv); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 rv = DoCacheWriteDataComplete(rv); | 873 rv = DoCacheWriteDataComplete(rv); |
873 break; | 874 break; |
874 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: | 875 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: |
875 DCHECK_EQ(OK, rv); | 876 DCHECK_EQ(OK, rv); |
876 rv = DoCacheWriteTruncatedResponse(); | 877 rv = DoCacheWriteTruncatedResponse(); |
877 break; | 878 break; |
878 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE: | 879 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE: |
879 rv = DoCacheWriteTruncatedResponseComplete(rv); | 880 rv = DoCacheWriteTruncatedResponseComplete(rv); |
880 break; | 881 break; |
881 default: | 882 default: |
882 NOTREACHED() << "bad state"; | 883 NOTREACHED() << "bad state " << state; |
883 rv = ERR_FAILED; | 884 rv = ERR_FAILED; |
884 break; | 885 break; |
885 } | 886 } |
887 DCHECK(next_state_ != STATE_UNSET) << "Previous state was " << state; | |
888 | |
886 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 889 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
887 | 890 |
888 if (rv != ERR_IO_PENDING && !callback_.is_null()) { | 891 if (rv != ERR_IO_PENDING && !callback_.is_null()) { |
889 read_buf_ = NULL; // Release the buffer before invoking the callback. | 892 read_buf_ = NULL; // Release the buffer before invoking the callback. |
890 base::ResetAndReturn(&callback_).Run(rv); | 893 base::ResetAndReturn(&callback_).Run(rv); |
891 } | 894 } |
892 | 895 |
893 return rv; | 896 return rv; |
894 } | 897 } |
895 | 898 |
(...skipping 10 matching lines...) Expand all Loading... | |
906 result); | 909 result); |
907 cache_pending_ = false; | 910 cache_pending_ = false; |
908 | 911 |
909 if (!ShouldPassThrough()) { | 912 if (!ShouldPassThrough()) { |
910 cache_key_ = cache_->GenerateCacheKey(request_); | 913 cache_key_ = cache_->GenerateCacheKey(request_); |
911 | 914 |
912 // Requested cache access mode. | 915 // Requested cache access mode. |
913 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { | 916 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { |
914 if (effective_load_flags_ & LOAD_BYPASS_CACHE) { | 917 if (effective_load_flags_ & LOAD_BYPASS_CACHE) { |
915 // The client has asked for nonsense. | 918 // The client has asked for nonsense. |
919 next_state_ = STATE_NONE; | |
916 return ERR_CACHE_MISS; | 920 return ERR_CACHE_MISS; |
917 } | 921 } |
918 mode_ = READ; | 922 mode_ = READ; |
919 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { | 923 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { |
920 mode_ = WRITE; | 924 mode_ = WRITE; |
921 } else { | 925 } else { |
922 mode_ = READ_WRITE; | 926 mode_ = READ_WRITE; |
923 } | 927 } |
924 | 928 |
925 // Downgrade to UPDATE if the request has been externally conditionalized. | 929 // Downgrade to UPDATE if the request has been externally conditionalized. |
(...skipping 17 matching lines...) Expand all Loading... | |
943 // Note that if mode_ == UPDATE (which is tied to external_validation_), the | 947 // Note that if mode_ == UPDATE (which is tied to external_validation_), the |
944 // transaction behaves the same for GET and HEAD requests at this point: if it | 948 // transaction behaves the same for GET and HEAD requests at this point: if it |
945 // was not modified, the entry is updated and a response is not returned from | 949 // was not modified, the entry is updated and a response is not returned from |
946 // the cache. If we receive 200, it doesn't matter if there was a validation | 950 // the cache. If we receive 200, it doesn't matter if there was a validation |
947 // header or not. | 951 // header or not. |
948 if (request_->method == "HEAD" && mode_ == WRITE) | 952 if (request_->method == "HEAD" && mode_ == WRITE) |
949 mode_ = NONE; | 953 mode_ = NONE; |
950 | 954 |
951 // If must use cache, then we must fail. This can happen for back/forward | 955 // If must use cache, then we must fail. This can happen for back/forward |
952 // navigations to a page generated via a form post. | 956 // navigations to a page generated via a form post. |
953 if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) | 957 if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { |
958 next_state_ = STATE_NONE; | |
954 return ERR_CACHE_MISS; | 959 return ERR_CACHE_MISS; |
960 } | |
955 | 961 |
956 if (mode_ == NONE) { | 962 if (mode_ == NONE) { |
957 if (partial_) { | 963 if (partial_) { |
958 partial_->RestoreHeaders(&custom_request_->extra_headers); | 964 partial_->RestoreHeaders(&custom_request_->extra_headers); |
959 partial_.reset(); | 965 partial_.reset(); |
960 } | 966 } |
961 next_state_ = STATE_SEND_REQUEST; | 967 next_state_ = STATE_SEND_REQUEST; |
962 } else { | 968 } else { |
963 next_state_ = STATE_INIT_ENTRY; | 969 next_state_ = STATE_INIT_ENTRY; |
964 } | 970 } |
965 | 971 |
966 // This is only set if we have something to do with the response. | 972 // This is only set if we have something to do with the response. |
967 range_requested_ = (partial_.get() != NULL); | 973 range_requested_ = (partial_.get() != NULL); |
968 | 974 |
969 return OK; | 975 return OK; |
970 } | 976 } |
971 | 977 |
972 int HttpCache::Transaction::DoInitEntry() { | 978 int HttpCache::Transaction::DoInitEntry() { |
973 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); | 979 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); |
974 DCHECK(!new_entry_); | 980 DCHECK(!new_entry_); |
975 | 981 |
976 if (!cache_.get()) | 982 if (!cache_.get()) { |
983 next_state_ = STATE_NONE; | |
977 return ERR_UNEXPECTED; | 984 return ERR_UNEXPECTED; |
985 } | |
978 | 986 |
979 if (mode_ == WRITE) { | 987 if (mode_ == WRITE) { |
980 next_state_ = STATE_DOOM_ENTRY; | 988 next_state_ = STATE_DOOM_ENTRY; |
981 return OK; | 989 return OK; |
982 } | 990 } |
983 | 991 |
984 next_state_ = STATE_OPEN_ENTRY; | 992 next_state_ = STATE_OPEN_ENTRY; |
985 return OK; | 993 return OK; |
986 } | 994 } |
987 | 995 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 } | 1036 } |
1029 if (mode_ == UPDATE) { | 1037 if (mode_ == UPDATE) { |
1030 // There is no cache entry to update; proceed without caching. | 1038 // There is no cache entry to update; proceed without caching. |
1031 mode_ = NONE; | 1039 mode_ = NONE; |
1032 next_state_ = STATE_SEND_REQUEST; | 1040 next_state_ = STATE_SEND_REQUEST; |
1033 return OK; | 1041 return OK; |
1034 } | 1042 } |
1035 | 1043 |
1036 // The entry does not exist, and we are not permitted to create a new entry, | 1044 // The entry does not exist, and we are not permitted to create a new entry, |
1037 // so we must fail. | 1045 // so we must fail. |
1046 next_state_ = STATE_NONE; | |
1038 return ERR_CACHE_MISS; | 1047 return ERR_CACHE_MISS; |
1039 } | 1048 } |
1040 | 1049 |
1041 int HttpCache::Transaction::DoDoomEntry() { | 1050 int HttpCache::Transaction::DoDoomEntry() { |
1042 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntry"); | 1051 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntry"); |
1043 next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 1052 next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
1044 cache_pending_ = true; | 1053 cache_pending_ = true; |
1045 if (first_cache_access_since_.is_null()) | 1054 if (first_cache_access_since_.is_null()) |
1046 first_cache_access_since_ = TimeTicks::Now(); | 1055 first_cache_access_since_ = TimeTicks::Now(); |
1047 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); | 1056 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1158 | 1167 |
1159 // If there is a failure, the cache should have taken care of new_entry_. | 1168 // If there is a failure, the cache should have taken care of new_entry_. |
1160 new_entry_ = NULL; | 1169 new_entry_ = NULL; |
1161 | 1170 |
1162 if (result == ERR_CACHE_RACE) { | 1171 if (result == ERR_CACHE_RACE) { |
1163 next_state_ = STATE_INIT_ENTRY; | 1172 next_state_ = STATE_INIT_ENTRY; |
1164 return OK; | 1173 return OK; |
1165 } | 1174 } |
1166 | 1175 |
1167 if (result == ERR_CACHE_LOCK_TIMEOUT) { | 1176 if (result == ERR_CACHE_LOCK_TIMEOUT) { |
1168 if (mode_ == READ) | 1177 if (mode_ == READ) { |
1178 next_state_ = STATE_NONE; | |
1169 return ERR_CACHE_MISS; | 1179 return ERR_CACHE_MISS; |
1180 } | |
1170 | 1181 |
1171 // The cache is busy, bypass it for this transaction. | 1182 // The cache is busy, bypass it for this transaction. |
1172 mode_ = NONE; | 1183 mode_ = NONE; |
1173 next_state_ = STATE_SEND_REQUEST; | 1184 next_state_ = STATE_SEND_REQUEST; |
1174 if (partial_) { | 1185 if (partial_) { |
1175 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1186 partial_->RestoreHeaders(&custom_request_->extra_headers); |
1176 partial_.reset(); | 1187 partial_.reset(); |
1177 } | 1188 } |
1178 return OK; | 1189 return OK; |
1179 } | 1190 } |
1180 | 1191 |
1181 open_entry_last_used_ = entry_->disk_entry->GetLastUsed(); | 1192 open_entry_last_used_ = entry_->disk_entry->GetLastUsed(); |
1182 | 1193 |
1194 // TODO(jkarlin): We should either handle the case or DCHECK. | |
shivanisha
2017/03/22 14:48:29
Not sure what the "todo" suggests.
jkarlin
2017/03/22 15:04:26
It's against Chromium style to NOTREACHED/DCHECK i
| |
1183 if (result != OK) { | 1195 if (result != OK) { |
1184 NOTREACHED(); | 1196 NOTREACHED(); |
1197 next_state_ = STATE_NONE; | |
1185 return result; | 1198 return result; |
1186 } | 1199 } |
1187 | 1200 |
1188 if (mode_ == WRITE) { | 1201 if (mode_ == WRITE) { |
1189 if (partial_) | 1202 if (partial_) |
1190 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1203 partial_->RestoreHeaders(&custom_request_->extra_headers); |
1191 next_state_ = STATE_SEND_REQUEST; | 1204 next_state_ = STATE_SEND_REQUEST; |
1192 } else { | 1205 } else { |
1193 // We have to read the headers from the cached entry. | 1206 // We have to read the headers from the cached entry. |
1194 DCHECK(mode_ & READ_META); | 1207 DCHECK(mode_ & READ_META); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 case READ_WRITE: | 1319 case READ_WRITE: |
1307 result = BeginPartialCacheValidation(); | 1320 result = BeginPartialCacheValidation(); |
1308 break; | 1321 break; |
1309 case UPDATE: | 1322 case UPDATE: |
1310 result = BeginExternallyConditionalizedRequest(); | 1323 result = BeginExternallyConditionalizedRequest(); |
1311 break; | 1324 break; |
1312 case WRITE: | 1325 case WRITE: |
1313 default: | 1326 default: |
1314 NOTREACHED(); | 1327 NOTREACHED(); |
1315 } | 1328 } |
1316 return result; | 1329 return result; |
shivanisha
2017/03/22 15:19:48
Since this Do function is setting the state in the
jkarlin
2017/03/22 15:25:02
That seems a bit redundant to me as the DCHECK wil
shivanisha
2017/03/22 15:31:53
Makes sense.
| |
1317 } | 1330 } |
1318 | 1331 |
1319 int HttpCache::Transaction::DoCacheQueryData() { | 1332 int HttpCache::Transaction::DoCacheQueryData() { |
1320 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; | 1333 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; |
1321 return entry_->disk_entry->ReadyForSparseIO(io_callback_); | 1334 return entry_->disk_entry->ReadyForSparseIO(io_callback_); |
1322 } | 1335 } |
1323 | 1336 |
1324 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { | 1337 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { |
1325 DCHECK_EQ(OK, result); | 1338 DCHECK_EQ(OK, result); |
1326 if (!cache_.get()) | 1339 if (!cache_.get()) { |
1340 next_state_ = STATE_NONE; | |
1327 return ERR_UNEXPECTED; | 1341 return ERR_UNEXPECTED; |
1342 } | |
1328 | 1343 |
1329 return ValidateEntryHeadersAndContinue(); | 1344 return ValidateEntryHeadersAndContinue(); |
shivanisha
2017/03/22 15:19:48
Since this Do function is setting the state in the
jkarlin
2017/03/22 15:25:02
Acknowledged.
| |
1330 } | 1345 } |
1331 | 1346 |
1332 // We may end up here multiple times for a given request. | 1347 // We may end up here multiple times for a given request. |
1333 int HttpCache::Transaction::DoStartPartialCacheValidation() { | 1348 int HttpCache::Transaction::DoStartPartialCacheValidation() { |
1334 if (mode_ == NONE) | 1349 if (mode_ == NONE) { |
1350 next_state_ = STATE_NONE; | |
1335 return OK; | 1351 return OK; |
1352 } | |
1336 | 1353 |
1337 next_state_ = STATE_COMPLETE_PARTIAL_CACHE_VALIDATION; | 1354 next_state_ = STATE_COMPLETE_PARTIAL_CACHE_VALIDATION; |
1338 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); | 1355 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); |
1339 } | 1356 } |
1340 | 1357 |
1341 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { | 1358 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { |
1342 if (!result) { | 1359 if (!result) { |
1343 // This is the end of the request. | 1360 // This is the end of the request. |
1344 if (mode_ & WRITE) { | 1361 if (mode_ & WRITE) { |
1345 DoneWritingToEntry(true); | 1362 DoneWritingToEntry(true); |
1346 } else { | 1363 } else { |
1347 cache_->DoneReadingFromEntry(entry_, this); | 1364 cache_->DoneReadingFromEntry(entry_, this); |
1348 entry_ = NULL; | 1365 entry_ = NULL; |
1349 } | 1366 } |
1367 next_state_ = STATE_NONE; | |
1350 return result; | 1368 return result; |
1351 } | 1369 } |
1352 | 1370 |
1353 if (result < 0) | 1371 if (result < 0) { |
1372 next_state_ = STATE_NONE; | |
1354 return result; | 1373 return result; |
1374 } | |
1355 | 1375 |
1356 partial_->PrepareCacheValidation(entry_->disk_entry, | 1376 partial_->PrepareCacheValidation(entry_->disk_entry, |
1357 &custom_request_->extra_headers); | 1377 &custom_request_->extra_headers); |
1358 | 1378 |
1359 if (reading_ && partial_->IsCurrentRangeCached()) { | 1379 if (reading_ && partial_->IsCurrentRangeCached()) { |
1360 next_state_ = STATE_CACHE_READ_DATA; | 1380 next_state_ = STATE_CACHE_READ_DATA; |
1361 return OK; | 1381 return OK; |
1362 } | 1382 } |
1363 | 1383 |
1364 return BeginCacheValidation(); | 1384 return BeginCacheValidation(); |
shivanisha
2017/03/22 15:19:48
Since this Do function is setting the state in the
jkarlin
2017/03/22 15:25:02
Acknowledged.
| |
1365 } | 1385 } |
1366 | 1386 |
1367 int HttpCache::Transaction::DoSendRequest() { | 1387 int HttpCache::Transaction::DoSendRequest() { |
1368 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequest"); | 1388 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequest"); |
1369 DCHECK(mode_ & WRITE || mode_ == NONE); | 1389 DCHECK(mode_ & WRITE || mode_ == NONE); |
1370 DCHECK(!network_trans_.get()); | 1390 DCHECK(!network_trans_.get()); |
1371 | 1391 |
1372 send_request_since_ = TimeTicks::Now(); | 1392 send_request_since_ = TimeTicks::Now(); |
1373 | 1393 |
1374 // Create a network transaction. | 1394 // Create a network transaction. |
1375 int rv = | 1395 int rv = |
1376 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); | 1396 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); |
1377 if (rv != OK) | 1397 if (rv != OK) { |
1398 next_state_ = STATE_NONE; | |
1378 return rv; | 1399 return rv; |
1400 } | |
1379 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); | 1401 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); |
1380 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); | 1402 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); |
1381 | 1403 |
1382 // Old load timing information, if any, is now obsolete. | 1404 // Old load timing information, if any, is now obsolete. |
1383 old_network_trans_load_timing_.reset(); | 1405 old_network_trans_load_timing_.reset(); |
1384 old_remote_endpoint_ = IPEndPoint(); | 1406 old_remote_endpoint_ = IPEndPoint(); |
1385 | 1407 |
1386 if (websocket_handshake_stream_base_create_helper_) | 1408 if (websocket_handshake_stream_base_create_helper_) |
1387 network_trans_->SetWebSocketHandshakeStreamCreateHelper( | 1409 network_trans_->SetWebSocketHandshakeStreamCreateHelper( |
1388 websocket_handshake_stream_base_create_helper_); | 1410 websocket_handshake_stream_base_create_helper_); |
1389 | 1411 |
1390 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1412 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1391 rv = network_trans_->Start(request_, io_callback_, net_log_); | 1413 rv = network_trans_->Start(request_, io_callback_, net_log_); |
1392 return rv; | 1414 return rv; |
1393 } | 1415 } |
1394 | 1416 |
1395 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 1417 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
1396 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequestComplete"); | 1418 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequestComplete"); |
1397 if (!cache_.get()) | 1419 if (!cache_.get()) { |
1420 next_state_ = STATE_NONE; | |
1398 return ERR_UNEXPECTED; | 1421 return ERR_UNEXPECTED; |
1422 } | |
1399 | 1423 |
1400 // If we tried to conditionalize the request and failed, we know | 1424 // If we tried to conditionalize the request and failed, we know |
1401 // we won't be reading from the cache after this point. | 1425 // we won't be reading from the cache after this point. |
1402 if (couldnt_conditionalize_request_) | 1426 if (couldnt_conditionalize_request_) |
1403 mode_ = WRITE; | 1427 mode_ = WRITE; |
1404 | 1428 |
1405 if (result == OK) { | 1429 if (result == OK) { |
1406 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; | 1430 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; |
1407 return OK; | 1431 return OK; |
1408 } | 1432 } |
1409 | 1433 |
1410 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); | 1434 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); |
1411 response_.network_accessed = response->network_accessed; | 1435 response_.network_accessed = response->network_accessed; |
1412 | 1436 |
1413 // Do not record requests that have network errors or restarts. | 1437 // Do not record requests that have network errors or restarts. |
1414 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); | 1438 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); |
1415 if (IsCertificateError(result)) { | 1439 if (IsCertificateError(result)) { |
1416 // If we get a certificate error, then there is a certificate in ssl_info, | 1440 // If we get a certificate error, then there is a certificate in ssl_info, |
1417 // so GetResponseInfo() should never return NULL here. | 1441 // so GetResponseInfo() should never return NULL here. |
1418 DCHECK(response); | 1442 DCHECK(response); |
1419 response_.ssl_info = response->ssl_info; | 1443 response_.ssl_info = response->ssl_info; |
1420 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 1444 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
1421 DCHECK(response); | 1445 DCHECK(response); |
1422 response_.cert_request_info = response->cert_request_info; | 1446 response_.cert_request_info = response->cert_request_info; |
1423 } else if (response_.was_cached) { | 1447 } else if (response_.was_cached) { |
1424 DoneWritingToEntry(true); | 1448 DoneWritingToEntry(true); |
1425 } | 1449 } |
1426 | 1450 |
1451 next_state_ = STATE_NONE; | |
1427 return result; | 1452 return result; |
1428 } | 1453 } |
1429 | 1454 |
1430 // We received the response headers and there is no error. | 1455 // We received the response headers and there is no error. |
1431 int HttpCache::Transaction::DoSuccessfulSendRequest() { | 1456 int HttpCache::Transaction::DoSuccessfulSendRequest() { |
1432 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest"); | 1457 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest"); |
1433 DCHECK(!new_response_); | 1458 DCHECK(!new_response_); |
1434 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 1459 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
1435 | 1460 |
1436 if (new_response->headers->response_code() == 401 || | 1461 if (new_response->headers->response_code() == 401 || |
1437 new_response->headers->response_code() == 407) { | 1462 new_response->headers->response_code() == 407) { |
1438 SetAuthResponse(*new_response); | 1463 SetAuthResponse(*new_response); |
1439 if (!reading_) | 1464 if (!reading_) { |
1465 next_state_ = STATE_NONE; | |
1440 return OK; | 1466 return OK; |
1467 } | |
1441 | 1468 |
1442 // We initiated a second request the caller doesn't know about. We should be | 1469 // We initiated a second request the caller doesn't know about. We should be |
1443 // able to authenticate this request because we should have authenticated | 1470 // able to authenticate this request because we should have authenticated |
1444 // this URL moments ago. | 1471 // this URL moments ago. |
1445 if (IsReadyToRestartForAuth()) { | 1472 if (IsReadyToRestartForAuth()) { |
1446 DCHECK(!response_.auth_challenge.get()); | 1473 DCHECK(!response_.auth_challenge.get()); |
1447 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1474 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1448 // In theory we should check to see if there are new cookies, but there | 1475 // In theory we should check to see if there are new cookies, but there |
1449 // is no way to do that from here. | 1476 // is no way to do that from here. |
1450 return network_trans_->RestartWithAuth(AuthCredentials(), io_callback_); | 1477 return network_trans_->RestartWithAuth(AuthCredentials(), io_callback_); |
1451 } | 1478 } |
1452 | 1479 |
1453 // We have to perform cleanup at this point so that at least the next | 1480 // We have to perform cleanup at this point so that at least the next |
1454 // request can succeed. We do not retry at this point, because data | 1481 // request can succeed. We do not retry at this point, because data |
1455 // has been read and we have no way to gather credentials. We would | 1482 // has been read and we have no way to gather credentials. We would |
1456 // fail again, and potentially loop. This can happen if the credentials | 1483 // fail again, and potentially loop. This can happen if the credentials |
1457 // expire while chrome is suspended. | 1484 // expire while chrome is suspended. |
1458 if (entry_) | 1485 if (entry_) |
1459 DoomPartialEntry(false); | 1486 DoomPartialEntry(false); |
1460 mode_ = NONE; | 1487 mode_ = NONE; |
1461 partial_.reset(); | 1488 partial_.reset(); |
1462 ResetNetworkTransaction(); | 1489 ResetNetworkTransaction(); |
1490 next_state_ = STATE_NONE; | |
1463 return ERR_CACHE_AUTH_FAILURE_AFTER_READ; | 1491 return ERR_CACHE_AUTH_FAILURE_AFTER_READ; |
1464 } | 1492 } |
1465 | 1493 |
1466 new_response_ = new_response; | 1494 new_response_ = new_response; |
1467 if (!ValidatePartialResponse() && !auth_response_.headers.get()) { | 1495 if (!ValidatePartialResponse() && !auth_response_.headers.get()) { |
1468 // Something went wrong with this request and we have to restart it. | 1496 // Something went wrong with this request and we have to restart it. |
1469 // If we have an authentication response, we are exposed to weird things | 1497 // If we have an authentication response, we are exposed to weird things |
1470 // hapenning if the user cancels the authentication before we receive | 1498 // hapenning if the user cancels the authentication before we receive |
1471 // the new response. | 1499 // the new response. |
1472 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST); | 1500 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1508 NonErrorResponse(new_response->headers->response_code())) { | 1536 NonErrorResponse(new_response->headers->response_code())) { |
1509 cache_->DoomMainEntryForUrl(request_->url); | 1537 cache_->DoomMainEntryForUrl(request_->url); |
1510 } | 1538 } |
1511 | 1539 |
1512 RecordNoStoreHeaderHistogram(request_->load_flags, new_response); | 1540 RecordNoStoreHeaderHistogram(request_->load_flags, new_response); |
1513 | 1541 |
1514 if (new_response_->headers->response_code() == 416 && | 1542 if (new_response_->headers->response_code() == 416 && |
1515 (request_->method == "GET" || request_->method == "POST")) { | 1543 (request_->method == "GET" || request_->method == "POST")) { |
1516 // If there is an active entry it may be destroyed with this transaction. | 1544 // If there is an active entry it may be destroyed with this transaction. |
1517 SetResponse(*new_response_); | 1545 SetResponse(*new_response_); |
1546 next_state_ = STATE_NONE; | |
1518 return OK; | 1547 return OK; |
1519 } | 1548 } |
1520 | 1549 |
1521 // Are we expecting a response to a conditional query? | 1550 // Are we expecting a response to a conditional query? |
1522 if (mode_ == READ_WRITE || mode_ == UPDATE) { | 1551 if (mode_ == READ_WRITE || mode_ == UPDATE) { |
1523 if (new_response->headers->response_code() == 304 || handling_206_) { | 1552 if (new_response->headers->response_code() == 304 || handling_206_) { |
1524 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED); | 1553 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED); |
1525 next_state_ = STATE_UPDATE_CACHED_RESPONSE; | 1554 next_state_ = STATE_UPDATE_CACHED_RESPONSE; |
1526 return OK; | 1555 return OK; |
1527 } | 1556 } |
(...skipping 30 matching lines...) Expand all Loading... | |
1558 | 1587 |
1559 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { | 1588 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { |
1560 if (!entry_->doomed) { | 1589 if (!entry_->doomed) { |
1561 int ret = cache_->DoomEntry(cache_key_, NULL); | 1590 int ret = cache_->DoomEntry(cache_key_, NULL); |
1562 DCHECK_EQ(OK, ret); | 1591 DCHECK_EQ(OK, ret); |
1563 } | 1592 } |
1564 } else { | 1593 } else { |
1565 // If we are already reading, we already updated the headers for this | 1594 // If we are already reading, we already updated the headers for this |
1566 // request; doing it again will change Content-Length. | 1595 // request; doing it again will change Content-Length. |
1567 if (!reading_) { | 1596 if (!reading_) { |
1568 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE; | 1597 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE; |
shivanisha
2017/03/22 15:19:48
Nothing to change here but pointing out for refere
jkarlin
2017/03/22 15:25:02
Yep, it's not so great. Addressed in the follow-up
| |
1569 rv = OK; | 1598 rv = OK; |
1570 } | 1599 } |
1571 } | 1600 } |
1572 return rv; | 1601 return rv; |
1573 } | 1602 } |
1574 | 1603 |
1575 int HttpCache::Transaction::DoCacheWriteUpdatedResponse() { | 1604 int HttpCache::Transaction::DoCacheWriteUpdatedResponse() { |
1576 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteUpdatedResponse"); | 1605 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteUpdatedResponse"); |
1577 | 1606 |
1578 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE; | 1607 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1630 if (handling_206_ && partial_) | 1659 if (handling_206_ && partial_) |
1631 partial_->FixContentLength(new_response_->headers.get()); | 1660 partial_->FixContentLength(new_response_->headers.get()); |
1632 | 1661 |
1633 SetResponse(*new_response_); | 1662 SetResponse(*new_response_); |
1634 | 1663 |
1635 if (request_->method == "HEAD") { | 1664 if (request_->method == "HEAD") { |
1636 // This response is replacing the cached one. | 1665 // This response is replacing the cached one. |
1637 DoneWritingToEntry(false); | 1666 DoneWritingToEntry(false); |
1638 mode_ = NONE; | 1667 mode_ = NONE; |
1639 new_response_ = NULL; | 1668 new_response_ = NULL; |
1669 next_state_ = STATE_NONE; | |
1640 return OK; | 1670 return OK; |
1641 } | 1671 } |
1642 | 1672 |
1643 if (handling_206_ && !CanResume(false)) { | 1673 if (handling_206_ && !CanResume(false)) { |
1644 // There is no point in storing this resource because it will never be used. | 1674 // There is no point in storing this resource because it will never be used. |
1645 // This may change if we support LOAD_ONLY_FROM_CACHE with sparse entries. | 1675 // This may change if we support LOAD_ONLY_FROM_CACHE with sparse entries. |
1646 DoneWritingToEntry(false); | 1676 DoneWritingToEntry(false); |
1647 if (partial_) | 1677 if (partial_) |
1648 partial_->FixResponseHeaders(response_.headers.get(), true); | 1678 partial_->FixResponseHeaders(response_.headers.get(), true); |
1649 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1679 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1709 result); | 1739 result); |
1710 } | 1740 } |
1711 } | 1741 } |
1712 | 1742 |
1713 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1743 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
1714 return OK; | 1744 return OK; |
1715 } | 1745 } |
1716 | 1746 |
1717 int HttpCache::Transaction::DoPartialHeadersReceived() { | 1747 int HttpCache::Transaction::DoPartialHeadersReceived() { |
1718 new_response_ = NULL; | 1748 new_response_ = NULL; |
1719 if (entry_ && !partial_ && entry_->disk_entry->GetDataSize(kMetadataIndex)) | |
1720 next_state_ = STATE_CACHE_READ_METADATA; | |
1721 | 1749 |
1722 if (!partial_) | 1750 if (!partial_) { |
1751 if (entry_ && entry_->disk_entry->GetDataSize(kMetadataIndex)) | |
1752 next_state_ = STATE_CACHE_READ_METADATA; | |
1753 else | |
1754 next_state_ = STATE_NONE; | |
1723 return OK; | 1755 return OK; |
1756 } | |
1724 | 1757 |
1725 if (reading_) { | 1758 if (reading_) { |
1726 if (network_trans_.get()) { | 1759 if (network_trans_.get()) { |
1727 next_state_ = STATE_NETWORK_READ; | 1760 next_state_ = STATE_NETWORK_READ; |
1728 } else { | 1761 } else { |
1729 next_state_ = STATE_CACHE_READ_DATA; | 1762 next_state_ = STATE_CACHE_READ_DATA; |
1730 } | 1763 } |
1731 } else if (mode_ != NONE) { | 1764 } else if (mode_ != NONE) { |
1732 // We are about to return the headers for a byte-range request to the user, | 1765 // We are about to return the headers for a byte-range request to the user, |
1733 // so let's fix them. | 1766 // so let's fix them. |
1734 partial_->FixResponseHeaders(response_.headers.get(), true); | 1767 partial_->FixResponseHeaders(response_.headers.get(), true); |
1768 next_state_ = STATE_NONE; | |
1769 } else { | |
1770 next_state_ = STATE_NONE; | |
1735 } | 1771 } |
1736 return OK; | 1772 return OK; |
1737 } | 1773 } |
1738 | 1774 |
1739 int HttpCache::Transaction::DoCacheReadMetadata() { | 1775 int HttpCache::Transaction::DoCacheReadMetadata() { |
1740 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); | 1776 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); |
1741 DCHECK(entry_); | 1777 DCHECK(entry_); |
1742 DCHECK(!response_.metadata.get()); | 1778 DCHECK(!response_.metadata.get()); |
1743 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 1779 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |
1744 | 1780 |
1745 response_.metadata = | 1781 response_.metadata = |
1746 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1782 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
1747 | 1783 |
1748 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1784 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
1749 return entry_->disk_entry->ReadData(kMetadataIndex, 0, | 1785 return entry_->disk_entry->ReadData(kMetadataIndex, 0, |
1750 response_.metadata.get(), | 1786 response_.metadata.get(), |
1751 response_.metadata->size(), | 1787 response_.metadata->size(), |
1752 io_callback_); | 1788 io_callback_); |
1753 } | 1789 } |
1754 | 1790 |
1755 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1791 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
1756 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete"); | 1792 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete"); |
1757 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, | 1793 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, |
1758 result); | 1794 result); |
1759 if (result != response_.metadata->size()) | 1795 if (result != response_.metadata->size()) |
1760 return OnCacheReadError(result, false); | 1796 return OnCacheReadError(result, false); |
1797 next_state_ = STATE_NONE; | |
1761 return OK; | 1798 return OK; |
1762 } | 1799 } |
1763 | 1800 |
1764 int HttpCache::Transaction::DoNetworkRead() { | 1801 int HttpCache::Transaction::DoNetworkRead() { |
1765 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead"); | 1802 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead"); |
1766 next_state_ = STATE_NETWORK_READ_COMPLETE; | 1803 next_state_ = STATE_NETWORK_READ_COMPLETE; |
1767 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); | 1804 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); |
1768 } | 1805 } |
1769 | 1806 |
1770 int HttpCache::Transaction::DoNetworkReadComplete(int result) { | 1807 int HttpCache::Transaction::DoNetworkReadComplete(int result) { |
1771 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkReadComplete"); | 1808 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkReadComplete"); |
1772 DCHECK(mode_ & WRITE || mode_ == NONE); | 1809 DCHECK(mode_ & WRITE || mode_ == NONE); |
1773 | 1810 |
1774 if (!cache_.get()) | 1811 if (!cache_.get()) { |
1812 next_state_ = STATE_NONE; | |
1775 return ERR_UNEXPECTED; | 1813 return ERR_UNEXPECTED; |
1814 } | |
1776 | 1815 |
1777 // If there is an error or we aren't saving the data, we are done; just wait | 1816 // If there is an error or we aren't saving the data, we are done; just wait |
1778 // until the destructor runs to see if we can keep the data. | 1817 // until the destructor runs to see if we can keep the data. |
1779 if (mode_ == NONE || result < 0) | 1818 if (mode_ == NONE || result < 0) { |
1819 next_state_ = STATE_NONE; | |
1780 return result; | 1820 return result; |
1821 } | |
1781 | 1822 |
1782 next_state_ = STATE_CACHE_WRITE_DATA; | 1823 next_state_ = STATE_CACHE_WRITE_DATA; |
1783 return result; | 1824 return result; |
1784 } | 1825 } |
1785 | 1826 |
1786 int HttpCache::Transaction::DoCacheReadData() { | 1827 int HttpCache::Transaction::DoCacheReadData() { |
1787 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadData"); | 1828 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadData"); |
1788 if (request_->method == "HEAD") | 1829 |
1830 if (request_->method == "HEAD") { | |
1831 next_state_ = STATE_NONE; | |
1789 return 0; | 1832 return 0; |
1833 } | |
1790 | 1834 |
1791 DCHECK(entry_); | 1835 DCHECK(entry_); |
1792 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1836 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
1793 | 1837 |
1794 if (net_log_.IsCapturing()) | 1838 if (net_log_.IsCapturing()) |
1795 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA); | 1839 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA); |
1796 if (partial_) { | 1840 if (partial_) { |
1797 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, | 1841 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, |
1798 io_callback_); | 1842 io_callback_); |
1799 } | 1843 } |
1800 | 1844 |
1801 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1845 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
1802 read_buf_.get(), io_buf_len_, | 1846 read_buf_.get(), io_buf_len_, |
1803 io_callback_); | 1847 io_callback_); |
1804 } | 1848 } |
1805 | 1849 |
1806 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 1850 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
1807 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadDataComplete"); | 1851 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadDataComplete"); |
1808 if (net_log_.IsCapturing()) { | 1852 if (net_log_.IsCapturing()) { |
1809 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA, | 1853 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA, |
1810 result); | 1854 result); |
1811 } | 1855 } |
1812 | 1856 |
1813 if (!cache_.get()) | 1857 if (!cache_.get()) { |
1858 next_state_ = STATE_NONE; | |
1814 return ERR_UNEXPECTED; | 1859 return ERR_UNEXPECTED; |
1860 } | |
1815 | 1861 |
1816 if (partial_) { | 1862 if (partial_) { |
1817 // Partial requests are confusing to report in histograms because they may | 1863 // Partial requests are confusing to report in histograms because they may |
1818 // have multiple underlying requests. | 1864 // have multiple underlying requests. |
1819 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); | 1865 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); |
1820 return DoPartialCacheReadCompleted(result); | 1866 return DoPartialCacheReadCompleted(result); |
1821 } | 1867 } |
1822 | 1868 |
1823 if (result > 0) { | 1869 if (result > 0) { |
1824 read_offset_ += result; | 1870 read_offset_ += result; |
1825 } else if (result == 0) { // End of file. | 1871 } else if (result == 0) { // End of file. |
1826 RecordHistograms(); | 1872 RecordHistograms(); |
1827 cache_->DoneReadingFromEntry(entry_, this); | 1873 cache_->DoneReadingFromEntry(entry_, this); |
1828 entry_ = NULL; | 1874 entry_ = NULL; |
1829 } else { | 1875 } else { |
1830 return OnCacheReadError(result, false); | 1876 return OnCacheReadError(result, false); |
1831 } | 1877 } |
1878 | |
1879 next_state_ = STATE_NONE; | |
1832 return result; | 1880 return result; |
1833 } | 1881 } |
1834 | 1882 |
1835 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1883 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
1836 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteData"); | 1884 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteData"); |
1837 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1885 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
1838 write_len_ = num_bytes; | 1886 write_len_ = num_bytes; |
1839 if (entry_) { | 1887 if (entry_) { |
1840 if (net_log_.IsCapturing()) | 1888 if (net_log_.IsCapturing()) |
1841 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); | 1889 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); |
1842 } | 1890 } |
1843 | 1891 |
1844 if (!entry_ || !num_bytes) | 1892 if (!entry_ || !num_bytes) |
1845 return num_bytes; | 1893 return num_bytes; |
1846 | 1894 |
1847 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1895 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
1848 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), | 1896 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), |
1849 num_bytes, io_callback_); | 1897 num_bytes, io_callback_); |
1850 } | 1898 } |
1851 | 1899 |
1852 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1900 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
1853 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteDataComplete"); | 1901 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteDataComplete"); |
1854 if (entry_) { | 1902 if (entry_) { |
1855 if (net_log_.IsCapturing()) { | 1903 if (net_log_.IsCapturing()) { |
1856 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, | 1904 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, |
1857 result); | 1905 result); |
1858 } | 1906 } |
1859 } | 1907 } |
1860 if (!cache_.get()) | 1908 if (!cache_.get()) { |
1909 next_state_ = STATE_NONE; | |
1861 return ERR_UNEXPECTED; | 1910 return ERR_UNEXPECTED; |
1911 } | |
1862 | 1912 |
1863 if (result != write_len_) { | 1913 if (result != write_len_) { |
1864 DLOG(ERROR) << "failed to write response data to cache"; | 1914 DLOG(ERROR) << "failed to write response data to cache"; |
1865 DoneWritingToEntry(false); | 1915 DoneWritingToEntry(false); |
1866 | 1916 |
1867 // We want to ignore errors writing to disk and just keep reading from | 1917 // We want to ignore errors writing to disk and just keep reading from |
1868 // the network. | 1918 // the network. |
1869 result = write_len_; | 1919 result = write_len_; |
1870 } else if (!done_reading_ && entry_ && (!partial_ || truncated_)) { | 1920 } else if (!done_reading_ && entry_ && (!partial_ || truncated_)) { |
1871 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1921 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
(...skipping 12 matching lines...) Expand all Loading... | |
1884 | 1934 |
1885 if (result == 0) { | 1935 if (result == 0) { |
1886 // End of file. This may be the result of a connection problem so see if we | 1936 // End of file. This may be the result of a connection problem so see if we |
1887 // have to keep the entry around to be flagged as truncated later on. | 1937 // have to keep the entry around to be flagged as truncated later on. |
1888 if (done_reading_ || !entry_ || partial_ || | 1938 if (done_reading_ || !entry_ || partial_ || |
1889 response_.headers->GetContentLength() <= 0) { | 1939 response_.headers->GetContentLength() <= 0) { |
1890 DoneWritingToEntry(true); | 1940 DoneWritingToEntry(true); |
1891 } | 1941 } |
1892 } | 1942 } |
1893 | 1943 |
1944 next_state_ = STATE_NONE; | |
1894 return result; | 1945 return result; |
1895 } | 1946 } |
1896 | 1947 |
1897 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1948 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
1898 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteTruncatedResponse"); | 1949 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteTruncatedResponse"); |
1899 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE; | 1950 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE; |
1900 return WriteResponseInfoToEntry(true); | 1951 return WriteResponseInfoToEntry(true); |
1901 } | 1952 } |
1902 | 1953 |
1903 int HttpCache::Transaction::DoCacheWriteTruncatedResponseComplete(int result) { | 1954 int HttpCache::Transaction::DoCacheWriteTruncatedResponseComplete(int result) { |
1904 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteTruncatedResponse"); | 1955 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteTruncatedResponse"); |
1905 | 1956 |
1957 next_state_ = STATE_NONE; | |
1906 return OnWriteResponseInfoToEntryComplete(result); | 1958 return OnWriteResponseInfoToEntryComplete(result); |
1907 } | 1959 } |
1908 | 1960 |
1909 //----------------------------------------------------------------------------- | 1961 //----------------------------------------------------------------------------- |
1910 | 1962 |
1911 void HttpCache::Transaction::SetRequest(const NetLogWithSource& net_log, | 1963 void HttpCache::Transaction::SetRequest(const NetLogWithSource& net_log, |
1912 const HttpRequestInfo* request) { | 1964 const HttpRequestInfo* request) { |
1913 net_log_ = net_log; | 1965 net_log_ = net_log; |
1914 request_ = request; | 1966 request_ = request; |
1915 effective_load_flags_ = request_->load_flags; | 1967 effective_load_flags_ = request_->load_flags; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2029 return false; | 2081 return false; |
2030 | 2082 |
2031 if (request_->method == "DELETE") | 2083 if (request_->method == "DELETE") |
2032 return false; | 2084 return false; |
2033 | 2085 |
2034 return true; | 2086 return true; |
2035 } | 2087 } |
2036 | 2088 |
2037 int HttpCache::Transaction::BeginCacheRead() { | 2089 int HttpCache::Transaction::BeginCacheRead() { |
2038 // We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges. | 2090 // We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges. |
2091 // TODO(jkarlin): Either handle this case or DCHECK. | |
2039 if (response_.headers->response_code() == 206 || partial_) { | 2092 if (response_.headers->response_code() == 206 || partial_) { |
2040 NOTREACHED(); | 2093 NOTREACHED(); |
2094 next_state_ = STATE_NONE; | |
2041 return ERR_CACHE_MISS; | 2095 return ERR_CACHE_MISS; |
2042 } | 2096 } |
2043 | 2097 |
2044 // We don't have the whole resource. | 2098 // We don't have the whole resource. |
2045 if (truncated_) | 2099 if (truncated_) { |
2100 next_state_ = STATE_NONE; | |
2046 return ERR_CACHE_MISS; | 2101 return ERR_CACHE_MISS; |
2102 } | |
2047 | 2103 |
2048 if (RequiresValidation() != VALIDATION_NONE) | 2104 if (RequiresValidation() != VALIDATION_NONE) { |
2105 next_state_ = STATE_NONE; | |
2049 return ERR_CACHE_MISS; | 2106 return ERR_CACHE_MISS; |
2107 } | |
2050 | 2108 |
2051 if (request_->method == "HEAD") | 2109 if (request_->method == "HEAD") |
2052 FixHeadersForHead(); | 2110 FixHeadersForHead(); |
2053 | 2111 |
2054 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) | 2112 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
2055 next_state_ = STATE_CACHE_READ_METADATA; | 2113 next_state_ = STATE_CACHE_READ_METADATA; |
2114 else | |
2115 next_state_ = STATE_NONE; | |
2056 | 2116 |
2057 return OK; | 2117 return OK; |
2058 } | 2118 } |
2059 | 2119 |
2060 int HttpCache::Transaction::BeginCacheValidation() { | 2120 int HttpCache::Transaction::BeginCacheValidation() { |
2061 DCHECK_EQ(mode_, READ_WRITE); | 2121 DCHECK_EQ(mode_, READ_WRITE); |
2062 | 2122 |
2063 ValidationType required_validation = RequiresValidation(); | 2123 ValidationType required_validation = RequiresValidation(); |
2064 | 2124 |
2065 bool skip_validation = (required_validation == VALIDATION_NONE); | 2125 bool skip_validation = (required_validation == VALIDATION_NONE); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2566 } | 2626 } |
2567 } | 2627 } |
2568 cache_->ConvertWriterToReader(entry_); | 2628 cache_->ConvertWriterToReader(entry_); |
2569 mode_ = READ; | 2629 mode_ = READ; |
2570 | 2630 |
2571 if (request_->method == "HEAD") | 2631 if (request_->method == "HEAD") |
2572 FixHeadersForHead(); | 2632 FixHeadersForHead(); |
2573 | 2633 |
2574 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) | 2634 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
2575 next_state_ = STATE_CACHE_READ_METADATA; | 2635 next_state_ = STATE_CACHE_READ_METADATA; |
2636 else | |
2637 next_state_ = STATE_NONE; | |
2576 return OK; | 2638 return OK; |
2577 } | 2639 } |
2578 | 2640 |
2579 int HttpCache::Transaction::WriteToEntry(int index, int offset, | 2641 int HttpCache::Transaction::WriteToEntry(int index, int offset, |
2580 IOBuffer* data, int data_len, | 2642 IOBuffer* data, int data_len, |
2581 const CompletionCallback& callback) { | 2643 const CompletionCallback& callback) { |
2582 if (!entry_) | 2644 if (!entry_) |
2583 return data_len; | 2645 return data_len; |
2584 | 2646 |
2585 int rv = 0; | 2647 int rv = 0; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2675 DCHECK(!reading_); | 2737 DCHECK(!reading_); |
2676 DCHECK(!network_trans_.get()); | 2738 DCHECK(!network_trans_.get()); |
2677 cache_->DoneWithEntry(entry_, this, false); | 2739 cache_->DoneWithEntry(entry_, this, false); |
2678 entry_ = NULL; | 2740 entry_ = NULL; |
2679 is_sparse_ = false; | 2741 is_sparse_ = false; |
2680 partial_.reset(); | 2742 partial_.reset(); |
2681 next_state_ = STATE_GET_BACKEND; | 2743 next_state_ = STATE_GET_BACKEND; |
2682 return OK; | 2744 return OK; |
2683 } | 2745 } |
2684 | 2746 |
2747 next_state_ = STATE_NONE; | |
2685 return ERR_CACHE_READ_FAILURE; | 2748 return ERR_CACHE_READ_FAILURE; |
2686 } | 2749 } |
2687 | 2750 |
2688 void HttpCache::Transaction::OnAddToEntryTimeout(base::TimeTicks start_time) { | 2751 void HttpCache::Transaction::OnAddToEntryTimeout(base::TimeTicks start_time) { |
2689 if (entry_lock_waiting_since_ != start_time) | 2752 if (entry_lock_waiting_since_ != start_time) |
2690 return; | 2753 return; |
2691 | 2754 |
2692 DCHECK_EQ(next_state_, STATE_ADD_TO_ENTRY_COMPLETE); | 2755 DCHECK_EQ(next_state_, STATE_ADD_TO_ENTRY_COMPLETE); |
2693 | 2756 |
2694 if (!cache_) | 2757 if (!cache_) |
(...skipping 15 matching lines...) Expand all Loading... | |
2710 partial_.reset(NULL); | 2773 partial_.reset(NULL); |
2711 } | 2774 } |
2712 | 2775 |
2713 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) { | 2776 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) { |
2714 partial_->OnNetworkReadCompleted(result); | 2777 partial_->OnNetworkReadCompleted(result); |
2715 | 2778 |
2716 if (result == 0) { | 2779 if (result == 0) { |
2717 // We need to move on to the next range. | 2780 // We need to move on to the next range. |
2718 ResetNetworkTransaction(); | 2781 ResetNetworkTransaction(); |
2719 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 2782 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
2783 } else { | |
2784 next_state_ = STATE_NONE; | |
2720 } | 2785 } |
2721 return result; | 2786 return result; |
2722 } | 2787 } |
2723 | 2788 |
2724 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { | 2789 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { |
2725 partial_->OnCacheReadCompleted(result); | 2790 partial_->OnCacheReadCompleted(result); |
2726 | 2791 |
2727 if (result == 0 && mode_ == READ_WRITE) { | 2792 if (result == 0 && mode_ == READ_WRITE) { |
2728 // We need to move on to the next range. | 2793 // We need to move on to the next range. |
2729 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 2794 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
2730 } else if (result < 0) { | 2795 } else if (result < 0) { |
2731 return OnCacheReadError(result, false); | 2796 return OnCacheReadError(result, false); |
2797 } else { | |
2798 next_state_ = STATE_NONE; | |
2732 } | 2799 } |
2733 return result; | 2800 return result; |
2734 } | 2801 } |
2735 | 2802 |
2736 int HttpCache::Transaction::DoRestartPartialRequest() { | 2803 int HttpCache::Transaction::DoRestartPartialRequest() { |
2737 // The stored data cannot be used. Get rid of it and restart this request. | 2804 // The stored data cannot be used. Get rid of it and restart this request. |
2738 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RESTART_PARTIAL_REQUEST); | 2805 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RESTART_PARTIAL_REQUEST); |
2739 | 2806 |
2740 // WRITE + Doom + STATE_INIT_ENTRY == STATE_CREATE_ENTRY (without an attempt | 2807 // WRITE + Doom + STATE_INIT_ENTRY == STATE_CREATE_ENTRY (without an attempt |
2741 // to Doom the entry again). | 2808 // to Doom the entry again). |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3000 default: | 3067 default: |
3001 NOTREACHED(); | 3068 NOTREACHED(); |
3002 } | 3069 } |
3003 } | 3070 } |
3004 | 3071 |
3005 void HttpCache::Transaction::OnIOComplete(int result) { | 3072 void HttpCache::Transaction::OnIOComplete(int result) { |
3006 DoLoop(result); | 3073 DoLoop(result); |
3007 } | 3074 } |
3008 | 3075 |
3009 } // namespace net | 3076 } // namespace net |
OLD | NEW |