Chromium Code Reviews| 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_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::Transaction", this, | |
|
caseq
2016/10/20 21:23:31
Not sure if you really want to have flow event her
xunjieli
2016/10/20 21:33:11
I'd actually prefer full function names over humab
jkarlin
2016/10/24 17:20:58
We want the flow arrows on the IO thread. This way
| |
| 194 TRACE_EVENT_FLAG_FLOW_OUT); | |
| 192 static_assert(HttpCache::Transaction::kNumValidationHeaders == | 195 static_assert(HttpCache::Transaction::kNumValidationHeaders == |
| 193 arraysize(kValidationHeaders), | 196 arraysize(kValidationHeaders), |
| 194 "invalid number of validation headers"); | 197 "invalid number of validation headers"); |
| 195 | 198 |
| 196 io_callback_ = base::Bind(&Transaction::OnIOComplete, | 199 io_callback_ = base::Bind(&Transaction::OnIOComplete, |
| 197 weak_factory_.GetWeakPtr()); | 200 weak_factory_.GetWeakPtr()); |
| 198 } | 201 } |
| 199 | 202 |
| 200 HttpCache::Transaction::~Transaction() { | 203 HttpCache::Transaction::~Transaction() { |
| 204 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::~Transaction", this, | |
| 205 TRACE_EVENT_FLAG_FLOW_IN); | |
| 201 // We may have to issue another IO, but we should never invoke the callback_ | 206 // We may have to issue another IO, but we should never invoke the callback_ |
| 202 // after this point. | 207 // after this point. |
| 203 callback_.Reset(); | 208 callback_.Reset(); |
| 204 | 209 |
| 205 if (cache_) { | 210 if (cache_) { |
| 206 if (entry_) { | 211 if (entry_) { |
| 207 bool cancel_request = reading_ && response_.headers.get(); | 212 bool cancel_request = reading_ && response_.headers.get(); |
| 208 if (cancel_request) { | 213 if (cancel_request) { |
| 209 if (partial_) { | 214 if (partial_) { |
| 210 entry_->disk_entry->CancelSparseIO(); | 215 entry_->disk_entry->CancelSparseIO(); |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 next_state_ = STATE_INIT_ENTRY; | 955 next_state_ = STATE_INIT_ENTRY; |
| 951 } | 956 } |
| 952 | 957 |
| 953 // This is only set if we have something to do with the response. | 958 // This is only set if we have something to do with the response. |
| 954 range_requested_ = (partial_.get() != NULL); | 959 range_requested_ = (partial_.get() != NULL); |
| 955 | 960 |
| 956 return OK; | 961 return OK; |
| 957 } | 962 } |
| 958 | 963 |
| 959 int HttpCache::Transaction::DoInitEntry() { | 964 int HttpCache::Transaction::DoInitEntry() { |
| 965 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoInitEntry", this, | |
| 966 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 960 DCHECK(!new_entry_); | 967 DCHECK(!new_entry_); |
| 961 | 968 |
| 962 if (!cache_.get()) | 969 if (!cache_.get()) |
| 963 return ERR_UNEXPECTED; | 970 return ERR_UNEXPECTED; |
| 964 | 971 |
| 965 if (mode_ == WRITE) { | 972 if (mode_ == WRITE) { |
| 966 next_state_ = STATE_DOOM_ENTRY; | 973 next_state_ = STATE_DOOM_ENTRY; |
| 967 return OK; | 974 return OK; |
| 968 } | 975 } |
| 969 | 976 |
| 970 next_state_ = STATE_OPEN_ENTRY; | 977 next_state_ = STATE_OPEN_ENTRY; |
| 971 return OK; | 978 return OK; |
| 972 } | 979 } |
| 973 | 980 |
| 974 int HttpCache::Transaction::DoOpenEntry() { | 981 int HttpCache::Transaction::DoOpenEntry() { |
| 982 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoOpenEntry", this, | |
| 983 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 975 DCHECK(!new_entry_); | 984 DCHECK(!new_entry_); |
| 976 next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 985 next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
| 977 cache_pending_ = true; | 986 cache_pending_ = true; |
| 978 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_OPEN_ENTRY); | 987 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_OPEN_ENTRY); |
| 979 first_cache_access_since_ = TimeTicks::Now(); | 988 first_cache_access_since_ = TimeTicks::Now(); |
| 980 return cache_->OpenEntry(cache_key_, &new_entry_, this); | 989 return cache_->OpenEntry(cache_key_, &new_entry_, this); |
| 981 } | 990 } |
| 982 | 991 |
| 983 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 992 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |
| 993 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoOpenEntryComplete", | |
| 994 this, | |
| 995 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 984 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 996 // 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 | 997 // OK, otherwise the cache will end up with an active entry without any |
| 986 // transaction attached. | 998 // transaction attached. |
| 987 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, | 999 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, |
| 988 result); | 1000 result); |
| 989 cache_pending_ = false; | 1001 cache_pending_ = false; |
| 990 if (result == OK) { | 1002 if (result == OK) { |
| 991 next_state_ = STATE_ADD_TO_ENTRY; | 1003 next_state_ = STATE_ADD_TO_ENTRY; |
| 992 return OK; | 1004 return OK; |
| 993 } | 1005 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1016 next_state_ = STATE_SEND_REQUEST; | 1028 next_state_ = STATE_SEND_REQUEST; |
| 1017 return OK; | 1029 return OK; |
| 1018 } | 1030 } |
| 1019 | 1031 |
| 1020 // The entry does not exist, and we are not permitted to create a new entry, | 1032 // The entry does not exist, and we are not permitted to create a new entry, |
| 1021 // so we must fail. | 1033 // so we must fail. |
| 1022 return ERR_CACHE_MISS; | 1034 return ERR_CACHE_MISS; |
| 1023 } | 1035 } |
| 1024 | 1036 |
| 1025 int HttpCache::Transaction::DoDoomEntry() { | 1037 int HttpCache::Transaction::DoDoomEntry() { |
| 1038 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoDoomEntry", this, | |
| 1039 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1026 next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 1040 next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
| 1027 cache_pending_ = true; | 1041 cache_pending_ = true; |
| 1028 if (first_cache_access_since_.is_null()) | 1042 if (first_cache_access_since_.is_null()) |
| 1029 first_cache_access_since_ = TimeTicks::Now(); | 1043 first_cache_access_since_ = TimeTicks::Now(); |
| 1030 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); | 1044 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); |
| 1031 return cache_->DoomEntry(cache_key_, this); | 1045 return cache_->DoomEntry(cache_key_, this); |
| 1032 } | 1046 } |
| 1033 | 1047 |
| 1034 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 1048 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
| 1049 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoDoomEntryComplete", | |
| 1050 this, | |
| 1051 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1035 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, | 1052 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, |
| 1036 result); | 1053 result); |
| 1037 next_state_ = STATE_CREATE_ENTRY; | 1054 next_state_ = STATE_CREATE_ENTRY; |
| 1038 cache_pending_ = false; | 1055 cache_pending_ = false; |
| 1039 if (result == ERR_CACHE_RACE) | 1056 if (result == ERR_CACHE_RACE) |
| 1040 next_state_ = STATE_INIT_ENTRY; | 1057 next_state_ = STATE_INIT_ENTRY; |
| 1041 return OK; | 1058 return OK; |
| 1042 } | 1059 } |
| 1043 | 1060 |
| 1044 int HttpCache::Transaction::DoCreateEntry() { | 1061 int HttpCache::Transaction::DoCreateEntry() { |
| 1062 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCreateEntry", this, | |
| 1063 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1045 DCHECK(!new_entry_); | 1064 DCHECK(!new_entry_); |
| 1046 next_state_ = STATE_CREATE_ENTRY_COMPLETE; | 1065 next_state_ = STATE_CREATE_ENTRY_COMPLETE; |
| 1047 cache_pending_ = true; | 1066 cache_pending_ = true; |
| 1048 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); | 1067 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); |
| 1049 return cache_->CreateEntry(cache_key_, &new_entry_, this); | 1068 return cache_->CreateEntry(cache_key_, &new_entry_, this); |
| 1050 } | 1069 } |
| 1051 | 1070 |
| 1052 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 1071 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
| 1072 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCreateEntryComplete", | |
| 1073 this, | |
| 1074 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1053 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 1075 // 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 | 1076 // OK, otherwise the cache will end up with an active entry without any |
| 1055 // transaction attached. | 1077 // transaction attached. |
| 1056 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, | 1078 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, |
| 1057 result); | 1079 result); |
| 1058 cache_pending_ = false; | 1080 cache_pending_ = false; |
| 1059 switch (result) { | 1081 switch (result) { |
| 1060 case OK: | 1082 case OK: |
| 1061 next_state_ = STATE_ADD_TO_ENTRY; | 1083 next_state_ = STATE_ADD_TO_ENTRY; |
| 1062 break; | 1084 break; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1073 DLOG(WARNING) << "Unable to create cache entry"; | 1095 DLOG(WARNING) << "Unable to create cache entry"; |
| 1074 mode_ = NONE; | 1096 mode_ = NONE; |
| 1075 if (partial_) | 1097 if (partial_) |
| 1076 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1098 partial_->RestoreHeaders(&custom_request_->extra_headers); |
| 1077 next_state_ = STATE_SEND_REQUEST; | 1099 next_state_ = STATE_SEND_REQUEST; |
| 1078 } | 1100 } |
| 1079 return OK; | 1101 return OK; |
| 1080 } | 1102 } |
| 1081 | 1103 |
| 1082 int HttpCache::Transaction::DoAddToEntry() { | 1104 int HttpCache::Transaction::DoAddToEntry() { |
| 1105 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoAddToEntry", this, | |
| 1106 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1083 DCHECK(new_entry_); | 1107 DCHECK(new_entry_); |
| 1084 cache_pending_ = true; | 1108 cache_pending_ = true; |
| 1085 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 1109 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
| 1086 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY); | 1110 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY); |
| 1087 DCHECK(entry_lock_waiting_since_.is_null()); | 1111 DCHECK(entry_lock_waiting_since_.is_null()); |
| 1088 entry_lock_waiting_since_ = TimeTicks::Now(); | 1112 entry_lock_waiting_since_ = TimeTicks::Now(); |
| 1089 int rv = cache_->AddTransactionToEntry(new_entry_, this); | 1113 int rv = cache_->AddTransactionToEntry(new_entry_, this); |
| 1090 if (rv == ERR_IO_PENDING) { | 1114 if (rv == ERR_IO_PENDING) { |
| 1091 if (bypass_lock_for_test_) { | 1115 if (bypass_lock_for_test_) { |
| 1092 OnAddToEntryTimeout(entry_lock_waiting_since_); | 1116 OnAddToEntryTimeout(entry_lock_waiting_since_); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1114 FROM_HERE, | 1138 FROM_HERE, |
| 1115 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | 1139 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, |
| 1116 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | 1140 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), |
| 1117 TimeDelta::FromMilliseconds(timeout_milliseconds)); | 1141 TimeDelta::FromMilliseconds(timeout_milliseconds)); |
| 1118 } | 1142 } |
| 1119 } | 1143 } |
| 1120 return rv; | 1144 return rv; |
| 1121 } | 1145 } |
| 1122 | 1146 |
| 1123 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1147 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
| 1148 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoAddToEntryComplete", | |
| 1149 this, | |
| 1150 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1124 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY, | 1151 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY, |
| 1125 result); | 1152 result); |
| 1126 const TimeDelta entry_lock_wait = | 1153 const TimeDelta entry_lock_wait = |
| 1127 TimeTicks::Now() - entry_lock_waiting_since_; | 1154 TimeTicks::Now() - entry_lock_waiting_since_; |
| 1128 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 1155 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
| 1129 | 1156 |
| 1130 entry_lock_waiting_since_ = TimeTicks(); | 1157 entry_lock_waiting_since_ = TimeTicks(); |
| 1131 DCHECK(new_entry_); | 1158 DCHECK(new_entry_); |
| 1132 cache_pending_ = false; | 1159 cache_pending_ = false; |
| 1133 | 1160 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 next_state_ = STATE_SEND_REQUEST; | 1193 next_state_ = STATE_SEND_REQUEST; |
| 1167 } else { | 1194 } else { |
| 1168 // We have to read the headers from the cached entry. | 1195 // We have to read the headers from the cached entry. |
| 1169 DCHECK(mode_ & READ_META); | 1196 DCHECK(mode_ & READ_META); |
| 1170 next_state_ = STATE_CACHE_READ_RESPONSE; | 1197 next_state_ = STATE_CACHE_READ_RESPONSE; |
| 1171 } | 1198 } |
| 1172 return OK; | 1199 return OK; |
| 1173 } | 1200 } |
| 1174 | 1201 |
| 1175 int HttpCache::Transaction::DoCacheReadResponse() { | 1202 int HttpCache::Transaction::DoCacheReadResponse() { |
| 1203 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCacheReadResponse", | |
| 1204 this, | |
| 1205 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1176 DCHECK(entry_); | 1206 DCHECK(entry_); |
| 1177 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; | 1207 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; |
| 1178 | 1208 |
| 1179 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); | 1209 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); |
| 1180 read_buf_ = new IOBuffer(io_buf_len_); | 1210 read_buf_ = new IOBuffer(io_buf_len_); |
| 1181 | 1211 |
| 1182 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1212 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
| 1183 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), | 1213 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), |
| 1184 io_buf_len_, io_callback_); | 1214 io_buf_len_, io_callback_); |
| 1185 } | 1215 } |
| 1186 | 1216 |
| 1187 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1217 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| 1218 TRACE_EVENT_WITH_FLOW0( | |
| 1219 "net", "HttpCache::Transaction::DoCacheReadResponseComplete", this, | |
| 1220 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1188 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, | 1221 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, |
| 1189 result); | 1222 result); |
| 1190 if (result != io_buf_len_ || | 1223 if (result != io_buf_len_ || |
| 1191 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_, | 1224 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_, |
| 1192 &truncated_)) { | 1225 &truncated_)) { |
| 1193 return OnCacheReadError(result, true); | 1226 return OnCacheReadError(result, true); |
| 1194 } | 1227 } |
| 1195 | 1228 |
| 1196 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1229 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1197 int64_t full_response_length = response_.headers->GetContentLength(); | 1230 int64_t full_response_length = response_.headers->GetContentLength(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1227 // for this transaction but the bit needs to be flipped in storage. | 1260 // for this transaction but the bit needs to be flipped in storage. |
| 1228 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH; | 1261 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH; |
| 1229 return OK; | 1262 return OK; |
| 1230 } | 1263 } |
| 1231 | 1264 |
| 1232 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; | 1265 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; |
| 1233 return OK; | 1266 return OK; |
| 1234 } | 1267 } |
| 1235 | 1268 |
| 1236 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() { | 1269 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() { |
| 1270 TRACE_EVENT_WITH_FLOW0( | |
| 1271 "net", "HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch", this, | |
| 1272 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1237 // Write back the toggled value for the next use of this entry. | 1273 // Write back the toggled value for the next use of this entry. |
| 1238 response_.unused_since_prefetch = !response_.unused_since_prefetch; | 1274 response_.unused_since_prefetch = !response_.unused_since_prefetch; |
| 1239 | 1275 |
| 1240 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this | 1276 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this |
| 1241 // transaction then metadata will be written to cache twice. If prefetching | 1277 // transaction then metadata will be written to cache twice. If prefetching |
| 1242 // becomes more common, consider combining the writes. | 1278 // becomes more common, consider combining the writes. |
| 1243 | 1279 |
| 1244 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE; | 1280 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE; |
| 1245 return WriteResponseInfoToEntry(false); | 1281 return WriteResponseInfoToEntry(false); |
| 1246 } | 1282 } |
| 1247 | 1283 |
| 1248 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete( | 1284 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete( |
| 1249 int result) { | 1285 int result) { |
| 1286 TRACE_EVENT_WITH_FLOW0( | |
| 1287 "net", "HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete", | |
| 1288 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1250 // Restore the original value for this transaction. | 1289 // Restore the original value for this transaction. |
| 1251 response_.unused_since_prefetch = !response_.unused_since_prefetch; | 1290 response_.unused_since_prefetch = !response_.unused_since_prefetch; |
| 1252 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; | 1291 next_state_ = STATE_CACHE_DISPATCH_VALIDATION; |
| 1253 return OnWriteResponseInfoToEntryComplete(result); | 1292 return OnWriteResponseInfoToEntryComplete(result); |
| 1254 } | 1293 } |
| 1255 | 1294 |
| 1256 int HttpCache::Transaction::DoCacheDispatchValidation() { | 1295 int HttpCache::Transaction::DoCacheDispatchValidation() { |
| 1296 TRACE_EVENT_WITH_FLOW0( | |
| 1297 "net", "HttpCache::Transaction::DoCacheDispatchValidation", this, | |
| 1298 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1257 // We now have access to the cache entry. | 1299 // We now have access to the cache entry. |
| 1258 // | 1300 // |
| 1259 // o if we are a reader for the transaction, then we can start reading the | 1301 // o if we are a reader for the transaction, then we can start reading the |
| 1260 // cache entry. | 1302 // cache entry. |
| 1261 // | 1303 // |
| 1262 // o if we can read or write, then we should check if the cache entry needs | 1304 // o if we can read or write, then we should check if the cache entry needs |
| 1263 // to be validated and then issue a network request if needed or just read | 1305 // to be validated and then issue a network request if needed or just read |
| 1264 // from the cache if the cache entry is already valid. | 1306 // from the cache if the cache entry is already valid. |
| 1265 // | 1307 // |
| 1266 // o if we are set to UPDATE, then we are handling an externally | 1308 // 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... | |
| 1328 | 1370 |
| 1329 if (reading_ && partial_->IsCurrentRangeCached()) { | 1371 if (reading_ && partial_->IsCurrentRangeCached()) { |
| 1330 next_state_ = STATE_CACHE_READ_DATA; | 1372 next_state_ = STATE_CACHE_READ_DATA; |
| 1331 return OK; | 1373 return OK; |
| 1332 } | 1374 } |
| 1333 | 1375 |
| 1334 return BeginCacheValidation(); | 1376 return BeginCacheValidation(); |
| 1335 } | 1377 } |
| 1336 | 1378 |
| 1337 int HttpCache::Transaction::DoSendRequest() { | 1379 int HttpCache::Transaction::DoSendRequest() { |
| 1380 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoSendRequest", this, | |
| 1381 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1338 DCHECK(mode_ & WRITE || mode_ == NONE); | 1382 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 1339 DCHECK(!network_trans_.get()); | 1383 DCHECK(!network_trans_.get()); |
| 1340 | 1384 |
| 1341 send_request_since_ = TimeTicks::Now(); | 1385 send_request_since_ = TimeTicks::Now(); |
| 1342 | 1386 |
| 1343 // Create a network transaction. | 1387 // Create a network transaction. |
| 1344 int rv = | 1388 int rv = |
| 1345 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); | 1389 cache_->network_layer_->CreateTransaction(priority_, &network_trans_); |
| 1346 if (rv != OK) | 1390 if (rv != OK) |
| 1347 return rv; | 1391 return rv; |
| 1348 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); | 1392 network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_); |
| 1349 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); | 1393 network_trans_->SetBeforeHeadersSentCallback(before_headers_sent_callback_); |
| 1350 | 1394 |
| 1351 // Old load timing information, if any, is now obsolete. | 1395 // Old load timing information, if any, is now obsolete. |
| 1352 old_network_trans_load_timing_.reset(); | 1396 old_network_trans_load_timing_.reset(); |
| 1353 old_remote_endpoint_ = IPEndPoint(); | 1397 old_remote_endpoint_ = IPEndPoint(); |
| 1354 | 1398 |
| 1355 if (websocket_handshake_stream_base_create_helper_) | 1399 if (websocket_handshake_stream_base_create_helper_) |
| 1356 network_trans_->SetWebSocketHandshakeStreamCreateHelper( | 1400 network_trans_->SetWebSocketHandshakeStreamCreateHelper( |
| 1357 websocket_handshake_stream_base_create_helper_); | 1401 websocket_handshake_stream_base_create_helper_); |
| 1358 | 1402 |
| 1359 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1403 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 1360 rv = network_trans_->Start(request_, io_callback_, net_log_); | 1404 rv = network_trans_->Start(request_, io_callback_, net_log_); |
| 1361 return rv; | 1405 return rv; |
| 1362 } | 1406 } |
| 1363 | 1407 |
| 1364 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 1408 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
| 1409 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoSendRequestComplete", | |
| 1410 this, | |
| 1411 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1365 if (!cache_.get()) | 1412 if (!cache_.get()) |
| 1366 return ERR_UNEXPECTED; | 1413 return ERR_UNEXPECTED; |
| 1367 | 1414 |
| 1368 // If we tried to conditionalize the request and failed, we know | 1415 // If we tried to conditionalize the request and failed, we know |
| 1369 // we won't be reading from the cache after this point. | 1416 // we won't be reading from the cache after this point. |
| 1370 if (couldnt_conditionalize_request_) | 1417 if (couldnt_conditionalize_request_) |
| 1371 mode_ = WRITE; | 1418 mode_ = WRITE; |
| 1372 | 1419 |
| 1373 if (result == OK) { | 1420 if (result == OK) { |
| 1374 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; | 1421 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1390 response_.cert_request_info = response->cert_request_info; | 1437 response_.cert_request_info = response->cert_request_info; |
| 1391 } else if (response_.was_cached) { | 1438 } else if (response_.was_cached) { |
| 1392 DoneWritingToEntry(true); | 1439 DoneWritingToEntry(true); |
| 1393 } | 1440 } |
| 1394 | 1441 |
| 1395 return result; | 1442 return result; |
| 1396 } | 1443 } |
| 1397 | 1444 |
| 1398 // We received the response headers and there is no error. | 1445 // We received the response headers and there is no error. |
| 1399 int HttpCache::Transaction::DoSuccessfulSendRequest() { | 1446 int HttpCache::Transaction::DoSuccessfulSendRequest() { |
| 1447 TRACE_EVENT_WITH_FLOW0( | |
| 1448 "net", "HttpCache::Transaction::DoSuccessfulSendRequest", this, | |
| 1449 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1400 DCHECK(!new_response_); | 1450 DCHECK(!new_response_); |
| 1401 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 1451 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
| 1402 | 1452 |
| 1403 if (new_response->headers->response_code() == 401 || | 1453 if (new_response->headers->response_code() == 401 || |
| 1404 new_response->headers->response_code() == 407) { | 1454 new_response->headers->response_code() == 407) { |
| 1405 SetAuthResponse(*new_response); | 1455 SetAuthResponse(*new_response); |
| 1406 if (!reading_) | 1456 if (!reading_) |
| 1407 return OK; | 1457 return OK; |
| 1408 | 1458 |
| 1409 // We initiated a second request the caller doesn't know about. We should be | 1459 // 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... | |
| 1495 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); | 1545 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); |
| 1496 mode_ = WRITE; | 1546 mode_ = WRITE; |
| 1497 } | 1547 } |
| 1498 | 1548 |
| 1499 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 1549 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
| 1500 return OK; | 1550 return OK; |
| 1501 } | 1551 } |
| 1502 | 1552 |
| 1503 // We received 304 or 206 and we want to update the cached response headers. | 1553 // We received 304 or 206 and we want to update the cached response headers. |
| 1504 int HttpCache::Transaction::DoUpdateCachedResponse() { | 1554 int HttpCache::Transaction::DoUpdateCachedResponse() { |
| 1555 TRACE_EVENT_WITH_FLOW0("net", | |
| 1556 "HttpCache::Transaction::DoUpdateCachedResponse", this, | |
| 1557 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1505 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1558 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1506 int rv = OK; | 1559 int rv = OK; |
| 1507 // Update the cached response based on the headers and properties of | 1560 // Update the cached response based on the headers and properties of |
| 1508 // new_response_. | 1561 // new_response_. |
| 1509 response_.headers->Update(*new_response_->headers.get()); | 1562 response_.headers->Update(*new_response_->headers.get()); |
| 1510 response_.response_time = new_response_->response_time; | 1563 response_.response_time = new_response_->response_time; |
| 1511 response_.request_time = new_response_->request_time; | 1564 response_.request_time = new_response_->request_time; |
| 1512 response_.network_accessed = new_response_->network_accessed; | 1565 response_.network_accessed = new_response_->network_accessed; |
| 1513 response_.unused_since_prefetch = new_response_->unused_since_prefetch; | 1566 response_.unused_since_prefetch = new_response_->unused_since_prefetch; |
| 1514 response_.ssl_info = new_response_->ssl_info; | 1567 response_.ssl_info = new_response_->ssl_info; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1532 // request; doing it again will change Content-Length. | 1585 // request; doing it again will change Content-Length. |
| 1533 if (!reading_) { | 1586 if (!reading_) { |
| 1534 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE; | 1587 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE; |
| 1535 rv = OK; | 1588 rv = OK; |
| 1536 } | 1589 } |
| 1537 } | 1590 } |
| 1538 return rv; | 1591 return rv; |
| 1539 } | 1592 } |
| 1540 | 1593 |
| 1541 int HttpCache::Transaction::DoCacheWriteUpdatedResponse() { | 1594 int HttpCache::Transaction::DoCacheWriteUpdatedResponse() { |
| 1595 TRACE_EVENT_WITH_FLOW0( | |
| 1596 "net", "HttpCache::Transaction::DoCacheWriteUpdatedResponse", this, | |
| 1597 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1598 | |
| 1542 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE; | 1599 next_state_ = STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE; |
| 1543 return WriteResponseInfoToEntry(false); | 1600 return WriteResponseInfoToEntry(false); |
| 1544 } | 1601 } |
| 1545 | 1602 |
| 1546 int HttpCache::Transaction::DoCacheWriteUpdatedResponseComplete(int result) { | 1603 int HttpCache::Transaction::DoCacheWriteUpdatedResponseComplete(int result) { |
| 1604 TRACE_EVENT_WITH_FLOW0( | |
| 1605 "net", "HttpCache::Transaction::DoCacheWriteUpdatedResponseComplete", | |
| 1606 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1547 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1607 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1548 return OnWriteResponseInfoToEntryComplete(result); | 1608 return OnWriteResponseInfoToEntryComplete(result); |
| 1549 } | 1609 } |
| 1550 | 1610 |
| 1551 int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { | 1611 int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { |
| 1612 TRACE_EVENT_WITH_FLOW0( | |
| 1613 "net", "HttpCache::Transaction::DoUpdateCachedResponseComplete", this, | |
| 1614 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1552 if (mode_ == UPDATE) { | 1615 if (mode_ == UPDATE) { |
| 1553 DCHECK(!handling_206_); | 1616 DCHECK(!handling_206_); |
| 1554 // We got a "not modified" response and already updated the corresponding | 1617 // We got a "not modified" response and already updated the corresponding |
| 1555 // cache entry above. | 1618 // cache entry above. |
| 1556 // | 1619 // |
| 1557 // By closing the cached entry now, we make sure that the 304 rather than | 1620 // By closing the cached entry now, we make sure that the 304 rather than |
| 1558 // the cached 200 response, is what will be returned to the user. | 1621 // the cached 200 response, is what will be returned to the user. |
| 1559 DoneWritingToEntry(true); | 1622 DoneWritingToEntry(true); |
| 1560 } else if (entry_ && !handling_206_) { | 1623 } else if (entry_ && !handling_206_) { |
| 1561 DCHECK_EQ(READ_WRITE, mode_); | 1624 DCHECK_EQ(READ_WRITE, mode_); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1574 new_response_ = NULL; | 1637 new_response_ = NULL; |
| 1575 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 1638 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
| 1576 partial_->SetRangeToStartDownload(); | 1639 partial_->SetRangeToStartDownload(); |
| 1577 return OK; | 1640 return OK; |
| 1578 } | 1641 } |
| 1579 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 1642 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
| 1580 return OK; | 1643 return OK; |
| 1581 } | 1644 } |
| 1582 | 1645 |
| 1583 int HttpCache::Transaction::DoOverwriteCachedResponse() { | 1646 int HttpCache::Transaction::DoOverwriteCachedResponse() { |
| 1647 TRACE_EVENT_WITH_FLOW0( | |
| 1648 "net", "HttpCache::Transaction::DoOverwriteCachedResponse", this, | |
| 1649 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1584 if (mode_ & READ) { | 1650 if (mode_ & READ) { |
| 1585 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1651 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1586 return OK; | 1652 return OK; |
| 1587 } | 1653 } |
| 1588 | 1654 |
| 1589 // We change the value of Content-Length for partial content. | 1655 // We change the value of Content-Length for partial content. |
| 1590 if (handling_206_ && partial_) | 1656 if (handling_206_ && partial_) |
| 1591 partial_->FixContentLength(new_response_->headers.get()); | 1657 partial_->FixContentLength(new_response_->headers.get()); |
| 1592 | 1658 |
| 1593 SetResponse(*new_response_); | 1659 SetResponse(*new_response_); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1608 partial_->FixResponseHeaders(response_.headers.get(), true); | 1674 partial_->FixResponseHeaders(response_.headers.get(), true); |
| 1609 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1675 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1610 return OK; | 1676 return OK; |
| 1611 } | 1677 } |
| 1612 | 1678 |
| 1613 next_state_ = STATE_CACHE_WRITE_RESPONSE; | 1679 next_state_ = STATE_CACHE_WRITE_RESPONSE; |
| 1614 return OK; | 1680 return OK; |
| 1615 } | 1681 } |
| 1616 | 1682 |
| 1617 int HttpCache::Transaction::DoCacheWriteResponse() { | 1683 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1684 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCacheWriteResponse", | |
| 1685 this, | |
| 1686 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1618 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; | 1687 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; |
| 1619 return WriteResponseInfoToEntry(truncated_); | 1688 return WriteResponseInfoToEntry(truncated_); |
| 1620 } | 1689 } |
| 1621 | 1690 |
| 1622 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1691 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
| 1692 TRACE_EVENT_WITH_FLOW0( | |
| 1693 "net", "HttpCache::Transaction::DoCacheWriteResponseComplete", this, | |
| 1694 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1623 next_state_ = STATE_TRUNCATE_CACHED_DATA; | 1695 next_state_ = STATE_TRUNCATE_CACHED_DATA; |
| 1624 return OnWriteResponseInfoToEntryComplete(result); | 1696 return OnWriteResponseInfoToEntryComplete(result); |
| 1625 } | 1697 } |
| 1626 | 1698 |
| 1627 int HttpCache::Transaction::DoTruncateCachedData() { | 1699 int HttpCache::Transaction::DoTruncateCachedData() { |
| 1700 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoTruncateCachedData", | |
| 1701 this, | |
| 1702 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1628 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 1703 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
| 1629 if (!entry_) | 1704 if (!entry_) |
| 1630 return OK; | 1705 return OK; |
| 1631 if (net_log_.IsCapturing()) | 1706 if (net_log_.IsCapturing()) |
| 1632 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); | 1707 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); |
| 1633 // Truncate the stream. | 1708 // Truncate the stream. |
| 1634 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); | 1709 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); |
| 1635 } | 1710 } |
| 1636 | 1711 |
| 1637 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 1712 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
| 1713 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoInitEntry", this, | |
| 1714 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1638 if (entry_) { | 1715 if (entry_) { |
| 1639 if (net_log_.IsCapturing()) { | 1716 if (net_log_.IsCapturing()) { |
| 1640 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, | 1717 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, |
| 1641 result); | 1718 result); |
| 1642 } | 1719 } |
| 1643 } | 1720 } |
| 1644 | 1721 |
| 1645 next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 1722 next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
| 1646 return OK; | 1723 return OK; |
| 1647 } | 1724 } |
| 1648 | 1725 |
| 1649 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 1726 int HttpCache::Transaction::DoTruncateCachedMetadata() { |
| 1727 TRACE_EVENT_WITH_FLOW0( | |
| 1728 "net", "HttpCache::Transaction::DoTruncateCachedMetadata", this, | |
| 1729 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1650 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 1730 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |
| 1651 if (!entry_) | 1731 if (!entry_) |
| 1652 return OK; | 1732 return OK; |
| 1653 | 1733 |
| 1654 if (net_log_.IsCapturing()) | 1734 if (net_log_.IsCapturing()) |
| 1655 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO); | 1735 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO); |
| 1656 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); | 1736 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); |
| 1657 } | 1737 } |
| 1658 | 1738 |
| 1659 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 1739 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
| 1740 TRACE_EVENT_WITH_FLOW0( | |
| 1741 "net", "HttpCache::Transaction::DoTruncateCachedMetadataComplete", this, | |
| 1742 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1660 if (entry_) { | 1743 if (entry_) { |
| 1661 if (net_log_.IsCapturing()) { | 1744 if (net_log_.IsCapturing()) { |
| 1662 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_INFO, | 1745 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_INFO, |
| 1663 result); | 1746 result); |
| 1664 } | 1747 } |
| 1665 } | 1748 } |
| 1666 | 1749 |
| 1667 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1750 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1668 return OK; | 1751 return OK; |
| 1669 } | 1752 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1684 } | 1767 } |
| 1685 } else if (mode_ != NONE) { | 1768 } else if (mode_ != NONE) { |
| 1686 // We are about to return the headers for a byte-range request to the user, | 1769 // We are about to return the headers for a byte-range request to the user, |
| 1687 // so let's fix them. | 1770 // so let's fix them. |
| 1688 partial_->FixResponseHeaders(response_.headers.get(), true); | 1771 partial_->FixResponseHeaders(response_.headers.get(), true); |
| 1689 } | 1772 } |
| 1690 return OK; | 1773 return OK; |
| 1691 } | 1774 } |
| 1692 | 1775 |
| 1693 int HttpCache::Transaction::DoCacheReadMetadata() { | 1776 int HttpCache::Transaction::DoCacheReadMetadata() { |
| 1777 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCacheReadMetadata", | |
| 1778 this, | |
| 1779 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1694 DCHECK(entry_); | 1780 DCHECK(entry_); |
| 1695 DCHECK(!response_.metadata.get()); | 1781 DCHECK(!response_.metadata.get()); |
| 1696 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 1782 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |
| 1697 | 1783 |
| 1698 response_.metadata = | 1784 response_.metadata = |
| 1699 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1785 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
| 1700 | 1786 |
| 1701 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1787 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
| 1702 return entry_->disk_entry->ReadData(kMetadataIndex, 0, | 1788 return entry_->disk_entry->ReadData(kMetadataIndex, 0, |
| 1703 response_.metadata.get(), | 1789 response_.metadata.get(), |
| 1704 response_.metadata->size(), | 1790 response_.metadata->size(), |
| 1705 io_callback_); | 1791 io_callback_); |
| 1706 } | 1792 } |
| 1707 | 1793 |
| 1708 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1794 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
| 1795 TRACE_EVENT_WITH_FLOW0( | |
| 1796 "net", "HttpCache::Transaction::DoCacheReadMetadataComplete", this, | |
| 1797 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1709 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, | 1798 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO, |
| 1710 result); | 1799 result); |
| 1711 if (result != response_.metadata->size()) | 1800 if (result != response_.metadata->size()) |
| 1712 return OnCacheReadError(result, false); | 1801 return OnCacheReadError(result, false); |
| 1713 return OK; | 1802 return OK; |
| 1714 } | 1803 } |
| 1715 | 1804 |
| 1716 int HttpCache::Transaction::DoNetworkRead() { | 1805 int HttpCache::Transaction::DoNetworkRead() { |
| 1806 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoNetworkRead", this, | |
| 1807 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1717 next_state_ = STATE_NETWORK_READ_COMPLETE; | 1808 next_state_ = STATE_NETWORK_READ_COMPLETE; |
| 1718 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); | 1809 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); |
| 1719 } | 1810 } |
| 1720 | 1811 |
| 1721 int HttpCache::Transaction::DoNetworkReadComplete(int result) { | 1812 int HttpCache::Transaction::DoNetworkReadComplete(int result) { |
| 1813 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoNetworkReadComplete", | |
| 1814 this, | |
| 1815 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1722 DCHECK(mode_ & WRITE || mode_ == NONE); | 1816 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 1723 | 1817 |
| 1724 if (!cache_.get()) | 1818 if (!cache_.get()) |
| 1725 return ERR_UNEXPECTED; | 1819 return ERR_UNEXPECTED; |
| 1726 | 1820 |
| 1727 // If there is an error or we aren't saving the data, we are done; just wait | 1821 // If there is an error or we aren't saving the data, we are done; just wait |
| 1728 // until the destructor runs to see if we can keep the data. | 1822 // until the destructor runs to see if we can keep the data. |
| 1729 if (mode_ == NONE || result < 0) | 1823 if (mode_ == NONE || result < 0) |
| 1730 return result; | 1824 return result; |
| 1731 | 1825 |
| 1732 next_state_ = STATE_CACHE_WRITE_DATA; | 1826 next_state_ = STATE_CACHE_WRITE_DATA; |
| 1733 return result; | 1827 return result; |
| 1734 } | 1828 } |
| 1735 | 1829 |
| 1736 int HttpCache::Transaction::DoCacheReadData() { | 1830 int HttpCache::Transaction::DoCacheReadData() { |
| 1831 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCacheReadData", this, | |
| 1832 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1737 if (request_->method == "HEAD") | 1833 if (request_->method == "HEAD") |
| 1738 return 0; | 1834 return 0; |
| 1739 | 1835 |
| 1740 DCHECK(entry_); | 1836 DCHECK(entry_); |
| 1741 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1837 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
| 1742 | 1838 |
| 1743 if (net_log_.IsCapturing()) | 1839 if (net_log_.IsCapturing()) |
| 1744 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA); | 1840 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA); |
| 1745 if (partial_) { | 1841 if (partial_) { |
| 1746 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, | 1842 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, |
| 1747 io_callback_); | 1843 io_callback_); |
| 1748 } | 1844 } |
| 1749 | 1845 |
| 1750 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1846 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
| 1751 read_buf_.get(), io_buf_len_, | 1847 read_buf_.get(), io_buf_len_, |
| 1752 io_callback_); | 1848 io_callback_); |
| 1753 } | 1849 } |
| 1754 | 1850 |
| 1755 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 1851 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
| 1852 TRACE_EVENT_WITH_FLOW0( | |
| 1853 "net", "HttpCache::Transaction::DoCacheReadDataComplete", this, | |
| 1854 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1756 if (net_log_.IsCapturing()) { | 1855 if (net_log_.IsCapturing()) { |
| 1757 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA, | 1856 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA, |
| 1758 result); | 1857 result); |
| 1759 } | 1858 } |
| 1760 | 1859 |
| 1761 if (!cache_.get()) | 1860 if (!cache_.get()) |
| 1762 return ERR_UNEXPECTED; | 1861 return ERR_UNEXPECTED; |
| 1763 | 1862 |
| 1764 if (partial_) { | 1863 if (partial_) { |
| 1765 // Partial requests are confusing to report in histograms because they may | 1864 // Partial requests are confusing to report in histograms because they may |
| 1766 // have multiple underlying requests. | 1865 // have multiple underlying requests. |
| 1767 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); | 1866 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); |
| 1768 return DoPartialCacheReadCompleted(result); | 1867 return DoPartialCacheReadCompleted(result); |
| 1769 } | 1868 } |
| 1770 | 1869 |
| 1771 if (result > 0) { | 1870 if (result > 0) { |
| 1772 read_offset_ += result; | 1871 read_offset_ += result; |
| 1773 } else if (result == 0) { // End of file. | 1872 } else if (result == 0) { // End of file. |
| 1774 RecordHistograms(); | 1873 RecordHistograms(); |
| 1775 cache_->DoneReadingFromEntry(entry_, this); | 1874 cache_->DoneReadingFromEntry(entry_, this); |
| 1776 entry_ = NULL; | 1875 entry_ = NULL; |
| 1777 } else { | 1876 } else { |
| 1778 return OnCacheReadError(result, false); | 1877 return OnCacheReadError(result, false); |
| 1779 } | 1878 } |
| 1780 return result; | 1879 return result; |
| 1781 } | 1880 } |
| 1782 | 1881 |
| 1783 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1882 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
| 1883 TRACE_EVENT_WITH_FLOW0("net", "HttpCache::Transaction::DoCacheWriteData", | |
| 1884 this, | |
| 1885 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1784 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1886 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
| 1785 write_len_ = num_bytes; | 1887 write_len_ = num_bytes; |
| 1786 if (entry_) { | 1888 if (entry_) { |
| 1787 if (net_log_.IsCapturing()) | 1889 if (net_log_.IsCapturing()) |
| 1788 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); | 1890 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA); |
| 1789 } | 1891 } |
| 1790 | 1892 |
| 1791 if (!entry_ || !num_bytes) | 1893 if (!entry_ || !num_bytes) |
| 1792 return num_bytes; | 1894 return num_bytes; |
| 1793 | 1895 |
| 1794 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1896 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1795 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), | 1897 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), |
| 1796 num_bytes, io_callback_); | 1898 num_bytes, io_callback_); |
| 1797 } | 1899 } |
| 1798 | 1900 |
| 1799 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1901 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
| 1902 TRACE_EVENT_WITH_FLOW0( | |
| 1903 "net", "HttpCache::Transaction::DoCacheWriteDataComplete", this, | |
| 1904 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1800 if (entry_) { | 1905 if (entry_) { |
| 1801 if (net_log_.IsCapturing()) { | 1906 if (net_log_.IsCapturing()) { |
| 1802 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, | 1907 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA, |
| 1803 result); | 1908 result); |
| 1804 } | 1909 } |
| 1805 } | 1910 } |
| 1806 if (!cache_.get()) | 1911 if (!cache_.get()) |
| 1807 return ERR_UNEXPECTED; | 1912 return ERR_UNEXPECTED; |
| 1808 | 1913 |
| 1809 if (result != write_len_) { | 1914 if (result != write_len_) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1834 if (done_reading_ || !entry_ || partial_ || | 1939 if (done_reading_ || !entry_ || partial_ || |
| 1835 response_.headers->GetContentLength() <= 0) { | 1940 response_.headers->GetContentLength() <= 0) { |
| 1836 DoneWritingToEntry(true); | 1941 DoneWritingToEntry(true); |
| 1837 } | 1942 } |
| 1838 } | 1943 } |
| 1839 | 1944 |
| 1840 return result; | 1945 return result; |
| 1841 } | 1946 } |
| 1842 | 1947 |
| 1843 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1948 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
| 1949 TRACE_EVENT_WITH_FLOW0( | |
| 1950 "net", "HttpCache::Transaction::DoCacheWriteTruncatedResponse", this, | |
| 1951 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1844 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE; | 1952 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE; |
| 1845 return WriteResponseInfoToEntry(true); | 1953 return WriteResponseInfoToEntry(true); |
| 1846 } | 1954 } |
| 1847 | 1955 |
| 1848 int HttpCache::Transaction::DoCacheWriteTruncatedResponseComplete(int result) { | 1956 int HttpCache::Transaction::DoCacheWriteTruncatedResponseComplete(int result) { |
| 1957 TRACE_EVENT_WITH_FLOW0( | |
| 1958 "net", "HttpCache::Transaction::DoCacheWriteTruncatedResponse", this, | |
| 1959 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | |
| 1960 | |
| 1849 return OnWriteResponseInfoToEntryComplete(result); | 1961 return OnWriteResponseInfoToEntryComplete(result); |
| 1850 } | 1962 } |
| 1851 | 1963 |
| 1852 //----------------------------------------------------------------------------- | 1964 //----------------------------------------------------------------------------- |
| 1853 | 1965 |
| 1854 void HttpCache::Transaction::SetRequest(const NetLogWithSource& net_log, | 1966 void HttpCache::Transaction::SetRequest(const NetLogWithSource& net_log, |
| 1855 const HttpRequestInfo* request) { | 1967 const HttpRequestInfo* request) { |
| 1856 net_log_ = net_log; | 1968 net_log_ = net_log; |
| 1857 request_ = request; | 1969 request_ = request; |
| 1858 effective_load_flags_ = request_->load_flags; | 1970 effective_load_flags_ = request_->load_flags; |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2939 default: | 3051 default: |
| 2940 NOTREACHED(); | 3052 NOTREACHED(); |
| 2941 } | 3053 } |
| 2942 } | 3054 } |
| 2943 | 3055 |
| 2944 void HttpCache::Transaction::OnIOComplete(int result) { | 3056 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2945 DoLoop(result); | 3057 DoLoop(result); |
| 2946 } | 3058 } |
| 2947 | 3059 |
| 2948 } // namespace net | 3060 } // namespace net |
| OLD | NEW |