| 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 10 matching lines...) Expand all Loading... |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 23 #include "base/metrics/sparse_histogram.h" | 23 #include "base/metrics/sparse_histogram.h" |
| 24 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 25 #include "base/strings/string_number_conversions.h" // For HexEncode. | 25 #include "base/strings/string_number_conversions.h" // For HexEncode. |
| 26 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
| 27 #include "base/strings/string_util.h" // For LowerCaseEqualsASCII. | 27 #include "base/strings/string_util.h" // For LowerCaseEqualsASCII. |
| 28 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 29 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
| 30 #include "base/time/clock.h" | 30 #include "base/time/clock.h" |
| 31 #include "base/trace_event/trace_event.h" |
| 31 #include "base/values.h" | 32 #include "base/values.h" |
| 32 #include "net/base/auth.h" | 33 #include "net/base/auth.h" |
| 33 #include "net/base/load_flags.h" | 34 #include "net/base/load_flags.h" |
| 34 #include "net/base/load_timing_info.h" | 35 #include "net/base/load_timing_info.h" |
| 35 #include "net/base/upload_data_stream.h" | 36 #include "net/base/upload_data_stream.h" |
| 36 #include "net/cert/cert_status_flags.h" | 37 #include "net/cert/cert_status_flags.h" |
| 37 #include "net/cert/x509_certificate.h" | 38 #include "net/cert/x509_certificate.h" |
| 38 #include "net/disk_cache/disk_cache.h" | 39 #include "net/disk_cache/disk_cache.h" |
| 39 #include "net/http/http_network_session.h" | 40 #include "net/http/http_network_session.h" |
| 40 #include "net/http/http_request_info.h" | 41 #include "net/http/http_request_info.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 io_buf_len_(0), | 183 io_buf_len_(0), |
| 183 read_offset_(0), | 184 read_offset_(0), |
| 184 effective_load_flags_(0), | 185 effective_load_flags_(0), |
| 185 write_len_(0), | 186 write_len_(0), |
| 186 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), | 187 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), |
| 187 validation_cause_(VALIDATION_CAUSE_UNDEFINED), | 188 validation_cause_(VALIDATION_CAUSE_UNDEFINED), |
| 188 total_received_bytes_(0), | 189 total_received_bytes_(0), |
| 189 total_sent_bytes_(0), | 190 total_sent_bytes_(0), |
| 190 websocket_handshake_stream_base_create_helper_(NULL), | 191 websocket_handshake_stream_base_create_helper_(NULL), |
| 191 weak_factory_(this) { | 192 weak_factory_(this) { |
| 193 TRACE_EVENT0("io", "HttpCacheTransaction::Transaction"); |
| 192 static_assert(HttpCache::Transaction::kNumValidationHeaders == | 194 static_assert(HttpCache::Transaction::kNumValidationHeaders == |
| 193 arraysize(kValidationHeaders), | 195 arraysize(kValidationHeaders), |
| 194 "invalid number of validation headers"); | 196 "invalid number of validation headers"); |
| 195 | 197 |
| 196 io_callback_ = base::Bind(&Transaction::OnIOComplete, | 198 io_callback_ = base::Bind(&Transaction::OnIOComplete, |
| 197 weak_factory_.GetWeakPtr()); | 199 weak_factory_.GetWeakPtr()); |
| 198 } | 200 } |
| 199 | 201 |
| 200 HttpCache::Transaction::~Transaction() { | 202 HttpCache::Transaction::~Transaction() { |
| 203 TRACE_EVENT0("io", "HttpCacheTransaction::~Transaction"); |
| 201 // We may have to issue another IO, but we should never invoke the callback_ | 204 // We may have to issue another IO, but we should never invoke the callback_ |
| 202 // after this point. | 205 // after this point. |
| 203 callback_.Reset(); | 206 callback_.Reset(); |
| 204 | 207 |
| 205 if (cache_) { | 208 if (cache_) { |
| 206 if (entry_) { | 209 if (entry_) { |
| 207 bool cancel_request = reading_ && response_.headers.get(); | 210 bool cancel_request = reading_ && response_.headers.get(); |
| 208 if (cancel_request) { | 211 if (cancel_request) { |
| 209 if (partial_) { | 212 if (partial_) { |
| 210 entry_->disk_entry->CancelSparseIO(); | 213 entry_->disk_entry->CancelSparseIO(); |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 next_state_ = STATE_INIT_ENTRY; | 953 next_state_ = STATE_INIT_ENTRY; |
| 951 } | 954 } |
| 952 | 955 |
| 953 // This is only set if we have something to do with the response. | 956 // This is only set if we have something to do with the response. |
| 954 range_requested_ = (partial_.get() != NULL); | 957 range_requested_ = (partial_.get() != NULL); |
| 955 | 958 |
| 956 return OK; | 959 return OK; |
| 957 } | 960 } |
| 958 | 961 |
| 959 int HttpCache::Transaction::DoInitEntry() { | 962 int HttpCache::Transaction::DoInitEntry() { |
| 963 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); |
| 960 DCHECK(!new_entry_); | 964 DCHECK(!new_entry_); |
| 961 | 965 |
| 962 if (!cache_.get()) | 966 if (!cache_.get()) |
| 963 return ERR_UNEXPECTED; | 967 return ERR_UNEXPECTED; |
| 964 | 968 |
| 965 if (mode_ == WRITE) { | 969 if (mode_ == WRITE) { |
| 966 next_state_ = STATE_DOOM_ENTRY; | 970 next_state_ = STATE_DOOM_ENTRY; |
| 967 return OK; | 971 return OK; |
| 968 } | 972 } |
| 969 | 973 |
| 970 next_state_ = STATE_OPEN_ENTRY; | 974 next_state_ = STATE_OPEN_ENTRY; |
| 971 return OK; | 975 return OK; |
| 972 } | 976 } |
| 973 | 977 |
| 974 int HttpCache::Transaction::DoOpenEntry() { | 978 int HttpCache::Transaction::DoOpenEntry() { |
| 979 TRACE_EVENT0("io", "HttpCacheTransaction::DoOpenEntry"); |
| 975 DCHECK(!new_entry_); | 980 DCHECK(!new_entry_); |
| 976 next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 981 next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
| 977 cache_pending_ = true; | 982 cache_pending_ = true; |
| 978 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_OPEN_ENTRY); | 983 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_OPEN_ENTRY); |
| 979 first_cache_access_since_ = TimeTicks::Now(); | 984 first_cache_access_since_ = TimeTicks::Now(); |
| 980 return cache_->OpenEntry(cache_key_, &new_entry_, this); | 985 return cache_->OpenEntry(cache_key_, &new_entry_, this); |
| 981 } | 986 } |
| 982 | 987 |
| 983 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 988 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |
| 989 TRACE_EVENT0("io", "HttpCacheTransaction::DoOpenEntryComplete"); |
| 984 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 990 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 985 // OK, otherwise the cache will end up with an active entry without any | 991 // OK, otherwise the cache will end up with an active entry without any |
| 986 // transaction attached. | 992 // transaction attached. |
| 987 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, | 993 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, |
| 988 result); | 994 result); |
| 989 cache_pending_ = false; | 995 cache_pending_ = false; |
| 990 if (result == OK) { | 996 if (result == OK) { |
| 991 next_state_ = STATE_ADD_TO_ENTRY; | 997 next_state_ = STATE_ADD_TO_ENTRY; |
| 992 return OK; | 998 return OK; |
| 993 } | 999 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1016 next_state_ = STATE_SEND_REQUEST; | 1022 next_state_ = STATE_SEND_REQUEST; |
| 1017 return OK; | 1023 return OK; |
| 1018 } | 1024 } |
| 1019 | 1025 |
| 1020 // The entry does not exist, and we are not permitted to create a new entry, | 1026 // The entry does not exist, and we are not permitted to create a new entry, |
| 1021 // so we must fail. | 1027 // so we must fail. |
| 1022 return ERR_CACHE_MISS; | 1028 return ERR_CACHE_MISS; |
| 1023 } | 1029 } |
| 1024 | 1030 |
| 1025 int HttpCache::Transaction::DoDoomEntry() { | 1031 int HttpCache::Transaction::DoDoomEntry() { |
| 1032 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntry"); |
| 1026 next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 1033 next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
| 1027 cache_pending_ = true; | 1034 cache_pending_ = true; |
| 1028 if (first_cache_access_since_.is_null()) | 1035 if (first_cache_access_since_.is_null()) |
| 1029 first_cache_access_since_ = TimeTicks::Now(); | 1036 first_cache_access_since_ = TimeTicks::Now(); |
| 1030 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); | 1037 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); |
| 1031 return cache_->DoomEntry(cache_key_, this); | 1038 return cache_->DoomEntry(cache_key_, this); |
| 1032 } | 1039 } |
| 1033 | 1040 |
| 1034 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 1041 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
| 1042 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntryComplete"); |
| 1035 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, | 1043 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, |
| 1036 result); | 1044 result); |
| 1037 next_state_ = STATE_CREATE_ENTRY; | 1045 next_state_ = STATE_CREATE_ENTRY; |
| 1038 cache_pending_ = false; | 1046 cache_pending_ = false; |
| 1039 if (result == ERR_CACHE_RACE) | 1047 if (result == ERR_CACHE_RACE) |
| 1040 next_state_ = STATE_INIT_ENTRY; | 1048 next_state_ = STATE_INIT_ENTRY; |
| 1041 return OK; | 1049 return OK; |
| 1042 } | 1050 } |
| 1043 | 1051 |
| 1044 int HttpCache::Transaction::DoCreateEntry() { | 1052 int HttpCache::Transaction::DoCreateEntry() { |
| 1053 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntry"); |
| 1045 DCHECK(!new_entry_); | 1054 DCHECK(!new_entry_); |
| 1046 next_state_ = STATE_CREATE_ENTRY_COMPLETE; | 1055 next_state_ = STATE_CREATE_ENTRY_COMPLETE; |
| 1047 cache_pending_ = true; | 1056 cache_pending_ = true; |
| 1048 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); | 1057 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); |
| 1049 return cache_->CreateEntry(cache_key_, &new_entry_, this); | 1058 return cache_->CreateEntry(cache_key_, &new_entry_, this); |
| 1050 } | 1059 } |
| 1051 | 1060 |
| 1052 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 1061 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
| 1062 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete"); |
| 1053 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 1063 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 1054 // OK, otherwise the cache will end up with an active entry without any | 1064 // OK, otherwise the cache will end up with an active entry without any |
| 1055 // transaction attached. | 1065 // transaction attached. |
| 1056 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, | 1066 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, |
| 1057 result); | 1067 result); |
| 1058 cache_pending_ = false; | 1068 cache_pending_ = false; |
| 1059 switch (result) { | 1069 switch (result) { |
| 1060 case OK: | 1070 case OK: |
| 1061 next_state_ = STATE_ADD_TO_ENTRY; | 1071 next_state_ = STATE_ADD_TO_ENTRY; |
| 1062 break; | 1072 break; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1073 DLOG(WARNING) << "Unable to create cache entry"; | 1083 DLOG(WARNING) << "Unable to create cache entry"; |
| 1074 mode_ = NONE; | 1084 mode_ = NONE; |
| 1075 if (partial_) | 1085 if (partial_) |
| 1076 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1086 partial_->RestoreHeaders(&custom_request_->extra_headers); |
| 1077 next_state_ = STATE_SEND_REQUEST; | 1087 next_state_ = STATE_SEND_REQUEST; |
| 1078 } | 1088 } |
| 1079 return OK; | 1089 return OK; |
| 1080 } | 1090 } |
| 1081 | 1091 |
| 1082 int HttpCache::Transaction::DoAddToEntry() { | 1092 int HttpCache::Transaction::DoAddToEntry() { |
| 1093 TRACE_EVENT0("io", "HttpCacheTransaction::DoAddToEntry"); |
| 1083 DCHECK(new_entry_); | 1094 DCHECK(new_entry_); |
| 1084 cache_pending_ = true; | 1095 cache_pending_ = true; |
| 1085 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 1096 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
| 1086 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY); | 1097 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY); |
| 1087 DCHECK(entry_lock_waiting_since_.is_null()); | 1098 DCHECK(entry_lock_waiting_since_.is_null()); |
| 1088 entry_lock_waiting_since_ = TimeTicks::Now(); | 1099 entry_lock_waiting_since_ = TimeTicks::Now(); |
| 1089 int rv = cache_->AddTransactionToEntry(new_entry_, this); | 1100 int rv = cache_->AddTransactionToEntry(new_entry_, this); |
| 1090 if (rv == ERR_IO_PENDING) { | 1101 if (rv == ERR_IO_PENDING) { |
| 1091 if (bypass_lock_for_test_) { | 1102 if (bypass_lock_for_test_) { |
| 1092 OnAddToEntryTimeout(entry_lock_waiting_since_); | 1103 OnAddToEntryTimeout(entry_lock_waiting_since_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1114 FROM_HERE, | 1125 FROM_HERE, |
| 1115 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | 1126 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, |
| 1116 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | 1127 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), |
| 1117 TimeDelta::FromMilliseconds(timeout_milliseconds)); | 1128 TimeDelta::FromMilliseconds(timeout_milliseconds)); |
| 1118 } | 1129 } |
| 1119 } | 1130 } |
| 1120 return rv; | 1131 return rv; |
| 1121 } | 1132 } |
| 1122 | 1133 |
| 1123 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1134 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
| 1135 TRACE_EVENT0("io", "HttpCacheTransaction::DoAddToEntryComplete"); |
| 1124 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY, | 1136 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY, |
| 1125 result); | 1137 result); |
| 1126 const TimeDelta entry_lock_wait = | 1138 const TimeDelta entry_lock_wait = |
| 1127 TimeTicks::Now() - entry_lock_waiting_since_; | 1139 TimeTicks::Now() - entry_lock_waiting_since_; |
| 1128 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 1140 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
| 1129 | 1141 |
| 1130 entry_lock_waiting_since_ = TimeTicks(); | 1142 entry_lock_waiting_since_ = TimeTicks(); |
| 1131 DCHECK(new_entry_); | 1143 DCHECK(new_entry_); |
| 1132 cache_pending_ = false; | 1144 cache_pending_ = false; |
| 1133 | 1145 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 next_state_ = STATE_SEND_REQUEST; | 1178 next_state_ = STATE_SEND_REQUEST; |
| 1167 } else { | 1179 } else { |
| 1168 // We have to read the headers from the cached entry. | 1180 // We have to read the headers from the cached entry. |
| 1169 DCHECK(mode_ & READ_META); | 1181 DCHECK(mode_ & READ_META); |
| 1170 next_state_ = STATE_CACHE_READ_RESPONSE; | 1182 next_state_ = STATE_CACHE_READ_RESPONSE; |
| 1171 } | 1183 } |
| 1172 return OK; | 1184 return OK; |
| 1173 } | 1185 } |
| 1174 | 1186 |
| 1175 int HttpCache::Transaction::DoCacheReadResponse() { | 1187 int HttpCache::Transaction::DoCacheReadResponse() { |
| 1188 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadResponse"); |
| 1176 DCHECK(entry_); | 1189 DCHECK(entry_); |
| 1177 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; | 1190 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; |
| 1178 | 1191 |
| 1179 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); | 1192 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); |
| 1180 read_buf_ = new IOBuffer(io_buf_len_); | 1193 read_buf_ = new IOBuffer(io_buf_len_); |
| 1181 | 1194 |
| 1182 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1195 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
| 1183 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), | 1196 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), |
| 1184 io_buf_len_, io_callback_); | 1197 io_buf_len_, io_callback_); |
| 1185 } | 1198 } |
| 1186 | 1199 |
| 1187 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1200 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| 1201 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadResponseComplete"); |
| 1188 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, | 1202 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, |
| 1189 result); | 1203 result); |
| 1190 if (result != io_buf_len_ || | 1204 if (result != io_buf_len_ || |
| 1191 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_, | 1205 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_, |
| 1192 &truncated_)) { | 1206 &truncated_)) { |
| 1193 return OnCacheReadError(result, true); | 1207 return OnCacheReadError(result, true); |
| 1194 } | 1208 } |
| 1195 | 1209 |
| 1196 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1210 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1197 int64_t full_response_length = response_.headers->GetContentLength(); | 1211 int64_t full_response_length = response_.headers->GetContentLength(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1225 // valid for this transaction but the bit needs to be flipped in storage. | 1239 // valid for this transaction but the bit needs to be flipped in storage. |
| 1226 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH; | 1240 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH; |
| 1227 return OK; | 1241 return OK; |
| 1228 } | 1242 } |
| 1229 | 1243 |
| 1230 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; | 1244 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; |
| 1231 return OK; | 1245 return OK; |
| 1232 } | 1246 } |
| 1233 | 1247 |
| 1234 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() { | 1248 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() { |
| 1249 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheToggleUnusedSincePrefetch"); |
| 1235 // Write back the toggled value for the next use of this entry. | 1250 // Write back the toggled value for the next use of this entry. |
| 1236 response_.unused_since_prefetch = !response_.unused_since_prefetch; | 1251 response_.unused_since_prefetch = !response_.unused_since_prefetch; |
| 1237 | 1252 |
| 1238 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this | 1253 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this |
| 1239 // transaction then metadata will be written to cache twice. If prefetching | 1254 // transaction then metadata will be written to cache twice. If prefetching |
| 1240 // becomes more common, consider combining the writes. | 1255 // becomes more common, consider combining the writes. |
| 1241 | 1256 |
| 1242 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE; | 1257 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE; |
| 1243 return WriteResponseInfoToEntry(false); | 1258 return WriteResponseInfoToEntry(false); |
| 1244 } | 1259 } |
| 1245 | 1260 |
| 1246 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete( | 1261 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete( |
| 1247 int result) { | 1262 int result) { |
| 1263 TRACE_EVENT0( |
| 1264 "net", "HttpCacheTransaction::DoCacheToggleUnusedSincePrefetchComplete"); |
| 1248 // Restore the original value for this transaction. | 1265 // Restore the original value for this transaction. |
| 1249 response_.unused_since_prefetch = !response_.unused_since_prefetch; | 1266 response_.unused_since_prefetch = !response_.unused_since_prefetch; |
| 1250 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; | 1267 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; |
| 1251 return OnWriteResponseInfoToEntryComplete(result); | 1268 return OnWriteResponseInfoToEntryComplete(result); |
| 1252 } | 1269 } |
| 1253 | 1270 |
| 1254 int HttpCache::Transaction::DoCacheDispatchValidation() { | 1271 int HttpCache::Transaction::DoCacheDispatchValidation() { |
| 1272 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheDispatchValidation"); |
| 1255 // We now have access to the cache entry. | 1273 // We now have access to the cache entry. |
| 1256 // | 1274 // |
| 1257 // o if we are a reader for the transaction, then we can start reading the | 1275 // o if we are a reader for the transaction, then we can start reading the |
| 1258 // cache entry. | 1276 // cache entry. |
| 1259 // | 1277 // |
| 1260 // o if we can read or write, then we should check if the cache entry needs | 1278 // o if we can read or write, then we should check if the cache entry needs |
| 1261 // to be validated and then issue a network request if needed or just read | 1279 // to be validated and then issue a network request if needed or just read |
| 1262 // from the cache if the cache entry is already valid. | 1280 // from the cache if the cache entry is already valid. |
| 1263 // | 1281 // |
| 1264 // o if we are set to UPDATE, then we are handling an externally | 1282 // o if we are set to UPDATE, then we are handling an externally |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 | 1344 |
| 1327 if (reading_ && partial_->IsCurrentRangeCached()) { | 1345 if (reading_ && partial_->IsCurrentRangeCached()) { |
| 1328 next_state_ = STATE_CACHE_READ_DATA; | 1346 next_state_ = STATE_CACHE_READ_DATA; |
| 1329 return OK; | 1347 return OK; |
| 1330 } | 1348 } |
| 1331 | 1349 |
| 1332 return BeginCacheValidation(); | 1350 return BeginCacheValidation(); |
| 1333 } | 1351 } |
| 1334 | 1352 |
| 1335 int HttpCache::Transaction::DoSendRequest() { | 1353 int HttpCache::Transaction::DoSendRequest() { |
| 1354 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequest"); |
| 1336 DCHECK(mode_ & WRITE || mode_ == NONE); | 1355 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 1337 DCHECK(!network_trans_.get()); | 1356 DCHECK(!network_trans_.get()); |
| 1338 | 1357 |
| 1339 send_request_since_ = TimeTicks::Now(); | 1358 send_request_since_ = TimeTicks::Now(); |
| 1340 | 1359 |
| 1341 // Create a network transaction. | 1360 // Create a network transaction. |
| 1342 int rv = | 1361 int rv = |
| 1343 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); | 1362 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); |
| 1344 if (rv != OK) | 1363 if (rv != OK) |
| 1345 return rv; | 1364 return rv; |
| 1346 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); | 1365 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); |
| 1347 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); | 1366 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); |
| 1348 | 1367 |
| 1349 // Old load timing information, if any, is now obsolete. | 1368 // Old load timing information, if any, is now obsolete. |
| 1350 old_network_trans_load_timing_.reset(); | 1369 old_network_trans_load_timing_.reset(); |
| 1351 old_remote_endpoint_ = IPEndPoint(); | 1370 old_remote_endpoint_ = IPEndPoint(); |
| 1352 | 1371 |
| 1353 if (websocket_handshake_stream_base_create_helper_) | 1372 if (websocket_handshake_stream_base_create_helper_) |
| 1354 network_trans_->SetWebSocketHandshakeStreamCreateHelper( | 1373 network_trans_->SetWebSocketHandshakeStreamCreateHelper( |
| 1355 websocket_handshake_stream_base_create_helper_); | 1374 websocket_handshake_stream_base_create_helper_); |
| 1356 | 1375 |
| 1357 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1376 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 1358 rv = network_trans_->Start(request_, io_callback_, net_log_); | 1377 rv = network_trans_->Start(request_, io_callback_, net_log_); |
| 1359 return rv; | 1378 return rv; |
| 1360 } | 1379 } |
| 1361 | 1380 |
| 1362 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 1381 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
| 1382 TRACE_EVENT0("io", "HttpCacheTransaction::DoSendRequestComplete"); |
| 1363 if (!cache_.get()) | 1383 if (!cache_.get()) |
| 1364 return ERR_UNEXPECTED; | 1384 return ERR_UNEXPECTED; |
| 1365 | 1385 |
| 1366 // If we tried to conditionalize the request and failed, we know | 1386 // If we tried to conditionalize the request and failed, we know |
| 1367 // we won't be reading from the cache after this point. | 1387 // we won't be reading from the cache after this point. |
| 1368 if (couldnt_conditionalize_request_) | 1388 if (couldnt_conditionalize_request_) |
| 1369 mode_ = WRITE; | 1389 mode_ = WRITE; |
| 1370 | 1390 |
| 1371 if (result == OK) { | 1391 if (result == OK) { |
| 1372 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; | 1392 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1388 response_.cert_request_info = response->cert_request_info; | 1408 response_.cert_request_info = response->cert_request_info; |
| 1389 } else if (response_.was_cached) { | 1409 } else if (response_.was_cached) { |
| 1390 DoneWritingToEntry(true); | 1410 DoneWritingToEntry(true); |
| 1391 } | 1411 } |
| 1392 | 1412 |
| 1393 return result; | 1413 return result; |
| 1394 } | 1414 } |
| 1395 | 1415 |
| 1396 // We received the response headers and there is no error. | 1416 // We received the response headers and there is no error. |
| 1397 int HttpCache::Transaction::DoSuccessfulSendRequest() { | 1417 int HttpCache::Transaction::DoSuccessfulSendRequest() { |
| 1418 TRACE_EVENT0("io", "HttpCacheTransaction::DoSuccessfulSendRequest"); |
| 1398 DCHECK(!new_response_); | 1419 DCHECK(!new_response_); |
| 1399 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 1420 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
| 1400 | 1421 |
| 1401 if (new_response->headers->response_code() == 401 || | 1422 if (new_response->headers->response_code() == 401 || |
| 1402 new_response->headers->response_code() == 407) { | 1423 new_response->headers->response_code() == 407) { |
| 1403 SetAuthResponse(*new_response); | 1424 SetAuthResponse(*new_response); |
| 1404 if (!reading_) | 1425 if (!reading_) |
| 1405 return OK; | 1426 return OK; |
| 1406 | 1427 |
| 1407 // We initiated a second request the caller doesn't know about. We should be | 1428 // We initiated a second request the caller doesn't know about. We should be |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); | 1514 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); |
| 1494 mode_ = WRITE; | 1515 mode_ = WRITE; |
| 1495 } | 1516 } |
| 1496 | 1517 |
| 1497 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 1518 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
| 1498 return OK; | 1519 return OK; |
| 1499 } | 1520 } |
| 1500 | 1521 |
| 1501 // We received 304 or 206 and we want to update the cached response headers. | 1522 // We received 304 or 206 and we want to update the cached response headers. |
| 1502 int HttpCache::Transaction::DoUpdateCachedResponse() { | 1523 int HttpCache::Transaction::DoUpdateCachedResponse() { |
| 1524 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse"); |
| 1503 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1525 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1504 int rv = OK; | 1526 int rv = OK; |
| 1505 // Update the cached response based on the headers and properties of | 1527 // Update the cached response based on the headers and properties of |
| 1506 // new_response_. | 1528 // new_response_. |
| 1507 response_.headers->Update(*new_response_->headers.get()); | 1529 response_.headers->Update(*new_response_->headers.get()); |
| 1508 response_.response_time = new_response_->response_time; | 1530 response_.response_time = new_response_->response_time; |
| 1509 response_.request_time = new_response_->request_time; | 1531 response_.request_time = new_response_->request_time; |
| 1510 response_.network_accessed = new_response_->network_accessed; | 1532 response_.network_accessed = new_response_->network_accessed; |
| 1511 response_.unused_since_prefetch = new_response_->unused_since_prefetch; | 1533 response_.unused_since_prefetch = new_response_->unused_since_prefetch; |
| 1512 response_.ssl_info = new_response_->ssl_info; | 1534 response_.ssl_info = new_response_->ssl_info; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1530 // request; doing it again will change Content-Length. | 1552 // request; doing it again will change Content-Length. |
| 1531 if (!reading_) { | 1553 if (!reading_) { |
| 1532 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE; | 1554 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE; |
| 1533 rv = OK; | 1555 rv = OK; |
| 1534 } | 1556 } |
| 1535 } | 1557 } |
| 1536 return rv; | 1558 return rv; |
| 1537 } | 1559 } |
| 1538 | 1560 |
| 1539 int HttpCache::Transaction::DoCacheWriteUpdatedResponse() { | 1561 int HttpCache::Transaction::DoCacheWriteUpdatedResponse() { |
| 1562 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteUpdatedResponse"); |
| 1563 |
| 1540 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE; | 1564 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE; |
| 1541 return WriteResponseInfoToEntry(false); | 1565 return WriteResponseInfoToEntry(false); |
| 1542 } | 1566 } |
| 1543 | 1567 |
| 1544 int HttpCache::Transaction::DoCacheWriteUpdatedResponseComplete(int result) { | 1568 int HttpCache::Transaction::DoCacheWriteUpdatedResponseComplete(int result) { |
| 1569 TRACE_EVENT0("io", |
| 1570 "HttpCacheTransaction::DoCacheWriteUpdatedResponseComplete"); |
| 1545 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1571 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1546 return OnWriteResponseInfoToEntryComplete(result); | 1572 return OnWriteResponseInfoToEntryComplete(result); |
| 1547 } | 1573 } |
| 1548 | 1574 |
| 1549 int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { | 1575 int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { |
| 1576 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponseComplete"); |
| 1550 if (mode_ == UPDATE) { | 1577 if (mode_ == UPDATE) { |
| 1551 DCHECK(!handling_206_); | 1578 DCHECK(!handling_206_); |
| 1552 // We got a "not modified" response and already updated the corresponding | 1579 // We got a "not modified" response and already updated the corresponding |
| 1553 // cache entry above. | 1580 // cache entry above. |
| 1554 // | 1581 // |
| 1555 // By closing the cached entry now, we make sure that the 304 rather than | 1582 // By closing the cached entry now, we make sure that the 304 rather than |
| 1556 // the cached 200 response, is what will be returned to the user. | 1583 // the cached 200 response, is what will be returned to the user. |
| 1557 DoneWritingToEntry(true); | 1584 DoneWritingToEntry(true); |
| 1558 } else if (entry_ && !handling_206_) { | 1585 } else if (entry_ && !handling_206_) { |
| 1559 DCHECK_EQ(READ_WRITE, mode_); | 1586 DCHECK_EQ(READ_WRITE, mode_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1572 new_response_ = NULL; | 1599 new_response_ = NULL; |
| 1573 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 1600 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
| 1574 partial_->SetRangeToStartDownload(); | 1601 partial_->SetRangeToStartDownload(); |
| 1575 return OK; | 1602 return OK; |
| 1576 } | 1603 } |
| 1577 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 1604 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
| 1578 return OK; | 1605 return OK; |
| 1579 } | 1606 } |
| 1580 | 1607 |
| 1581 int HttpCache::Transaction::DoOverwriteCachedResponse() { | 1608 int HttpCache::Transaction::DoOverwriteCachedResponse() { |
| 1609 TRACE_EVENT0("io", "HttpCacheTransaction::DoOverwriteCachedResponse"); |
| 1582 if (mode_ & READ) { | 1610 if (mode_ & READ) { |
| 1583 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1611 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1584 return OK; | 1612 return OK; |
| 1585 } | 1613 } |
| 1586 | 1614 |
| 1587 // We change the value of Content-Length for partial content. | 1615 // We change the value of Content-Length for partial content. |
| 1588 if (handling_206_ && partial_) | 1616 if (handling_206_ && partial_) |
| 1589 partial_->FixContentLength(new_response_->headers.get()); | 1617 partial_->FixContentLength(new_response_->headers.get()); |
| 1590 | 1618 |
| 1591 SetResponse(*new_response_); | 1619 SetResponse(*new_response_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1606 partial_->FixResponseHeaders(response_.headers.get(), true); | 1634 partial_->FixResponseHeaders(response_.headers.get(), true); |
| 1607 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1635 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1608 return OK; | 1636 return OK; |
| 1609 } | 1637 } |
| 1610 | 1638 |
| 1611 next_state_ = STATE_CACHE_WRITE_RESPONSE; | 1639 next_state_ = STATE_CACHE_WRITE_RESPONSE; |
| 1612 return OK; | 1640 return OK; |
| 1613 } | 1641 } |
| 1614 | 1642 |
| 1615 int HttpCache::Transaction::DoCacheWriteResponse() { | 1643 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1644 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteResponse"); |
| 1616 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; | 1645 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; |
| 1617 return WriteResponseInfoToEntry(truncated_); | 1646 return WriteResponseInfoToEntry(truncated_); |
| 1618 } | 1647 } |
| 1619 | 1648 |
| 1620 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1649 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
| 1650 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteResponseComplete"); |
| 1621 next_state_ = STATE_TRUNCATE_CACHED_DATA; | 1651 next_state_ = STATE_TRUNCATE_CACHED_DATA; |
| 1622 return OnWriteResponseInfoToEntryComplete(result); | 1652 return OnWriteResponseInfoToEntryComplete(result); |
| 1623 } | 1653 } |
| 1624 | 1654 |
| 1625 int HttpCache::Transaction::DoTruncateCachedData() { | 1655 int HttpCache::Transaction::DoTruncateCachedData() { |
| 1656 TRACE_EVENT0("io", "HttpCacheTransaction::DoTruncateCachedData"); |
| 1626 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 1657 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
| 1627 if (!entry_) | 1658 if (!entry_) |
| 1628 return OK; | 1659 return OK; |
| 1629 if (net_log_.IsCapturing()) | 1660 if (net_log_.IsCapturing()) |
| 1630 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); | 1661 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); |
| 1631 // Truncate the stream. | 1662 // Truncate the stream. |
| 1632 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); | 1663 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); |
| 1633 } | 1664 } |
| 1634 | 1665 |
| 1635 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 1666 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
| 1667 TRACE_EVENT0("io", "HttpCacheTransaction::DoInitEntry"); |
| 1636 if (entry_) { | 1668 if (entry_) { |
| 1637 if (net_log_.IsCapturing()) { | 1669 if (net_log_.IsCapturing()) { |
| 1638 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, | 1670 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, |
| 1639 result); | 1671 result); |
| 1640 } | 1672 } |
| 1641 } | 1673 } |
| 1642 | 1674 |
| 1643 next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 1675 next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
| 1644 return OK; | 1676 return OK; |
| 1645 } | 1677 } |
| 1646 | 1678 |
| 1647 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 1679 int HttpCache::Transaction::DoTruncateCachedMetadata() { |
| 1680 TRACE_EVENT0("io", "HttpCacheTransaction::DoTruncateCachedMetadata"); |
| 1648 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 1681 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |
| 1649 if (!entry_) | 1682 if (!entry_) |
| 1650 return OK; | 1683 return OK; |
| 1651 | 1684 |
| 1652 if (net_log_.IsCapturing()) | 1685 if (net_log_.IsCapturing()) |
| 1653 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO); | 1686 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO); |
| 1654 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); | 1687 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); |
| 1655 } | 1688 } |
| 1656 | 1689 |
| 1657 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 1690 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
| 1691 TRACE_EVENT0("io", "HttpCacheTransaction::DoTruncateCachedMetadataComplete"); |
| 1658 if (entry_) { | 1692 if (entry_) { |
| 1659 if (net_log_.IsCapturing()) { | 1693 if (net_log_.IsCapturing()) { |
| 1660 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_INFO, | 1694 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_INFO, |
| 1661 result); | 1695 result); |
| 1662 } | 1696 } |
| 1663 } | 1697 } |
| 1664 | 1698 |
| 1665 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1699 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1666 return OK; | 1700 return OK; |
| 1667 } | 1701 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1682 } | 1716 } |
| 1683 } else if (mode_ != NONE) { | 1717 } else if (mode_ != NONE) { |
| 1684 // We are about to return the headers for a byte-range request to the user, | 1718 // We are about to return the headers for a byte-range request to the user, |
| 1685 // so let's fix them. | 1719 // so let's fix them. |
| 1686 partial_->FixResponseHeaders(response_.headers.get(), true); | 1720 partial_->FixResponseHeaders(response_.headers.get(), true); |
| 1687 } | 1721 } |
| 1688 return OK; | 1722 return OK; |
| 1689 } | 1723 } |
| 1690 | 1724 |
| 1691 int HttpCache::Transaction::DoCacheReadMetadata() { | 1725 int HttpCache::Transaction::DoCacheReadMetadata() { |
| 1726 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); |
| 1692 DCHECK(entry_); | 1727 DCHECK(entry_); |
| 1693 DCHECK(!response_.metadata.get()); | 1728 DCHECK(!response_.metadata.get()); |
| 1694 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 1729 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |
| 1695 | 1730 |
| 1696 response_.metadata = | 1731 response_.metadata = |
| 1697 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1732 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
| 1698 | 1733 |
| 1699 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1734 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
| 1700 return entry_->disk_entry->ReadData(kMetadataIndex, 0, | 1735 return entry_->disk_entry->ReadData(kMetadataIndex, 0, |
| 1701 response_.metadata.get(), | 1736 response_.metadata.get(), |
| 1702 response_.metadata->size(), | 1737 response_.metadata->size(), |
| 1703 io_callback_); | 1738 io_callback_); |
| 1704 } | 1739 } |
| 1705 | 1740 |
| 1706 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1741 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
| 1742 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadataComplete"); |
| 1707 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, | 1743 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, |
| 1708 result); | 1744 result); |
| 1709 if (result != response_.metadata->size()) | 1745 if (result != response_.metadata->size()) |
| 1710 return OnCacheReadError(result, false); | 1746 return OnCacheReadError(result, false); |
| 1711 return OK; | 1747 return OK; |
| 1712 } | 1748 } |
| 1713 | 1749 |
| 1714 int HttpCache::Transaction::DoNetworkRead() { | 1750 int HttpCache::Transaction::DoNetworkRead() { |
| 1751 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkRead"); |
| 1715 next_state_ = STATE_NETWORK_READ_COMPLETE; | 1752 next_state_ = STATE_NETWORK_READ_COMPLETE; |
| 1716 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); | 1753 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); |
| 1717 } | 1754 } |
| 1718 | 1755 |
| 1719 int HttpCache::Transaction::DoNetworkReadComplete(int result) { | 1756 int HttpCache::Transaction::DoNetworkReadComplete(int result) { |
| 1757 TRACE_EVENT0("io", "HttpCacheTransaction::DoNetworkReadComplete"); |
| 1720 DCHECK(mode_ & WRITE || mode_ == NONE); | 1758 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 1721 | 1759 |
| 1722 if (!cache_.get()) | 1760 if (!cache_.get()) |
| 1723 return ERR_UNEXPECTED; | 1761 return ERR_UNEXPECTED; |
| 1724 | 1762 |
| 1725 // If there is an error or we aren't saving the data, we are done; just wait | 1763 // If there is an error or we aren't saving the data, we are done; just wait |
| 1726 // until the destructor runs to see if we can keep the data. | 1764 // until the destructor runs to see if we can keep the data. |
| 1727 if (mode_ == NONE || result < 0) | 1765 if (mode_ == NONE || result < 0) |
| 1728 return result; | 1766 return result; |
| 1729 | 1767 |
| 1730 next_state_ = STATE_CACHE_WRITE_DATA; | 1768 next_state_ = STATE_CACHE_WRITE_DATA; |
| 1731 return result; | 1769 return result; |
| 1732 } | 1770 } |
| 1733 | 1771 |
| 1734 int HttpCache::Transaction::DoCacheReadData() { | 1772 int HttpCache::Transaction::DoCacheReadData() { |
| 1773 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadData"); |
| 1735 if (request_->method == "HEAD") | 1774 if (request_->method == "HEAD") |
| 1736 return 0; | 1775 return 0; |
| 1737 | 1776 |
| 1738 DCHECK(entry_); | 1777 DCHECK(entry_); |
| 1739 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1778 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
| 1740 | 1779 |
| 1741 if (net_log_.IsCapturing()) | 1780 if (net_log_.IsCapturing()) |
| 1742 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA); | 1781 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA); |
| 1743 if (partial_) { | 1782 if (partial_) { |
| 1744 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, | 1783 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, |
| 1745 io_callback_); | 1784 io_callback_); |
| 1746 } | 1785 } |
| 1747 | 1786 |
| 1748 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1787 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
| 1749 read_buf_.get(), io_buf_len_, | 1788 read_buf_.get(), io_buf_len_, |
| 1750 io_callback_); | 1789 io_callback_); |
| 1751 } | 1790 } |
| 1752 | 1791 |
| 1753 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 1792 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
| 1793 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadDataComplete"); |
| 1754 if (net_log_.IsCapturing()) { | 1794 if (net_log_.IsCapturing()) { |
| 1755 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA, | 1795 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA, |
| 1756 result); | 1796 result); |
| 1757 } | 1797 } |
| 1758 | 1798 |
| 1759 if (!cache_.get()) | 1799 if (!cache_.get()) |
| 1760 return ERR_UNEXPECTED; | 1800 return ERR_UNEXPECTED; |
| 1761 | 1801 |
| 1762 if (partial_) { | 1802 if (partial_) { |
| 1763 // Partial requests are confusing to report in histograms because they may | 1803 // Partial requests are confusing to report in histograms because they may |
| 1764 // have multiple underlying requests. | 1804 // have multiple underlying requests. |
| 1765 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); | 1805 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); |
| 1766 return DoPartialCacheReadCompleted(result); | 1806 return DoPartialCacheReadCompleted(result); |
| 1767 } | 1807 } |
| 1768 | 1808 |
| 1769 if (result > 0) { | 1809 if (result > 0) { |
| 1770 read_offset_ += result; | 1810 read_offset_ += result; |
| 1771 } else if (result == 0) { // End of file. | 1811 } else if (result == 0) { // End of file. |
| 1772 RecordHistograms(); | 1812 RecordHistograms(); |
| 1773 cache_->DoneReadingFromEntry(entry_, this); | 1813 cache_->DoneReadingFromEntry(entry_, this); |
| 1774 entry_ = NULL; | 1814 entry_ = NULL; |
| 1775 } else { | 1815 } else { |
| 1776 return OnCacheReadError(result, false); | 1816 return OnCacheReadError(result, false); |
| 1777 } | 1817 } |
| 1778 return result; | 1818 return result; |
| 1779 } | 1819 } |
| 1780 | 1820 |
| 1781 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1821 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
| 1822 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteData"); |
| 1782 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1823 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
| 1783 write_len_ = num_bytes; | 1824 write_len_ = num_bytes; |
| 1784 if (entry_) { | 1825 if (entry_) { |
| 1785 if (net_log_.IsCapturing()) | 1826 if (net_log_.IsCapturing()) |
| 1786 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); | 1827 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); |
| 1787 } | 1828 } |
| 1788 | 1829 |
| 1789 if (!entry_ || !num_bytes) | 1830 if (!entry_ || !num_bytes) |
| 1790 return num_bytes; | 1831 return num_bytes; |
| 1791 | 1832 |
| 1792 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1833 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1793 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), | 1834 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), |
| 1794 num_bytes, io_callback_); | 1835 num_bytes, io_callback_); |
| 1795 } | 1836 } |
| 1796 | 1837 |
| 1797 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1838 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
| 1839 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteDataComplete"); |
| 1798 if (entry_) { | 1840 if (entry_) { |
| 1799 if (net_log_.IsCapturing()) { | 1841 if (net_log_.IsCapturing()) { |
| 1800 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, | 1842 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, |
| 1801 result); | 1843 result); |
| 1802 } | 1844 } |
| 1803 } | 1845 } |
| 1804 if (!cache_.get()) | 1846 if (!cache_.get()) |
| 1805 return ERR_UNEXPECTED; | 1847 return ERR_UNEXPECTED; |
| 1806 | 1848 |
| 1807 if (result != write_len_) { | 1849 if (result != write_len_) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1832 if (done_reading_ || !entry_ || partial_ || | 1874 if (done_reading_ || !entry_ || partial_ || |
| 1833 response_.headers->GetContentLength() <= 0) { | 1875 response_.headers->GetContentLength() <= 0) { |
| 1834 DoneWritingToEntry(true); | 1876 DoneWritingToEntry(true); |
| 1835 } | 1877 } |
| 1836 } | 1878 } |
| 1837 | 1879 |
| 1838 return result; | 1880 return result; |
| 1839 } | 1881 } |
| 1840 | 1882 |
| 1841 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1883 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
| 1884 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteTruncatedResponse"); |
| 1842 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE; | 1885 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE; |
| 1843 return WriteResponseInfoToEntry(true); | 1886 return WriteResponseInfoToEntry(true); |
| 1844 } | 1887 } |
| 1845 | 1888 |
| 1846 int HttpCache::Transaction::DoCacheWriteTruncatedResponseComplete(int result) { | 1889 int HttpCache::Transaction::DoCacheWriteTruncatedResponseComplete(int result) { |
| 1890 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteTruncatedResponse"); |
| 1891 |
| 1847 return OnWriteResponseInfoToEntryComplete(result); | 1892 return OnWriteResponseInfoToEntryComplete(result); |
| 1848 } | 1893 } |
| 1849 | 1894 |
| 1850 //----------------------------------------------------------------------------- | 1895 //----------------------------------------------------------------------------- |
| 1851 | 1896 |
| 1852 void HttpCache::Transaction::SetRequest(const NetLogWithSource& net_log, | 1897 void HttpCache::Transaction::SetRequest(const NetLogWithSource& net_log, |
| 1853 const HttpRequestInfo* request) { | 1898 const HttpRequestInfo* request) { |
| 1854 net_log_ = net_log; | 1899 net_log_ = net_log; |
| 1855 request_ = request; | 1900 request_ = request; |
| 1856 effective_load_flags_ = request_->load_flags; | 1901 effective_load_flags_ = request_->load_flags; |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2940 default: | 2985 default: |
| 2941 NOTREACHED(); | 2986 NOTREACHED(); |
| 2942 } | 2987 } |
| 2943 } | 2988 } |
| 2944 | 2989 |
| 2945 void HttpCache::Transaction::OnIOComplete(int result) { | 2990 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2946 DoLoop(result); | 2991 DoLoop(result); |
| 2947 } | 2992 } |
| 2948 | 2993 |
| 2949 } // namespace net | 2994 } // namespace net |
| OLD | NEW |