| 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" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 } | 996 } |
| 997 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 997 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 998 | 998 |
| 999 if (rv != ERR_IO_PENDING) | 999 if (rv != ERR_IO_PENDING) |
| 1000 HandleResult(rv); | 1000 HandleResult(rv); |
| 1001 | 1001 |
| 1002 return rv; | 1002 return rv; |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 int HttpCache::Transaction::DoGetBackend() { | 1005 int HttpCache::Transaction::DoGetBackend() { |
| 1006 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1007 tracked_objects::ScopedTracker tracking_profile( |
| 1008 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1009 "422516 HttpCache::Transaction::DoGetBackend")); |
| 1010 |
| 1006 cache_pending_ = true; | 1011 cache_pending_ = true; |
| 1007 next_state_ = STATE_GET_BACKEND_COMPLETE; | 1012 next_state_ = STATE_GET_BACKEND_COMPLETE; |
| 1008 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND); | 1013 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND); |
| 1009 return cache_->GetBackendForTransaction(this); | 1014 return cache_->GetBackendForTransaction(this); |
| 1010 } | 1015 } |
| 1011 | 1016 |
| 1012 int HttpCache::Transaction::DoGetBackendComplete(int result) { | 1017 int HttpCache::Transaction::DoGetBackendComplete(int result) { |
| 1018 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1019 tracked_objects::ScopedTracker tracking_profile( |
| 1020 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1021 "422516 HttpCache::Transaction::DoGetBackendComplete")); |
| 1022 |
| 1013 DCHECK(result == OK || result == ERR_FAILED); | 1023 DCHECK(result == OK || result == ERR_FAILED); |
| 1014 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, | 1024 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, |
| 1015 result); | 1025 result); |
| 1016 cache_pending_ = false; | 1026 cache_pending_ = false; |
| 1017 | 1027 |
| 1018 if (!ShouldPassThrough()) { | 1028 if (!ShouldPassThrough()) { |
| 1019 cache_key_ = cache_->GenerateCacheKey(request_); | 1029 cache_key_ = cache_->GenerateCacheKey(request_); |
| 1020 | 1030 |
| 1021 // Requested cache access mode. | 1031 // Requested cache access mode. |
| 1022 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { | 1032 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 next_state_ = STATE_INIT_ENTRY; | 1078 next_state_ = STATE_INIT_ENTRY; |
| 1069 } | 1079 } |
| 1070 | 1080 |
| 1071 // This is only set if we have something to do with the response. | 1081 // This is only set if we have something to do with the response. |
| 1072 range_requested_ = (partial_.get() != NULL); | 1082 range_requested_ = (partial_.get() != NULL); |
| 1073 | 1083 |
| 1074 return OK; | 1084 return OK; |
| 1075 } | 1085 } |
| 1076 | 1086 |
| 1077 int HttpCache::Transaction::DoSendRequest() { | 1087 int HttpCache::Transaction::DoSendRequest() { |
| 1088 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1089 tracked_objects::ScopedTracker tracking_profile( |
| 1090 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1091 "422516 HttpCache::Transaction::DoSendRequest")); |
| 1092 |
| 1078 DCHECK(mode_ & WRITE || mode_ == NONE); | 1093 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 1079 DCHECK(!network_trans_.get()); | 1094 DCHECK(!network_trans_.get()); |
| 1080 | 1095 |
| 1081 send_request_since_ = TimeTicks::Now(); | 1096 send_request_since_ = TimeTicks::Now(); |
| 1082 | 1097 |
| 1083 // Create a network transaction. | 1098 // Create a network transaction. |
| 1084 int rv = cache_->network_layer_->CreateTransaction(priority_, | 1099 int rv = cache_->network_layer_->CreateTransaction(priority_, |
| 1085 &network_trans_); | 1100 &network_trans_); |
| 1086 if (rv != OK) | 1101 if (rv != OK) |
| 1087 return rv; | 1102 return rv; |
| 1088 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); | 1103 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); |
| 1089 network_trans_->SetBeforeProxyHeadersSentCallback( | 1104 network_trans_->SetBeforeProxyHeadersSentCallback( |
| 1090 before_proxy_headers_sent_callback_); | 1105 before_proxy_headers_sent_callback_); |
| 1091 | 1106 |
| 1092 // Old load timing information, if any, is now obsolete. | 1107 // Old load timing information, if any, is now obsolete. |
| 1093 old_network_trans_load_timing_.reset(); | 1108 old_network_trans_load_timing_.reset(); |
| 1094 | 1109 |
| 1095 if (websocket_handshake_stream_base_create_helper_) | 1110 if (websocket_handshake_stream_base_create_helper_) |
| 1096 network_trans_->SetWebSocketHandshakeStreamCreateHelper( | 1111 network_trans_->SetWebSocketHandshakeStreamCreateHelper( |
| 1097 websocket_handshake_stream_base_create_helper_); | 1112 websocket_handshake_stream_base_create_helper_); |
| 1098 | 1113 |
| 1099 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1114 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 1100 rv = network_trans_->Start(request_, io_callback_, net_log_); | 1115 rv = network_trans_->Start(request_, io_callback_, net_log_); |
| 1101 return rv; | 1116 return rv; |
| 1102 } | 1117 } |
| 1103 | 1118 |
| 1104 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 1119 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
| 1120 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1121 tracked_objects::ScopedTracker tracking_profile( |
| 1122 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1123 "422516 HttpCache::Transaction::DoSendRequestComplete")); |
| 1124 |
| 1105 if (!cache_.get()) | 1125 if (!cache_.get()) |
| 1106 return ERR_UNEXPECTED; | 1126 return ERR_UNEXPECTED; |
| 1107 | 1127 |
| 1108 // If requested, and we have a readable cache entry, and we have | 1128 // If requested, and we have a readable cache entry, and we have |
| 1109 // an error indicating that we're offline as opposed to in contact | 1129 // an error indicating that we're offline as opposed to in contact |
| 1110 // with a bad server, read from cache anyway. | 1130 // with a bad server, read from cache anyway. |
| 1111 if (IsOfflineError(result)) { | 1131 if (IsOfflineError(result)) { |
| 1112 if (mode_ == READ_WRITE && entry_ && !partial_) { | 1132 if (mode_ == READ_WRITE && entry_ && !partial_) { |
| 1113 RecordOfflineStatus(effective_load_flags_, | 1133 RecordOfflineStatus(effective_load_flags_, |
| 1114 OFFLINE_STATUS_DATA_AVAILABLE_OFFLINE); | 1134 OFFLINE_STATUS_DATA_AVAILABLE_OFFLINE); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 DCHECK(response); | 1170 DCHECK(response); |
| 1151 response_.cert_request_info = response->cert_request_info; | 1171 response_.cert_request_info = response->cert_request_info; |
| 1152 } else if (response_.was_cached) { | 1172 } else if (response_.was_cached) { |
| 1153 DoneWritingToEntry(true); | 1173 DoneWritingToEntry(true); |
| 1154 } | 1174 } |
| 1155 return result; | 1175 return result; |
| 1156 } | 1176 } |
| 1157 | 1177 |
| 1158 // We received the response headers and there is no error. | 1178 // We received the response headers and there is no error. |
| 1159 int HttpCache::Transaction::DoSuccessfulSendRequest() { | 1179 int HttpCache::Transaction::DoSuccessfulSendRequest() { |
| 1180 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1181 tracked_objects::ScopedTracker tracking_profile( |
| 1182 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1183 "422516 HttpCache::Transaction::DoSuccessfulSendRequest")); |
| 1184 |
| 1160 DCHECK(!new_response_); | 1185 DCHECK(!new_response_); |
| 1161 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 1186 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
| 1162 bool authentication_failure = false; | 1187 bool authentication_failure = false; |
| 1163 | 1188 |
| 1164 if (new_response->headers->response_code() == 401 || | 1189 if (new_response->headers->response_code() == 401 || |
| 1165 new_response->headers->response_code() == 407) { | 1190 new_response->headers->response_code() == 407) { |
| 1166 auth_response_ = *new_response; | 1191 auth_response_ = *new_response; |
| 1167 if (!reading_) | 1192 if (!reading_) |
| 1168 return OK; | 1193 return OK; |
| 1169 | 1194 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 } | 1276 } |
| 1252 UpdateTransactionPattern(PATTERN_ENTRY_UPDATED); | 1277 UpdateTransactionPattern(PATTERN_ENTRY_UPDATED); |
| 1253 mode_ = WRITE; | 1278 mode_ = WRITE; |
| 1254 } | 1279 } |
| 1255 | 1280 |
| 1256 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 1281 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
| 1257 return OK; | 1282 return OK; |
| 1258 } | 1283 } |
| 1259 | 1284 |
| 1260 int HttpCache::Transaction::DoNetworkRead() { | 1285 int HttpCache::Transaction::DoNetworkRead() { |
| 1286 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1287 tracked_objects::ScopedTracker tracking_profile( |
| 1288 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1289 "422516 HttpCache::Transaction::DoNetworkRead")); |
| 1290 |
| 1261 next_state_ = STATE_NETWORK_READ_COMPLETE; | 1291 next_state_ = STATE_NETWORK_READ_COMPLETE; |
| 1262 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); | 1292 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); |
| 1263 } | 1293 } |
| 1264 | 1294 |
| 1265 int HttpCache::Transaction::DoNetworkReadComplete(int result) { | 1295 int HttpCache::Transaction::DoNetworkReadComplete(int result) { |
| 1296 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1297 tracked_objects::ScopedTracker tracking_profile( |
| 1298 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1299 "422516 HttpCache::Transaction::DoNetworkReadComplete")); |
| 1300 |
| 1266 DCHECK(mode_ & WRITE || mode_ == NONE); | 1301 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 1267 | 1302 |
| 1268 if (!cache_.get()) | 1303 if (!cache_.get()) |
| 1269 return ERR_UNEXPECTED; | 1304 return ERR_UNEXPECTED; |
| 1270 | 1305 |
| 1271 // If there is an error or we aren't saving the data, we are done; just wait | 1306 // If there is an error or we aren't saving the data, we are done; just wait |
| 1272 // until the destructor runs to see if we can keep the data. | 1307 // until the destructor runs to see if we can keep the data. |
| 1273 if (mode_ == NONE || result < 0) | 1308 if (mode_ == NONE || result < 0) |
| 1274 return result; | 1309 return result; |
| 1275 | 1310 |
| 1276 next_state_ = STATE_CACHE_WRITE_DATA; | 1311 next_state_ = STATE_CACHE_WRITE_DATA; |
| 1277 return result; | 1312 return result; |
| 1278 } | 1313 } |
| 1279 | 1314 |
| 1280 int HttpCache::Transaction::DoInitEntry() { | 1315 int HttpCache::Transaction::DoInitEntry() { |
| 1316 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1317 tracked_objects::ScopedTracker tracking_profile( |
| 1318 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1319 "422516 HttpCache::Transaction::DoInitEntry")); |
| 1320 |
| 1281 DCHECK(!new_entry_); | 1321 DCHECK(!new_entry_); |
| 1282 | 1322 |
| 1283 if (!cache_.get()) | 1323 if (!cache_.get()) |
| 1284 return ERR_UNEXPECTED; | 1324 return ERR_UNEXPECTED; |
| 1285 | 1325 |
| 1286 if (mode_ == WRITE) { | 1326 if (mode_ == WRITE) { |
| 1287 next_state_ = STATE_DOOM_ENTRY; | 1327 next_state_ = STATE_DOOM_ENTRY; |
| 1288 return OK; | 1328 return OK; |
| 1289 } | 1329 } |
| 1290 | 1330 |
| 1291 next_state_ = STATE_OPEN_ENTRY; | 1331 next_state_ = STATE_OPEN_ENTRY; |
| 1292 return OK; | 1332 return OK; |
| 1293 } | 1333 } |
| 1294 | 1334 |
| 1295 int HttpCache::Transaction::DoOpenEntry() { | 1335 int HttpCache::Transaction::DoOpenEntry() { |
| 1336 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1337 tracked_objects::ScopedTracker tracking_profile( |
| 1338 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1339 "422516 HttpCache::Transaction::DoOpenEntry")); |
| 1340 |
| 1296 DCHECK(!new_entry_); | 1341 DCHECK(!new_entry_); |
| 1297 next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 1342 next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
| 1298 cache_pending_ = true; | 1343 cache_pending_ = true; |
| 1299 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY); | 1344 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
| 1300 first_cache_access_since_ = TimeTicks::Now(); | 1345 first_cache_access_since_ = TimeTicks::Now(); |
| 1301 return cache_->OpenEntry(cache_key_, &new_entry_, this); | 1346 return cache_->OpenEntry(cache_key_, &new_entry_, this); |
| 1302 } | 1347 } |
| 1303 | 1348 |
| 1304 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 1349 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |
| 1350 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1351 tracked_objects::ScopedTracker tracking_profile( |
| 1352 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1353 "422516 HttpCache::Transaction::DoOpenEntryComplete")); |
| 1354 |
| 1305 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 1355 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 1306 // OK, otherwise the cache will end up with an active entry without any | 1356 // OK, otherwise the cache will end up with an active entry without any |
| 1307 // transaction attached. | 1357 // transaction attached. |
| 1308 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); | 1358 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); |
| 1309 cache_pending_ = false; | 1359 cache_pending_ = false; |
| 1310 if (result == OK) { | 1360 if (result == OK) { |
| 1311 next_state_ = STATE_ADD_TO_ENTRY; | 1361 next_state_ = STATE_ADD_TO_ENTRY; |
| 1312 return OK; | 1362 return OK; |
| 1313 } | 1363 } |
| 1314 | 1364 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1338 } | 1388 } |
| 1339 if (cache_->mode() == PLAYBACK) | 1389 if (cache_->mode() == PLAYBACK) |
| 1340 DVLOG(1) << "Playback Cache Miss: " << request_->url; | 1390 DVLOG(1) << "Playback Cache Miss: " << request_->url; |
| 1341 | 1391 |
| 1342 // The entry does not exist, and we are not permitted to create a new entry, | 1392 // The entry does not exist, and we are not permitted to create a new entry, |
| 1343 // so we must fail. | 1393 // so we must fail. |
| 1344 return ERR_CACHE_MISS; | 1394 return ERR_CACHE_MISS; |
| 1345 } | 1395 } |
| 1346 | 1396 |
| 1347 int HttpCache::Transaction::DoCreateEntry() { | 1397 int HttpCache::Transaction::DoCreateEntry() { |
| 1398 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1399 tracked_objects::ScopedTracker tracking_profile( |
| 1400 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1401 "422516 HttpCache::Transaction::DoCreateEntry")); |
| 1402 |
| 1348 DCHECK(!new_entry_); | 1403 DCHECK(!new_entry_); |
| 1349 next_state_ = STATE_CREATE_ENTRY_COMPLETE; | 1404 next_state_ = STATE_CREATE_ENTRY_COMPLETE; |
| 1350 cache_pending_ = true; | 1405 cache_pending_ = true; |
| 1351 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY); | 1406 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
| 1352 return cache_->CreateEntry(cache_key_, &new_entry_, this); | 1407 return cache_->CreateEntry(cache_key_, &new_entry_, this); |
| 1353 } | 1408 } |
| 1354 | 1409 |
| 1355 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 1410 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
| 1411 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1412 tracked_objects::ScopedTracker tracking_profile( |
| 1413 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1414 "422516 HttpCache::Transaction::DoCreateEntryComplete")); |
| 1415 |
| 1356 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 1416 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 1357 // OK, otherwise the cache will end up with an active entry without any | 1417 // OK, otherwise the cache will end up with an active entry without any |
| 1358 // transaction attached. | 1418 // transaction attached. |
| 1359 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, | 1419 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, |
| 1360 result); | 1420 result); |
| 1361 cache_pending_ = false; | 1421 cache_pending_ = false; |
| 1362 next_state_ = STATE_ADD_TO_ENTRY; | 1422 next_state_ = STATE_ADD_TO_ENTRY; |
| 1363 | 1423 |
| 1364 if (result == ERR_CACHE_RACE) { | 1424 if (result == ERR_CACHE_RACE) { |
| 1365 next_state_ = STATE_INIT_ENTRY; | 1425 next_state_ = STATE_INIT_ENTRY; |
| 1366 return OK; | 1426 return OK; |
| 1367 } | 1427 } |
| 1368 | 1428 |
| 1369 if (result != OK) { | 1429 if (result != OK) { |
| 1370 // We have a race here: Maybe we failed to open the entry and decided to | 1430 // We have a race here: Maybe we failed to open the entry and decided to |
| 1371 // create one, but by the time we called create, another transaction already | 1431 // create one, but by the time we called create, another transaction already |
| 1372 // created the entry. If we want to eliminate this issue, we need an atomic | 1432 // created the entry. If we want to eliminate this issue, we need an atomic |
| 1373 // OpenOrCreate() method exposed by the disk cache. | 1433 // OpenOrCreate() method exposed by the disk cache. |
| 1374 DLOG(WARNING) << "Unable to create cache entry"; | 1434 DLOG(WARNING) << "Unable to create cache entry"; |
| 1375 mode_ = NONE; | 1435 mode_ = NONE; |
| 1376 if (partial_.get()) | 1436 if (partial_.get()) |
| 1377 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1437 partial_->RestoreHeaders(&custom_request_->extra_headers); |
| 1378 next_state_ = STATE_SEND_REQUEST; | 1438 next_state_ = STATE_SEND_REQUEST; |
| 1379 } | 1439 } |
| 1380 return OK; | 1440 return OK; |
| 1381 } | 1441 } |
| 1382 | 1442 |
| 1383 int HttpCache::Transaction::DoDoomEntry() { | 1443 int HttpCache::Transaction::DoDoomEntry() { |
| 1444 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1445 tracked_objects::ScopedTracker tracking_profile( |
| 1446 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1447 "422516 HttpCache::Transaction::DoDoomEntry")); |
| 1448 |
| 1384 next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 1449 next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
| 1385 cache_pending_ = true; | 1450 cache_pending_ = true; |
| 1386 if (first_cache_access_since_.is_null()) | 1451 if (first_cache_access_since_.is_null()) |
| 1387 first_cache_access_since_ = TimeTicks::Now(); | 1452 first_cache_access_since_ = TimeTicks::Now(); |
| 1388 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY); | 1453 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY); |
| 1389 return cache_->DoomEntry(cache_key_, this); | 1454 return cache_->DoomEntry(cache_key_, this); |
| 1390 } | 1455 } |
| 1391 | 1456 |
| 1392 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 1457 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
| 1458 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1459 tracked_objects::ScopedTracker tracking_profile( |
| 1460 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1461 "422516 HttpCache::Transaction::DoDoomEntryComplete")); |
| 1462 |
| 1393 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); | 1463 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); |
| 1394 next_state_ = STATE_CREATE_ENTRY; | 1464 next_state_ = STATE_CREATE_ENTRY; |
| 1395 cache_pending_ = false; | 1465 cache_pending_ = false; |
| 1396 if (result == ERR_CACHE_RACE) | 1466 if (result == ERR_CACHE_RACE) |
| 1397 next_state_ = STATE_INIT_ENTRY; | 1467 next_state_ = STATE_INIT_ENTRY; |
| 1398 return OK; | 1468 return OK; |
| 1399 } | 1469 } |
| 1400 | 1470 |
| 1401 int HttpCache::Transaction::DoAddToEntry() { | 1471 int HttpCache::Transaction::DoAddToEntry() { |
| 1472 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1473 tracked_objects::ScopedTracker tracking_profile( |
| 1474 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1475 "422516 HttpCache::Transaction::DoAddToEntry")); |
| 1476 |
| 1402 DCHECK(new_entry_); | 1477 DCHECK(new_entry_); |
| 1403 cache_pending_ = true; | 1478 cache_pending_ = true; |
| 1404 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 1479 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
| 1405 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); | 1480 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
| 1406 DCHECK(entry_lock_waiting_since_.is_null()); | 1481 DCHECK(entry_lock_waiting_since_.is_null()); |
| 1407 entry_lock_waiting_since_ = TimeTicks::Now(); | 1482 entry_lock_waiting_since_ = TimeTicks::Now(); |
| 1408 int rv = cache_->AddTransactionToEntry(new_entry_, this); | 1483 int rv = cache_->AddTransactionToEntry(new_entry_, this); |
| 1409 if (rv == ERR_IO_PENDING) { | 1484 if (rv == ERR_IO_PENDING) { |
| 1410 if (bypass_lock_for_test_) { | 1485 if (bypass_lock_for_test_) { |
| 1411 OnAddToEntryTimeout(entry_lock_waiting_since_); | 1486 OnAddToEntryTimeout(entry_lock_waiting_since_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1433 FROM_HERE, | 1508 FROM_HERE, |
| 1434 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | 1509 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, |
| 1435 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | 1510 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), |
| 1436 TimeDelta::FromMilliseconds(timeout_milliseconds)); | 1511 TimeDelta::FromMilliseconds(timeout_milliseconds)); |
| 1437 } | 1512 } |
| 1438 } | 1513 } |
| 1439 return rv; | 1514 return rv; |
| 1440 } | 1515 } |
| 1441 | 1516 |
| 1442 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1517 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
| 1518 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1519 tracked_objects::ScopedTracker tracking_profile( |
| 1520 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1521 "422516 HttpCache::Transaction::DoAddToEntryComplete")); |
| 1522 |
| 1443 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 1523 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, |
| 1444 result); | 1524 result); |
| 1445 const TimeDelta entry_lock_wait = | 1525 const TimeDelta entry_lock_wait = |
| 1446 TimeTicks::Now() - entry_lock_waiting_since_; | 1526 TimeTicks::Now() - entry_lock_waiting_since_; |
| 1447 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 1527 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
| 1448 | 1528 |
| 1449 entry_lock_waiting_since_ = TimeTicks(); | 1529 entry_lock_waiting_since_ = TimeTicks(); |
| 1450 DCHECK(new_entry_); | 1530 DCHECK(new_entry_); |
| 1451 cache_pending_ = false; | 1531 cache_pending_ = false; |
| 1452 | 1532 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 } else { | 1564 } else { |
| 1485 // We have to read the headers from the cached entry. | 1565 // We have to read the headers from the cached entry. |
| 1486 DCHECK(mode_ & READ_META); | 1566 DCHECK(mode_ & READ_META); |
| 1487 next_state_ = STATE_CACHE_READ_RESPONSE; | 1567 next_state_ = STATE_CACHE_READ_RESPONSE; |
| 1488 } | 1568 } |
| 1489 return OK; | 1569 return OK; |
| 1490 } | 1570 } |
| 1491 | 1571 |
| 1492 // We may end up here multiple times for a given request. | 1572 // We may end up here multiple times for a given request. |
| 1493 int HttpCache::Transaction::DoStartPartialCacheValidation() { | 1573 int HttpCache::Transaction::DoStartPartialCacheValidation() { |
| 1574 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1575 tracked_objects::ScopedTracker tracking_profile( |
| 1576 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1577 "422516 HttpCache::Transaction::DoStartPartialCacheValidation")); |
| 1578 |
| 1494 if (mode_ == NONE) | 1579 if (mode_ == NONE) |
| 1495 return OK; | 1580 return OK; |
| 1496 | 1581 |
| 1497 next_state_ = STATE_COMPLETE_PARTIAL_CACHE_VALIDATION; | 1582 next_state_ = STATE_COMPLETE_PARTIAL_CACHE_VALIDATION; |
| 1498 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); | 1583 return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_); |
| 1499 } | 1584 } |
| 1500 | 1585 |
| 1501 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { | 1586 int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) { |
| 1587 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1588 tracked_objects::ScopedTracker tracking_profile( |
| 1589 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1590 "422516 HttpCache::Transaction::DoCompletePartialCacheValidation")); |
| 1591 |
| 1502 if (!result) { | 1592 if (!result) { |
| 1503 // This is the end of the request. | 1593 // This is the end of the request. |
| 1504 if (mode_ & WRITE) { | 1594 if (mode_ & WRITE) { |
| 1505 DoneWritingToEntry(true); | 1595 DoneWritingToEntry(true); |
| 1506 } else { | 1596 } else { |
| 1507 cache_->DoneReadingFromEntry(entry_, this); | 1597 cache_->DoneReadingFromEntry(entry_, this); |
| 1508 entry_ = NULL; | 1598 entry_ = NULL; |
| 1509 } | 1599 } |
| 1510 return result; | 1600 return result; |
| 1511 } | 1601 } |
| 1512 | 1602 |
| 1513 if (result < 0) | 1603 if (result < 0) |
| 1514 return result; | 1604 return result; |
| 1515 | 1605 |
| 1516 partial_->PrepareCacheValidation(entry_->disk_entry, | 1606 partial_->PrepareCacheValidation(entry_->disk_entry, |
| 1517 &custom_request_->extra_headers); | 1607 &custom_request_->extra_headers); |
| 1518 | 1608 |
| 1519 if (reading_ && partial_->IsCurrentRangeCached()) { | 1609 if (reading_ && partial_->IsCurrentRangeCached()) { |
| 1520 next_state_ = STATE_CACHE_READ_DATA; | 1610 next_state_ = STATE_CACHE_READ_DATA; |
| 1521 return OK; | 1611 return OK; |
| 1522 } | 1612 } |
| 1523 | 1613 |
| 1524 return BeginCacheValidation(); | 1614 return BeginCacheValidation(); |
| 1525 } | 1615 } |
| 1526 | 1616 |
| 1527 // We received 304 or 206 and we want to update the cached response headers. | 1617 // We received 304 or 206 and we want to update the cached response headers. |
| 1528 int HttpCache::Transaction::DoUpdateCachedResponse() { | 1618 int HttpCache::Transaction::DoUpdateCachedResponse() { |
| 1619 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1620 tracked_objects::ScopedTracker tracking_profile( |
| 1621 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1622 "422516 HttpCache::Transaction::DoUpdateCachedResponse")); |
| 1623 |
| 1529 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1624 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1530 int rv = OK; | 1625 int rv = OK; |
| 1531 // Update cached response based on headers in new_response. | 1626 // Update cached response based on headers in new_response. |
| 1532 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? | 1627 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? |
| 1533 response_.headers->Update(*new_response_->headers.get()); | 1628 response_.headers->Update(*new_response_->headers.get()); |
| 1534 response_.response_time = new_response_->response_time; | 1629 response_.response_time = new_response_->response_time; |
| 1535 response_.request_time = new_response_->request_time; | 1630 response_.request_time = new_response_->request_time; |
| 1536 response_.network_accessed = new_response_->network_accessed; | 1631 response_.network_accessed = new_response_->network_accessed; |
| 1537 | 1632 |
| 1538 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { | 1633 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { |
| 1539 if (!entry_->doomed) { | 1634 if (!entry_->doomed) { |
| 1540 int ret = cache_->DoomEntry(cache_key_, NULL); | 1635 int ret = cache_->DoomEntry(cache_key_, NULL); |
| 1541 DCHECK_EQ(OK, ret); | 1636 DCHECK_EQ(OK, ret); |
| 1542 } | 1637 } |
| 1543 } else { | 1638 } else { |
| 1544 // If we are already reading, we already updated the headers for this | 1639 // If we are already reading, we already updated the headers for this |
| 1545 // request; doing it again will change Content-Length. | 1640 // request; doing it again will change Content-Length. |
| 1546 if (!reading_) { | 1641 if (!reading_) { |
| 1547 target_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1642 target_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1548 next_state_ = STATE_CACHE_WRITE_RESPONSE; | 1643 next_state_ = STATE_CACHE_WRITE_RESPONSE; |
| 1549 rv = OK; | 1644 rv = OK; |
| 1550 } | 1645 } |
| 1551 } | 1646 } |
| 1552 return rv; | 1647 return rv; |
| 1553 } | 1648 } |
| 1554 | 1649 |
| 1555 int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { | 1650 int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { |
| 1651 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1652 tracked_objects::ScopedTracker tracking_profile( |
| 1653 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1654 "422516 HttpCache::Transaction::DoUpdateCachedResponseComplete")); |
| 1655 |
| 1556 if (mode_ == UPDATE) { | 1656 if (mode_ == UPDATE) { |
| 1557 DCHECK(!handling_206_); | 1657 DCHECK(!handling_206_); |
| 1558 // We got a "not modified" response and already updated the corresponding | 1658 // We got a "not modified" response and already updated the corresponding |
| 1559 // cache entry above. | 1659 // cache entry above. |
| 1560 // | 1660 // |
| 1561 // By closing the cached entry now, we make sure that the 304 rather than | 1661 // By closing the cached entry now, we make sure that the 304 rather than |
| 1562 // the cached 200 response, is what will be returned to the user. | 1662 // the cached 200 response, is what will be returned to the user. |
| 1563 DoneWritingToEntry(true); | 1663 DoneWritingToEntry(true); |
| 1564 } else if (entry_ && !handling_206_) { | 1664 } else if (entry_ && !handling_206_) { |
| 1565 DCHECK_EQ(READ_WRITE, mode_); | 1665 DCHECK_EQ(READ_WRITE, mode_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1579 new_response_ = NULL; | 1679 new_response_ = NULL; |
| 1580 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 1680 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
| 1581 partial_->SetRangeToStartDownload(); | 1681 partial_->SetRangeToStartDownload(); |
| 1582 return OK; | 1682 return OK; |
| 1583 } | 1683 } |
| 1584 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 1684 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
| 1585 return OK; | 1685 return OK; |
| 1586 } | 1686 } |
| 1587 | 1687 |
| 1588 int HttpCache::Transaction::DoOverwriteCachedResponse() { | 1688 int HttpCache::Transaction::DoOverwriteCachedResponse() { |
| 1689 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1690 tracked_objects::ScopedTracker tracking_profile( |
| 1691 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1692 "422516 HttpCache::Transaction::DoOverwriteCachedResponse")); |
| 1693 |
| 1589 if (mode_ & READ) { | 1694 if (mode_ & READ) { |
| 1590 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1695 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1591 return OK; | 1696 return OK; |
| 1592 } | 1697 } |
| 1593 | 1698 |
| 1594 // We change the value of Content-Length for partial content. | 1699 // We change the value of Content-Length for partial content. |
| 1595 if (handling_206_ && partial_.get()) | 1700 if (handling_206_ && partial_.get()) |
| 1596 partial_->FixContentLength(new_response_->headers.get()); | 1701 partial_->FixContentLength(new_response_->headers.get()); |
| 1597 | 1702 |
| 1598 response_ = *new_response_; | 1703 response_ = *new_response_; |
| 1599 | 1704 |
| 1600 if (request_->method == "HEAD") { | 1705 if (request_->method == "HEAD") { |
| 1601 // This response is replacing the cached one. | 1706 // This response is replacing the cached one. |
| 1602 DoneWritingToEntry(false); | 1707 DoneWritingToEntry(false); |
| 1603 mode_ = NONE; | 1708 mode_ = NONE; |
| 1604 new_response_ = NULL; | 1709 new_response_ = NULL; |
| 1605 return OK; | 1710 return OK; |
| 1606 } | 1711 } |
| 1607 | 1712 |
| 1608 target_state_ = STATE_TRUNCATE_CACHED_DATA; | 1713 target_state_ = STATE_TRUNCATE_CACHED_DATA; |
| 1609 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : | 1714 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : |
| 1610 STATE_CACHE_WRITE_RESPONSE; | 1715 STATE_CACHE_WRITE_RESPONSE; |
| 1611 return OK; | 1716 return OK; |
| 1612 } | 1717 } |
| 1613 | 1718 |
| 1614 int HttpCache::Transaction::DoTruncateCachedData() { | 1719 int HttpCache::Transaction::DoTruncateCachedData() { |
| 1720 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1721 tracked_objects::ScopedTracker tracking_profile( |
| 1722 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1723 "422516 HttpCache::Transaction::DoTruncateCachedData")); |
| 1724 |
| 1615 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 1725 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
| 1616 if (!entry_) | 1726 if (!entry_) |
| 1617 return OK; | 1727 return OK; |
| 1618 if (net_log_.IsLogging()) | 1728 if (net_log_.IsLogging()) |
| 1619 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | 1729 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
| 1620 // Truncate the stream. | 1730 // Truncate the stream. |
| 1621 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); | 1731 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); |
| 1622 } | 1732 } |
| 1623 | 1733 |
| 1624 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 1734 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
| 1735 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1736 tracked_objects::ScopedTracker tracking_profile( |
| 1737 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1738 "422516 HttpCache::Transaction::DoTruncateCachedDataComplete")); |
| 1739 |
| 1625 if (entry_) { | 1740 if (entry_) { |
| 1626 if (net_log_.IsLogging()) { | 1741 if (net_log_.IsLogging()) { |
| 1627 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 1742 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
| 1628 result); | 1743 result); |
| 1629 } | 1744 } |
| 1630 } | 1745 } |
| 1631 | 1746 |
| 1632 next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 1747 next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
| 1633 return OK; | 1748 return OK; |
| 1634 } | 1749 } |
| 1635 | 1750 |
| 1636 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 1751 int HttpCache::Transaction::DoTruncateCachedMetadata() { |
| 1752 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1753 tracked_objects::ScopedTracker tracking_profile( |
| 1754 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1755 "422516 HttpCache::Transaction::DoTruncateCachedMetadata")); |
| 1756 |
| 1637 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 1757 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |
| 1638 if (!entry_) | 1758 if (!entry_) |
| 1639 return OK; | 1759 return OK; |
| 1640 | 1760 |
| 1641 if (net_log_.IsLogging()) | 1761 if (net_log_.IsLogging()) |
| 1642 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1762 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1643 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); | 1763 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); |
| 1644 } | 1764 } |
| 1645 | 1765 |
| 1646 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 1766 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
| 1767 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1768 tracked_objects::ScopedTracker tracking_profile( |
| 1769 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1770 "422516 HttpCache::Transaction::DoTruncateCachedMetadataComplete")); |
| 1771 |
| 1647 if (entry_) { | 1772 if (entry_) { |
| 1648 if (net_log_.IsLogging()) { | 1773 if (net_log_.IsLogging()) { |
| 1649 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 1774 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
| 1650 result); | 1775 result); |
| 1651 } | 1776 } |
| 1652 } | 1777 } |
| 1653 | 1778 |
| 1654 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1779 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1655 return OK; | 1780 return OK; |
| 1656 } | 1781 } |
| 1657 | 1782 |
| 1658 int HttpCache::Transaction::DoPartialHeadersReceived() { | 1783 int HttpCache::Transaction::DoPartialHeadersReceived() { |
| 1784 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1785 tracked_objects::ScopedTracker tracking_profile( |
| 1786 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1787 "422516 HttpCache::Transaction::DoPartialHeadersReceived")); |
| 1788 |
| 1659 new_response_ = NULL; | 1789 new_response_ = NULL; |
| 1660 if (entry_ && !partial_.get() && | 1790 if (entry_ && !partial_.get() && |
| 1661 entry_->disk_entry->GetDataSize(kMetadataIndex)) | 1791 entry_->disk_entry->GetDataSize(kMetadataIndex)) |
| 1662 next_state_ = STATE_CACHE_READ_METADATA; | 1792 next_state_ = STATE_CACHE_READ_METADATA; |
| 1663 | 1793 |
| 1664 if (!partial_.get()) | 1794 if (!partial_.get()) |
| 1665 return OK; | 1795 return OK; |
| 1666 | 1796 |
| 1667 if (reading_) { | 1797 if (reading_) { |
| 1668 if (network_trans_.get()) { | 1798 if (network_trans_.get()) { |
| 1669 next_state_ = STATE_NETWORK_READ; | 1799 next_state_ = STATE_NETWORK_READ; |
| 1670 } else { | 1800 } else { |
| 1671 next_state_ = STATE_CACHE_READ_DATA; | 1801 next_state_ = STATE_CACHE_READ_DATA; |
| 1672 } | 1802 } |
| 1673 } else if (mode_ != NONE) { | 1803 } else if (mode_ != NONE) { |
| 1674 // We are about to return the headers for a byte-range request to the user, | 1804 // We are about to return the headers for a byte-range request to the user, |
| 1675 // so let's fix them. | 1805 // so let's fix them. |
| 1676 partial_->FixResponseHeaders(response_.headers.get(), true); | 1806 partial_->FixResponseHeaders(response_.headers.get(), true); |
| 1677 } | 1807 } |
| 1678 return OK; | 1808 return OK; |
| 1679 } | 1809 } |
| 1680 | 1810 |
| 1681 int HttpCache::Transaction::DoCacheReadResponse() { | 1811 int HttpCache::Transaction::DoCacheReadResponse() { |
| 1812 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1813 tracked_objects::ScopedTracker tracking_profile( |
| 1814 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1815 "422516 HttpCache::Transaction::DoCacheReadResponse")); |
| 1816 |
| 1682 DCHECK(entry_); | 1817 DCHECK(entry_); |
| 1683 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; | 1818 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; |
| 1684 | 1819 |
| 1685 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); | 1820 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); |
| 1686 read_buf_ = new IOBuffer(io_buf_len_); | 1821 read_buf_ = new IOBuffer(io_buf_len_); |
| 1687 | 1822 |
| 1688 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); | 1823 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
| 1689 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), | 1824 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), |
| 1690 io_buf_len_, io_callback_); | 1825 io_buf_len_, io_callback_); |
| 1691 } | 1826 } |
| 1692 | 1827 |
| 1693 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1828 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| 1829 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1830 tracked_objects::ScopedTracker tracking_profile( |
| 1831 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1832 "422516 HttpCache::Transaction::DoCacheReadResponseComplete")); |
| 1833 |
| 1694 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1834 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| 1695 if (result != io_buf_len_ || | 1835 if (result != io_buf_len_ || |
| 1696 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, | 1836 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
| 1697 &response_, &truncated_)) { | 1837 &response_, &truncated_)) { |
| 1698 return OnCacheReadError(result, true); | 1838 return OnCacheReadError(result, true); |
| 1699 } | 1839 } |
| 1700 | 1840 |
| 1701 // cert_cache() will be null if the CertCacheTrial field trial is disabled. | 1841 // cert_cache() will be null if the CertCacheTrial field trial is disabled. |
| 1702 if (cache_->cert_cache() && response_.ssl_info.is_valid()) | 1842 if (cache_->cert_cache() && response_.ssl_info.is_valid()) |
| 1703 ReadCertChain(); | 1843 ReadCertChain(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1733 break; | 1873 break; |
| 1734 case WRITE: | 1874 case WRITE: |
| 1735 default: | 1875 default: |
| 1736 NOTREACHED(); | 1876 NOTREACHED(); |
| 1737 result = ERR_FAILED; | 1877 result = ERR_FAILED; |
| 1738 } | 1878 } |
| 1739 return result; | 1879 return result; |
| 1740 } | 1880 } |
| 1741 | 1881 |
| 1742 int HttpCache::Transaction::DoCacheWriteResponse() { | 1882 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1883 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1884 tracked_objects::ScopedTracker tracking_profile( |
| 1885 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1886 "422516 HttpCache::Transaction::DoCacheWriteResponse")); |
| 1887 |
| 1743 if (entry_) { | 1888 if (entry_) { |
| 1744 if (net_log_.IsLogging()) | 1889 if (net_log_.IsLogging()) |
| 1745 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1890 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1746 } | 1891 } |
| 1747 return WriteResponseInfoToEntry(false); | 1892 return WriteResponseInfoToEntry(false); |
| 1748 } | 1893 } |
| 1749 | 1894 |
| 1750 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1895 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
| 1896 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1897 tracked_objects::ScopedTracker tracking_profile( |
| 1898 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1899 "422516 HttpCache::Transaction::DoCacheWriteTruncatedResponse")); |
| 1900 |
| 1751 if (entry_) { | 1901 if (entry_) { |
| 1752 if (net_log_.IsLogging()) | 1902 if (net_log_.IsLogging()) |
| 1753 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1903 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1754 } | 1904 } |
| 1755 return WriteResponseInfoToEntry(true); | 1905 return WriteResponseInfoToEntry(true); |
| 1756 } | 1906 } |
| 1757 | 1907 |
| 1758 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1908 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
| 1909 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1910 tracked_objects::ScopedTracker tracking_profile( |
| 1911 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1912 "422516 HttpCache::Transaction::DoCacheWriteResponseComplete")); |
| 1913 |
| 1759 next_state_ = target_state_; | 1914 next_state_ = target_state_; |
| 1760 target_state_ = STATE_NONE; | 1915 target_state_ = STATE_NONE; |
| 1761 if (!entry_) | 1916 if (!entry_) |
| 1762 return OK; | 1917 return OK; |
| 1763 if (net_log_.IsLogging()) { | 1918 if (net_log_.IsLogging()) { |
| 1764 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 1919 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
| 1765 result); | 1920 result); |
| 1766 } | 1921 } |
| 1767 | 1922 |
| 1768 // Balance the AddRef from WriteResponseInfoToEntry. | 1923 // Balance the AddRef from WriteResponseInfoToEntry. |
| 1769 if (result != io_buf_len_) { | 1924 if (result != io_buf_len_) { |
| 1770 DLOG(ERROR) << "failed to write response info to cache"; | 1925 DLOG(ERROR) << "failed to write response info to cache"; |
| 1771 DoneWritingToEntry(false); | 1926 DoneWritingToEntry(false); |
| 1772 } | 1927 } |
| 1773 return OK; | 1928 return OK; |
| 1774 } | 1929 } |
| 1775 | 1930 |
| 1776 int HttpCache::Transaction::DoCacheReadMetadata() { | 1931 int HttpCache::Transaction::DoCacheReadMetadata() { |
| 1932 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1933 tracked_objects::ScopedTracker tracking_profile( |
| 1934 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1935 "422516 HttpCache::Transaction::DoCacheReadMetadata")); |
| 1936 |
| 1777 DCHECK(entry_); | 1937 DCHECK(entry_); |
| 1778 DCHECK(!response_.metadata.get()); | 1938 DCHECK(!response_.metadata.get()); |
| 1779 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 1939 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |
| 1780 | 1940 |
| 1781 response_.metadata = | 1941 response_.metadata = |
| 1782 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1942 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
| 1783 | 1943 |
| 1784 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); | 1944 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
| 1785 return entry_->disk_entry->ReadData(kMetadataIndex, 0, | 1945 return entry_->disk_entry->ReadData(kMetadataIndex, 0, |
| 1786 response_.metadata.get(), | 1946 response_.metadata.get(), |
| 1787 response_.metadata->size(), | 1947 response_.metadata->size(), |
| 1788 io_callback_); | 1948 io_callback_); |
| 1789 } | 1949 } |
| 1790 | 1950 |
| 1791 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1951 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
| 1952 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1953 tracked_objects::ScopedTracker tracking_profile( |
| 1954 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1955 "422516 HttpCache::Transaction::DoCacheReadMetadataComplete")); |
| 1956 |
| 1792 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1957 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| 1793 if (result != response_.metadata->size()) | 1958 if (result != response_.metadata->size()) |
| 1794 return OnCacheReadError(result, false); | 1959 return OnCacheReadError(result, false); |
| 1795 return OK; | 1960 return OK; |
| 1796 } | 1961 } |
| 1797 | 1962 |
| 1798 int HttpCache::Transaction::DoCacheQueryData() { | 1963 int HttpCache::Transaction::DoCacheQueryData() { |
| 1964 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1965 tracked_objects::ScopedTracker tracking_profile( |
| 1966 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1967 "422516 HttpCache::Transaction::DoCacheQueryData")); |
| 1968 |
| 1799 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; | 1969 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; |
| 1800 return entry_->disk_entry->ReadyForSparseIO(io_callback_); | 1970 return entry_->disk_entry->ReadyForSparseIO(io_callback_); |
| 1801 } | 1971 } |
| 1802 | 1972 |
| 1803 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { | 1973 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { |
| 1974 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1975 tracked_objects::ScopedTracker tracking_profile( |
| 1976 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1977 "422516 HttpCache::Transaction::DoCacheQueryDataComplete")); |
| 1978 |
| 1804 if (result == ERR_NOT_IMPLEMENTED) { | 1979 if (result == ERR_NOT_IMPLEMENTED) { |
| 1805 // Restart the request overwriting the cache entry. | 1980 // Restart the request overwriting the cache entry. |
| 1806 // TODO(pasko): remove this workaround as soon as the SimpleBackendImpl | 1981 // TODO(pasko): remove this workaround as soon as the SimpleBackendImpl |
| 1807 // supports Sparse IO. | 1982 // supports Sparse IO. |
| 1808 return DoRestartPartialRequest(); | 1983 return DoRestartPartialRequest(); |
| 1809 } | 1984 } |
| 1810 DCHECK_EQ(OK, result); | 1985 DCHECK_EQ(OK, result); |
| 1811 if (!cache_.get()) | 1986 if (!cache_.get()) |
| 1812 return ERR_UNEXPECTED; | 1987 return ERR_UNEXPECTED; |
| 1813 | 1988 |
| 1814 return ValidateEntryHeadersAndContinue(); | 1989 return ValidateEntryHeadersAndContinue(); |
| 1815 } | 1990 } |
| 1816 | 1991 |
| 1817 int HttpCache::Transaction::DoCacheReadData() { | 1992 int HttpCache::Transaction::DoCacheReadData() { |
| 1993 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1994 tracked_objects::ScopedTracker tracking_profile( |
| 1995 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1996 "422516 HttpCache::Transaction::DoCacheReadData")); |
| 1997 |
| 1818 DCHECK(entry_); | 1998 DCHECK(entry_); |
| 1819 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1999 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
| 1820 | 2000 |
| 1821 if (net_log_.IsLogging()) | 2001 if (net_log_.IsLogging()) |
| 1822 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); | 2002 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); |
| 1823 if (partial_.get()) { | 2003 if (partial_.get()) { |
| 1824 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, | 2004 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, |
| 1825 io_callback_); | 2005 io_callback_); |
| 1826 } | 2006 } |
| 1827 | 2007 |
| 1828 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 2008 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
| 1829 read_buf_.get(), io_buf_len_, | 2009 read_buf_.get(), io_buf_len_, |
| 1830 io_callback_); | 2010 io_callback_); |
| 1831 } | 2011 } |
| 1832 | 2012 |
| 1833 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 2013 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
| 2014 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 2015 tracked_objects::ScopedTracker tracking_profile( |
| 2016 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2017 "422516 HttpCache::Transaction::DoCacheReadDataComplete")); |
| 2018 |
| 1834 if (net_log_.IsLogging()) { | 2019 if (net_log_.IsLogging()) { |
| 1835 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, | 2020 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, |
| 1836 result); | 2021 result); |
| 1837 } | 2022 } |
| 1838 | 2023 |
| 1839 if (!cache_.get()) | 2024 if (!cache_.get()) |
| 1840 return ERR_UNEXPECTED; | 2025 return ERR_UNEXPECTED; |
| 1841 | 2026 |
| 1842 if (partial_.get()) { | 2027 if (partial_.get()) { |
| 1843 // Partial requests are confusing to report in histograms because they may | 2028 // Partial requests are confusing to report in histograms because they may |
| 1844 // have multiple underlying requests. | 2029 // have multiple underlying requests. |
| 1845 UpdateTransactionPattern(PATTERN_NOT_COVERED); | 2030 UpdateTransactionPattern(PATTERN_NOT_COVERED); |
| 1846 return DoPartialCacheReadCompleted(result); | 2031 return DoPartialCacheReadCompleted(result); |
| 1847 } | 2032 } |
| 1848 | 2033 |
| 1849 if (result > 0) { | 2034 if (result > 0) { |
| 1850 read_offset_ += result; | 2035 read_offset_ += result; |
| 1851 } else if (result == 0) { // End of file. | 2036 } else if (result == 0) { // End of file. |
| 1852 RecordHistograms(); | 2037 RecordHistograms(); |
| 1853 cache_->DoneReadingFromEntry(entry_, this); | 2038 cache_->DoneReadingFromEntry(entry_, this); |
| 1854 entry_ = NULL; | 2039 entry_ = NULL; |
| 1855 } else { | 2040 } else { |
| 1856 return OnCacheReadError(result, false); | 2041 return OnCacheReadError(result, false); |
| 1857 } | 2042 } |
| 1858 return result; | 2043 return result; |
| 1859 } | 2044 } |
| 1860 | 2045 |
| 1861 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 2046 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
| 2047 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 2048 tracked_objects::ScopedTracker tracking_profile( |
| 2049 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2050 "422516 HttpCache::Transaction::DoCacheWriteData")); |
| 2051 |
| 1862 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 2052 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
| 1863 write_len_ = num_bytes; | 2053 write_len_ = num_bytes; |
| 1864 if (entry_) { | 2054 if (entry_) { |
| 1865 if (net_log_.IsLogging()) | 2055 if (net_log_.IsLogging()) |
| 1866 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | 2056 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
| 1867 } | 2057 } |
| 1868 | 2058 |
| 1869 return AppendResponseDataToEntry(read_buf_.get(), num_bytes, io_callback_); | 2059 return AppendResponseDataToEntry(read_buf_.get(), num_bytes, io_callback_); |
| 1870 } | 2060 } |
| 1871 | 2061 |
| 1872 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 2062 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
| 2063 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 2064 tracked_objects::ScopedTracker tracking_profile( |
| 2065 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2066 "422516 HttpCache::Transaction::DoCacheWriteDataComplete")); |
| 2067 |
| 1873 if (entry_) { | 2068 if (entry_) { |
| 1874 if (net_log_.IsLogging()) { | 2069 if (net_log_.IsLogging()) { |
| 1875 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 2070 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
| 1876 result); | 2071 result); |
| 1877 } | 2072 } |
| 1878 } | 2073 } |
| 1879 // Balance the AddRef from DoCacheWriteData. | 2074 // Balance the AddRef from DoCacheWriteData. |
| 1880 if (!cache_.get()) | 2075 if (!cache_.get()) |
| 1881 return ERR_UNEXPECTED; | 2076 return ERR_UNEXPECTED; |
| 1882 | 2077 |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2952 | 3147 |
| 2953 void HttpCache::Transaction::OnIOComplete(int result) { | 3148 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2954 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 3149 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 2955 tracked_objects::ScopedTracker tracking_profile( | 3150 tracked_objects::ScopedTracker tracking_profile( |
| 2956 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); | 3151 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); |
| 2957 | 3152 |
| 2958 DoLoop(result); | 3153 DoLoop(result); |
| 2959 } | 3154 } |
| 2960 | 3155 |
| 2961 } // namespace net | 3156 } // namespace net |
| OLD | NEW |