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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 mode_(NONE), | 158 mode_(NONE), |
| 159 original_mode_(NONE), | 159 original_mode_(NONE), |
| 160 reading_(false), | 160 reading_(false), |
| 161 invalid_range_(false), | 161 invalid_range_(false), |
| 162 truncated_(false), | 162 truncated_(false), |
| 163 is_sparse_(false), | 163 is_sparse_(false), |
| 164 range_requested_(false), | 164 range_requested_(false), |
| 165 handling_206_(false), | 165 handling_206_(false), |
| 166 cache_pending_(false), | 166 cache_pending_(false), |
| 167 done_reading_(false), | 167 done_reading_(false), |
| 168 done_headers_create_new_entry_(false), | |
| 168 vary_mismatch_(false), | 169 vary_mismatch_(false), |
| 169 couldnt_conditionalize_request_(false), | 170 couldnt_conditionalize_request_(false), |
| 170 bypass_lock_for_test_(false), | 171 bypass_lock_for_test_(false), |
| 171 fail_conditionalization_for_test_(false), | 172 fail_conditionalization_for_test_(false), |
| 172 io_buf_len_(0), | 173 io_buf_len_(0), |
| 173 read_offset_(0), | 174 read_offset_(0), |
| 174 effective_load_flags_(0), | 175 effective_load_flags_(0), |
| 175 write_len_(0), | 176 write_len_(0), |
| 176 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), | 177 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), |
| 177 validation_cause_(VALIDATION_CAUSE_UNDEFINED), | 178 validation_cause_(VALIDATION_CAUSE_UNDEFINED), |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 case STATE_CREATE_ENTRY_COMPLETE: | 748 case STATE_CREATE_ENTRY_COMPLETE: |
| 748 rv = DoCreateEntryComplete(rv); | 749 rv = DoCreateEntryComplete(rv); |
| 749 break; | 750 break; |
| 750 case STATE_ADD_TO_ENTRY: | 751 case STATE_ADD_TO_ENTRY: |
| 751 DCHECK_EQ(OK, rv); | 752 DCHECK_EQ(OK, rv); |
| 752 rv = DoAddToEntry(); | 753 rv = DoAddToEntry(); |
| 753 break; | 754 break; |
| 754 case STATE_ADD_TO_ENTRY_COMPLETE: | 755 case STATE_ADD_TO_ENTRY_COMPLETE: |
| 755 rv = DoAddToEntryComplete(rv); | 756 rv = DoAddToEntryComplete(rv); |
| 756 break; | 757 break; |
| 758 case STATE_DONE_HEADERS_ADD_TO_ENTRY_COMPLETE: | |
| 759 rv = DoDoneHeadersAddToEntryComplete(rv); | |
| 760 break; | |
| 757 case STATE_CACHE_READ_RESPONSE: | 761 case STATE_CACHE_READ_RESPONSE: |
| 758 DCHECK_EQ(OK, rv); | 762 DCHECK_EQ(OK, rv); |
| 759 rv = DoCacheReadResponse(); | 763 rv = DoCacheReadResponse(); |
| 760 break; | 764 break; |
| 761 case STATE_CACHE_READ_RESPONSE_COMPLETE: | 765 case STATE_CACHE_READ_RESPONSE_COMPLETE: |
| 762 rv = DoCacheReadResponseComplete(rv); | 766 rv = DoCacheReadResponseComplete(rv); |
| 763 break; | 767 break; |
| 764 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH: | 768 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH: |
| 765 DCHECK_EQ(OK, rv); | 769 DCHECK_EQ(OK, rv); |
| 766 rv = DoCacheToggleUnusedSincePrefetch(); | 770 rv = DoCacheToggleUnusedSincePrefetch(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 // transaction attached. | 1026 // transaction attached. |
| 1023 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, | 1027 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY, |
| 1024 result); | 1028 result); |
| 1025 cache_pending_ = false; | 1029 cache_pending_ = false; |
| 1026 if (result == OK) { | 1030 if (result == OK) { |
| 1027 TransitionToState(STATE_ADD_TO_ENTRY); | 1031 TransitionToState(STATE_ADD_TO_ENTRY); |
| 1028 return OK; | 1032 return OK; |
| 1029 } | 1033 } |
| 1030 | 1034 |
| 1031 if (result == ERR_CACHE_RACE) { | 1035 if (result == ERR_CACHE_RACE) { |
| 1032 TransitionToState(STATE_HEADERS_PHASE_CANNOT_PROCEED); | 1036 TransitionToState(STATE_INIT_ENTRY); |
| 1033 return OK; | 1037 return OK; |
| 1034 } | 1038 } |
| 1035 | 1039 |
| 1036 if (request_->method == "PUT" || request_->method == "DELETE" || | 1040 if (request_->method == "PUT" || request_->method == "DELETE" || |
| 1037 (request_->method == "HEAD" && mode_ == READ_WRITE)) { | 1041 (request_->method == "HEAD" && mode_ == READ_WRITE)) { |
| 1038 DCHECK(mode_ == READ_WRITE || mode_ == WRITE || request_->method == "HEAD"); | 1042 DCHECK(mode_ == READ_WRITE || mode_ == WRITE || request_->method == "HEAD"); |
| 1039 mode_ = NONE; | 1043 mode_ = NONE; |
| 1040 TransitionToState(STATE_SEND_REQUEST); | 1044 TransitionToState(STATE_SEND_REQUEST); |
| 1041 return OK; | 1045 return OK; |
| 1042 } | 1046 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1067 first_cache_access_since_ = TimeTicks::Now(); | 1071 first_cache_access_since_ = TimeTicks::Now(); |
| 1068 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); | 1072 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY); |
| 1069 return cache_->DoomEntry(cache_key_, this); | 1073 return cache_->DoomEntry(cache_key_, this); |
| 1070 } | 1074 } |
| 1071 | 1075 |
| 1072 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 1076 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
| 1073 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntryComplete"); | 1077 TRACE_EVENT0("io", "HttpCacheTransaction::DoDoomEntryComplete"); |
| 1074 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, | 1078 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY, |
| 1075 result); | 1079 result); |
| 1076 cache_pending_ = false; | 1080 cache_pending_ = false; |
| 1077 TransitionToState(result == ERR_CACHE_RACE | 1081 |
| 1078 ? STATE_HEADERS_PHASE_CANNOT_PROCEED | 1082 TransitionToState(result == ERR_CACHE_RACE ? STATE_INIT_ENTRY |
| 1079 : STATE_CREATE_ENTRY); | 1083 : STATE_CREATE_ENTRY); |
| 1080 return OK; | 1084 return OK; |
| 1081 } | 1085 } |
| 1082 | 1086 |
| 1083 int HttpCache::Transaction::DoCreateEntry() { | 1087 int HttpCache::Transaction::DoCreateEntry() { |
| 1084 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntry"); | 1088 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntry"); |
| 1085 DCHECK(!new_entry_); | 1089 DCHECK(!new_entry_); |
| 1086 TransitionToState(STATE_CREATE_ENTRY_COMPLETE); | 1090 TransitionToState(STATE_CREATE_ENTRY_COMPLETE); |
| 1087 cache_pending_ = true; | 1091 cache_pending_ = true; |
| 1088 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); | 1092 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY); |
| 1089 return cache_->CreateEntry(cache_key_, &new_entry_, this); | 1093 return cache_->CreateEntry(cache_key_, &new_entry_, this); |
| 1090 } | 1094 } |
| 1091 | 1095 |
| 1092 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 1096 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
| 1093 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete"); | 1097 TRACE_EVENT0("io", "HttpCacheTransaction::DoCreateEntryComplete"); |
| 1094 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 1098 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 1095 // OK, otherwise the cache will end up with an active entry without any | 1099 // OK, otherwise the cache will end up with an active entry without any |
| 1096 // transaction attached. | 1100 // transaction attached. |
| 1097 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, | 1101 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY, |
| 1098 result); | 1102 result); |
| 1099 cache_pending_ = false; | 1103 cache_pending_ = false; |
| 1100 switch (result) { | 1104 switch (result) { |
| 1101 case OK: | 1105 case OK: |
| 1102 TransitionToState(STATE_ADD_TO_ENTRY); | 1106 TransitionToState(STATE_ADD_TO_ENTRY); |
| 1103 break; | 1107 break; |
| 1104 | 1108 |
| 1105 case ERR_CACHE_RACE: | 1109 case ERR_CACHE_RACE: |
| 1106 TransitionToState(STATE_HEADERS_PHASE_CANNOT_PROCEED); | 1110 TransitionToState(STATE_INIT_ENTRY); |
| 1107 break; | 1111 break; |
| 1108 | 1112 |
| 1109 default: | 1113 default: |
| 1110 // We have a race here: Maybe we failed to open the entry and decided to | 1114 // We have a race here: Maybe we failed to open the entry and decided to |
| 1111 // create one, but by the time we called create, another transaction | 1115 // create one, but by the time we called create, another transaction |
| 1112 // already created the entry. If we want to eliminate this issue, we | 1116 // already created the entry. If we want to eliminate this issue, we |
| 1113 // need an atomic OpenOrCreate() method exposed by the disk cache. | 1117 // need an atomic OpenOrCreate() method exposed by the disk cache. |
| 1114 DLOG(WARNING) << "Unable to create cache entry"; | 1118 DLOG(WARNING) << "Unable to create cache entry"; |
| 1119 // Switching into passing through data directly from the network, avoiding | |
| 1120 // the cache entry. | |
| 1115 mode_ = NONE; | 1121 mode_ = NONE; |
| 1116 if (partial_) | 1122 |
| 1117 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1123 if (!done_headers_create_new_entry_) { |
| 1118 TransitionToState(STATE_SEND_REQUEST); | 1124 if (partial_) |
| 1125 partial_->RestoreHeaders(&custom_request_->extra_headers); | |
| 1126 TransitionToState(STATE_SEND_REQUEST); | |
| 1127 return OK; | |
| 1128 } | |
| 1129 | |
| 1130 // The headers have already been received as a result of validation, | |
| 1131 // triggering the doom of the old entry. So no network request needs to | |
| 1132 // be sent. Note that since mode_ is set to pass-through, response will | |
| 1133 // not be written to the cache but moving to state | |
| 1134 // STATE_CACHE_WRITE_RESPONSE for consistency. | |
| 1135 done_headers_create_new_entry_ = false; | |
| 1136 TransitionToState(STATE_CACHE_WRITE_RESPONSE); | |
| 1119 } | 1137 } |
| 1120 return OK; | 1138 return OK; |
| 1121 } | 1139 } |
| 1122 | 1140 |
| 1123 int HttpCache::Transaction::DoAddToEntry() { | 1141 int HttpCache::Transaction::DoAddToEntry() { |
| 1124 TRACE_EVENT0("io", "HttpCacheTransaction::DoAddToEntry"); | 1142 TRACE_EVENT0("io", "HttpCacheTransaction::DoAddToEntry"); |
| 1125 DCHECK(new_entry_); | 1143 DCHECK(new_entry_); |
| 1126 cache_pending_ = true; | 1144 cache_pending_ = true; |
| 1127 TransitionToState(STATE_ADD_TO_ENTRY_COMPLETE); | |
| 1128 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY); | 1145 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY); |
| 1129 DCHECK(entry_lock_waiting_since_.is_null()); | 1146 DCHECK(entry_lock_waiting_since_.is_null()); |
| 1147 int rv = cache_->AddTransactionToEntry(new_entry_, this); | |
| 1148 DCHECK_EQ(rv, ERR_IO_PENDING); | |
| 1149 | |
| 1150 if (done_headers_create_new_entry_) { | |
| 1151 TransitionToState(STATE_DONE_HEADERS_ADD_TO_ENTRY_COMPLETE); | |
|
Randy Smith (Not in Mondays)
2017/04/27 17:47:12
It's my belief that short-circuiting all the logic
shivanisha
2017/05/31 15:51:47
Added a comment.
| |
| 1152 return rv; | |
| 1153 } | |
| 1154 | |
| 1155 TransitionToState(STATE_ADD_TO_ENTRY_COMPLETE); | |
| 1156 | |
| 1130 entry_lock_waiting_since_ = TimeTicks::Now(); | 1157 entry_lock_waiting_since_ = TimeTicks::Now(); |
| 1131 int rv = cache_->AddTransactionToEntry(new_entry_, this); | 1158 |
| 1132 if (rv == ERR_IO_PENDING) { | 1159 if (bypass_lock_for_test_) { |
| 1133 if (bypass_lock_for_test_) { | 1160 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1134 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1161 FROM_HERE, |
| 1135 FROM_HERE, | 1162 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, |
| 1136 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | 1163 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_)); |
| 1137 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_)); | 1164 } else { |
| 1138 } else { | 1165 int timeout_milliseconds = 20 * 1000; |
| 1139 int timeout_milliseconds = 20 * 1000; | 1166 if (partial_ && new_entry_->writer && |
| 1140 if (partial_ && new_entry_->writer && | 1167 new_entry_->writer->range_requested_) { |
| 1141 new_entry_->writer->range_requested_) { | 1168 // Quickly timeout and bypass the cache if we're a range request and |
| 1142 // Quickly timeout and bypass the cache if we're a range request and | 1169 // we're blocked by the reader/writer lock. Doing so eliminates a long |
| 1143 // we're blocked by the reader/writer lock. Doing so eliminates a long | 1170 // running issue, http://crbug.com/31014, where two of the same media |
| 1144 // running issue, http://crbug.com/31014, where two of the same media | 1171 // resources could not be played back simultaneously due to one locking |
| 1145 // resources could not be played back simultaneously due to one locking | 1172 // the cache entry until the entire video was downloaded. |
| 1146 // the cache entry until the entire video was downloaded. | 1173 // |
| 1147 // | 1174 // Bypassing the cache is not ideal, as we are now ignoring the cache |
| 1148 // Bypassing the cache is not ideal, as we are now ignoring the cache | 1175 // entirely for all range requests to a resource beyond the first. This |
| 1149 // entirely for all range requests to a resource beyond the first. This | 1176 // is however a much more succinct solution than the alternatives, which |
| 1150 // is however a much more succinct solution than the alternatives, which | 1177 // would require somewhat significant changes to the http caching logic. |
| 1151 // would require somewhat significant changes to the http caching logic. | 1178 // |
| 1152 // | 1179 // Allow some timeout slack for the entry addition to complete in case |
| 1153 // Allow some timeout slack for the entry addition to complete in case | 1180 // the writer lock is imminently released; we want to avoid skipping |
| 1154 // the writer lock is imminently released; we want to avoid skipping | 1181 // the cache if at all possible. See http://crbug.com/408765 |
| 1155 // the cache if at all possible. See http://crbug.com/408765 | 1182 timeout_milliseconds = 25; |
| 1156 timeout_milliseconds = 25; | |
| 1157 } | |
| 1158 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1159 FROM_HERE, | |
| 1160 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | |
| 1161 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | |
| 1162 TimeDelta::FromMilliseconds(timeout_milliseconds)); | |
| 1163 } | 1183 } |
| 1184 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1185 FROM_HERE, | |
| 1186 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | |
| 1187 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | |
| 1188 TimeDelta::FromMilliseconds(timeout_milliseconds)); | |
| 1164 } | 1189 } |
| 1165 return rv; | 1190 return rv; |
| 1166 } | 1191 } |
| 1167 | 1192 |
| 1168 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1193 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
| 1169 TRACE_EVENT0("io", "HttpCacheTransaction::DoAddToEntryComplete"); | 1194 TRACE_EVENT0("io", "HttpCacheTransaction::DoAddToEntryComplete"); |
| 1170 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY, | 1195 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY, |
| 1171 result); | 1196 result); |
| 1172 const TimeDelta entry_lock_wait = | 1197 const TimeDelta entry_lock_wait = |
| 1173 TimeTicks::Now() - entry_lock_waiting_since_; | 1198 TimeTicks::Now() - entry_lock_waiting_since_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1221 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1246 partial_->RestoreHeaders(&custom_request_->extra_headers); |
| 1222 TransitionToState(STATE_SEND_REQUEST); | 1247 TransitionToState(STATE_SEND_REQUEST); |
| 1223 } else { | 1248 } else { |
| 1224 // We have to read the headers from the cached entry. | 1249 // We have to read the headers from the cached entry. |
| 1225 DCHECK(mode_ & READ_META); | 1250 DCHECK(mode_ & READ_META); |
| 1226 TransitionToState(STATE_CACHE_READ_RESPONSE); | 1251 TransitionToState(STATE_CACHE_READ_RESPONSE); |
| 1227 } | 1252 } |
| 1228 return OK; | 1253 return OK; |
| 1229 } | 1254 } |
| 1230 | 1255 |
| 1256 int HttpCache::Transaction::DoDoneHeadersAddToEntryComplete(int result) { | |
| 1257 // This state is reached when |this| has already completed validation leading | |
| 1258 // to a no-match with original entry which was doomed and |new_entry_| was | |
| 1259 // created. |this| transaction should thus go ahead and write the response to | |
| 1260 // the newly created entry. | |
|
Randy Smith (Not in Mondays)
2017/04/27 17:47:12
Preface second sentence with something like "A res
shivanisha
2017/05/31 15:51:47
Done
| |
| 1261 DCHECK_EQ(result, OK); | |
| 1262 DCHECK(mode_ & WRITE); | |
| 1263 DCHECK(new_entry_); | |
| 1264 DCHECK(response_.headers); | |
| 1265 | |
| 1266 cache_pending_ = false; | |
| 1267 entry_ = new_entry_; | |
| 1268 done_headers_create_new_entry_ = false; | |
| 1269 bool is_match = response_.headers->response_code() == 304; | |
| 1270 DCHECK(cache_->CanTransactionWriteResponseHeaders(entry_, this, is_match)); | |
| 1271 TransitionToState(STATE_CACHE_WRITE_RESPONSE); | |
| 1272 return OK; | |
| 1273 } | |
| 1274 | |
| 1231 int HttpCache::Transaction::DoCacheReadResponse() { | 1275 int HttpCache::Transaction::DoCacheReadResponse() { |
| 1232 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadResponse"); | 1276 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadResponse"); |
| 1233 DCHECK(entry_); | 1277 DCHECK(entry_); |
| 1234 TransitionToState(STATE_CACHE_READ_RESPONSE_COMPLETE); | 1278 TransitionToState(STATE_CACHE_READ_RESPONSE_COMPLETE); |
| 1235 | 1279 |
| 1236 io_buf_len_ = entry_->GetDataSize(kResponseInfoIndex, this); | 1280 io_buf_len_ = entry_->GetDataSize(kResponseInfoIndex, this); |
| 1237 read_buf_ = new IOBuffer(io_buf_len_); | 1281 read_buf_ = new IOBuffer(io_buf_len_); |
| 1238 | 1282 |
| 1239 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); | 1283 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); |
| 1240 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), | 1284 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 TransitionToState(STATE_CACHE_WRITE_RESPONSE_COMPLETE); | 1756 TransitionToState(STATE_CACHE_WRITE_RESPONSE_COMPLETE); |
| 1713 | 1757 |
| 1714 // Invalidate any current entry with a successful response if this transaction | 1758 // Invalidate any current entry with a successful response if this transaction |
| 1715 // cannot write to this entry. This transaction then continues to read from | 1759 // cannot write to this entry. This transaction then continues to read from |
| 1716 // the network without writing to the backend. | 1760 // the network without writing to the backend. |
| 1717 bool is_match = response_.headers->response_code() == 304; | 1761 bool is_match = response_.headers->response_code() == 304; |
| 1718 if (entry_ && response_.headers && | 1762 if (entry_ && response_.headers && |
| 1719 !cache_->CanTransactionWriteResponseHeaders(entry_, this, is_match)) { | 1763 !cache_->CanTransactionWriteResponseHeaders(entry_, this, is_match)) { |
| 1720 cache_->DoneWritingToEntry(entry_, false, this); | 1764 cache_->DoneWritingToEntry(entry_, false, this); |
| 1721 entry_ = nullptr; | 1765 entry_ = nullptr; |
| 1722 mode_ = NONE; | 1766 done_headers_create_new_entry_ = true; |
| 1767 | |
| 1768 // This transaction should not add itself to any other existing entry but | |
| 1769 // create a new entry. Going to state STATE_INIT_ENTRY will take care of | |
| 1770 // dooming if any other entry exists. | |
| 1771 mode_ = WRITE; | |
| 1772 next_state_ = STATE_INIT_ENTRY; | |
|
Randy Smith (Not in Mondays)
2017/04/27 17:47:12
nit: TransitionToState? (& move the TransitionToS
shivanisha
2017/05/31 15:51:47
done
| |
| 1723 return OK; | 1773 return OK; |
| 1724 } | 1774 } |
| 1725 | 1775 |
| 1726 return WriteResponseInfoToEntry(truncated_); | 1776 return WriteResponseInfoToEntry(truncated_); |
| 1727 } | 1777 } |
| 1728 | 1778 |
| 1729 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1779 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
| 1730 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteResponseComplete"); | 1780 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheWriteResponseComplete"); |
| 1731 TransitionToState(STATE_TRUNCATE_CACHED_DATA); | 1781 TransitionToState(STATE_TRUNCATE_CACHED_DATA); |
| 1732 return OnWriteResponseInfoToEntryComplete(result); | 1782 return OnWriteResponseInfoToEntryComplete(result); |
| (...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3114 } | 3164 } |
| 3115 | 3165 |
| 3116 void HttpCache::Transaction::TransitionToState(State state) { | 3166 void HttpCache::Transaction::TransitionToState(State state) { |
| 3117 // Ensure that the state is only set once per Do* state. | 3167 // Ensure that the state is only set once per Do* state. |
| 3118 DCHECK(in_do_loop_); | 3168 DCHECK(in_do_loop_); |
| 3119 DCHECK_EQ(STATE_UNSET, next_state_) << "Next state is " << state; | 3169 DCHECK_EQ(STATE_UNSET, next_state_) << "Next state is " << state; |
| 3120 next_state_ = state; | 3170 next_state_ = state; |
| 3121 } | 3171 } |
| 3122 | 3172 |
| 3123 } // namespace net | 3173 } // namespace net |
| OLD | NEW |