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 // This file declares HttpCache::Transaction, a private class of HttpCache so | 5 // This file declares HttpCache::Transaction, a private class of HttpCache so |
6 // it should only be included by http_cache.cc | 6 // it should only be included by http_cache.cc |
7 | 7 |
8 #ifndef NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 8 #ifndef NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
9 #define NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 9 #define NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
10 | 10 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 void SetPriority(RequestPriority priority) override; | 157 void SetPriority(RequestPriority priority) override; |
158 void SetWebSocketHandshakeStreamCreateHelper( | 158 void SetWebSocketHandshakeStreamCreateHelper( |
159 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; | 159 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; |
160 void SetBeforeNetworkStartCallback( | 160 void SetBeforeNetworkStartCallback( |
161 const BeforeNetworkStartCallback& callback) override; | 161 const BeforeNetworkStartCallback& callback) override; |
162 void SetBeforeHeadersSentCallback( | 162 void SetBeforeHeadersSentCallback( |
163 const BeforeHeadersSentCallback& callback) override; | 163 const BeforeHeadersSentCallback& callback) override; |
164 int ResumeNetworkStart() override; | 164 int ResumeNetworkStart() override; |
165 void GetConnectionAttempts(ConnectionAttempts* out) const override; | 165 void GetConnectionAttempts(ConnectionAttempts* out) const override; |
166 | 166 |
| 167 // Invoked when parallel validation cannot proceed due to response failure |
| 168 // and this transaction needs to be restarted. |
| 169 void SetValidatingCannotProceed(); |
| 170 |
167 // Returns the estimate of dynamically allocated memory in bytes. | 171 // Returns the estimate of dynamically allocated memory in bytes. |
168 size_t EstimateMemoryUsage() const; | 172 size_t EstimateMemoryUsage() const; |
169 | 173 |
170 private: | 174 private: |
171 static const size_t kNumValidationHeaders = 2; | 175 static const size_t kNumValidationHeaders = 2; |
172 // Helper struct to pair a header name with its value, for | 176 // Helper struct to pair a header name with its value, for |
173 // headers used to validate cache entries. | 177 // headers used to validate cache entries. |
174 struct ValidationHeaders { | 178 struct ValidationHeaders { |
175 ValidationHeaders() : initialized(false) {} | 179 ValidationHeaders() : initialized(false) {} |
176 | 180 |
177 std::string values[kNumValidationHeaders]; | 181 std::string values[kNumValidationHeaders]; |
178 bool initialized; | 182 bool initialized; |
179 }; | 183 }; |
180 | 184 |
| 185 // Used when restarting the transaction. |
| 186 struct RestartInfo { |
| 187 Mode mode = NONE; |
| 188 HttpResponseInfo::CacheEntryStatus cache_entry_status = |
| 189 HttpResponseInfo::CacheEntryStatus::ENTRY_UNDEFINED; |
| 190 }; |
| 191 |
181 enum State { | 192 enum State { |
182 STATE_UNSET, | 193 STATE_UNSET, |
183 | 194 |
184 // Normally, states are traversed in approximately this order. | 195 // Normally, states are traversed in approximately this order. |
185 STATE_NONE, | 196 STATE_NONE, |
186 STATE_GET_BACKEND, | 197 STATE_GET_BACKEND, |
187 STATE_GET_BACKEND_COMPLETE, | 198 STATE_GET_BACKEND_COMPLETE, |
188 STATE_INIT_ENTRY, | 199 STATE_INIT_ENTRY, |
189 STATE_OPEN_ENTRY, | 200 STATE_OPEN_ENTRY, |
190 STATE_OPEN_ENTRY_COMPLETE, | 201 STATE_OPEN_ENTRY_COMPLETE, |
(...skipping 22 matching lines...) Expand all Loading... |
213 STATE_OVERWRITE_CACHED_RESPONSE, | 224 STATE_OVERWRITE_CACHED_RESPONSE, |
214 STATE_CACHE_WRITE_RESPONSE, | 225 STATE_CACHE_WRITE_RESPONSE, |
215 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 226 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
216 STATE_TRUNCATE_CACHED_DATA, | 227 STATE_TRUNCATE_CACHED_DATA, |
217 STATE_TRUNCATE_CACHED_DATA_COMPLETE, | 228 STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
218 STATE_TRUNCATE_CACHED_METADATA, | 229 STATE_TRUNCATE_CACHED_METADATA, |
219 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, | 230 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, |
220 STATE_PARTIAL_HEADERS_RECEIVED, | 231 STATE_PARTIAL_HEADERS_RECEIVED, |
221 STATE_CACHE_READ_METADATA, | 232 STATE_CACHE_READ_METADATA, |
222 STATE_CACHE_READ_METADATA_COMPLETE, | 233 STATE_CACHE_READ_METADATA_COMPLETE, |
| 234 STATE_HEADERS_PHASE_CANNOT_PROCEED, |
| 235 STATE_FINISH_HEADERS, |
| 236 STATE_FINISH_HEADERS_COMPLETE, |
223 | 237 |
224 // These states are entered from Read/AddTruncatedFlag. | 238 // These states are entered from Read/AddTruncatedFlag. |
225 STATE_NETWORK_READ, | 239 STATE_NETWORK_READ, |
226 STATE_NETWORK_READ_COMPLETE, | 240 STATE_NETWORK_READ_COMPLETE, |
227 STATE_CACHE_READ_DATA, | 241 STATE_CACHE_READ_DATA, |
228 STATE_CACHE_READ_DATA_COMPLETE, | 242 STATE_CACHE_READ_DATA_COMPLETE, |
229 STATE_CACHE_WRITE_DATA, | 243 STATE_CACHE_WRITE_DATA, |
230 STATE_CACHE_WRITE_DATA_COMPLETE, | 244 STATE_CACHE_WRITE_DATA_COMPLETE, |
231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, | 245 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE | 246 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 int DoOverwriteCachedResponse(); | 295 int DoOverwriteCachedResponse(); |
282 int DoCacheWriteResponse(); | 296 int DoCacheWriteResponse(); |
283 int DoCacheWriteResponseComplete(int result); | 297 int DoCacheWriteResponseComplete(int result); |
284 int DoTruncateCachedData(); | 298 int DoTruncateCachedData(); |
285 int DoTruncateCachedDataComplete(int result); | 299 int DoTruncateCachedDataComplete(int result); |
286 int DoTruncateCachedMetadata(); | 300 int DoTruncateCachedMetadata(); |
287 int DoTruncateCachedMetadataComplete(int result); | 301 int DoTruncateCachedMetadataComplete(int result); |
288 int DoPartialHeadersReceived(); | 302 int DoPartialHeadersReceived(); |
289 int DoCacheReadMetadata(); | 303 int DoCacheReadMetadata(); |
290 int DoCacheReadMetadataComplete(int result); | 304 int DoCacheReadMetadataComplete(int result); |
| 305 int DoHeadersPhaseCannotProceed(); |
| 306 int DoFinishHeaders(int result); |
| 307 int DoFinishHeadersComplete(int result); |
291 int DoNetworkRead(); | 308 int DoNetworkRead(); |
292 int DoNetworkReadComplete(int result); | 309 int DoNetworkReadComplete(int result); |
293 int DoCacheReadData(); | 310 int DoCacheReadData(); |
294 int DoCacheReadDataComplete(int result); | 311 int DoCacheReadDataComplete(int result); |
295 int DoCacheWriteData(int num_bytes); | 312 int DoCacheWriteData(int num_bytes); |
296 int DoCacheWriteDataComplete(int result); | 313 int DoCacheWriteDataComplete(int result); |
297 int DoCacheWriteTruncatedResponse(); | 314 int DoCacheWriteTruncatedResponse(); |
298 int DoCacheWriteTruncatedResponseComplete(int result); | 315 int DoCacheWriteTruncatedResponseComplete(int result); |
299 | 316 |
300 // Sets request_ and fields derived from it. | 317 // Sets request_ and fields derived from it. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 void SetResponse(const HttpResponseInfo& new_response); | 440 void SetResponse(const HttpResponseInfo& new_response); |
424 void SetAuthResponse(const HttpResponseInfo& new_response); | 441 void SetAuthResponse(const HttpResponseInfo& new_response); |
425 | 442 |
426 void UpdateCacheEntryStatus( | 443 void UpdateCacheEntryStatus( |
427 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); | 444 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); |
428 | 445 |
429 // Sets the response.cache_entry_status to the current cache_entry_status_. | 446 // Sets the response.cache_entry_status to the current cache_entry_status_. |
430 void SyncCacheEntryStatusToResponse(); | 447 void SyncCacheEntryStatusToResponse(); |
431 void RecordHistograms(); | 448 void RecordHistograms(); |
432 | 449 |
433 // Called to signal completion of asynchronous IO. | 450 // Called to signal completion of asynchronous IO. Note that this callback is |
| 451 // used in the conventional sense where one layer calls the callback of the |
| 452 // layer above it e.g. this callback gets called from the network transaction |
| 453 // layer. In addition, it is also used for HttpCache layer to let this |
| 454 // transaction know when it is out of a queued state in ActiveEntry and can |
| 455 // continue its processing. |
434 void OnIOComplete(int result); | 456 void OnIOComplete(int result); |
435 | 457 |
436 // When in a DoLoop, use this to set the next state as it verifies that the | 458 // When in a DoLoop, use this to set the next state as it verifies that the |
437 // state isn't set twice. | 459 // state isn't set twice. |
438 void TransitionToState(State state); | 460 void TransitionToState(State state); |
439 | 461 |
440 State next_state_; | 462 State next_state_; |
441 const HttpRequestInfo* request_; | 463 const HttpRequestInfo* request_; |
| 464 std::string method_; |
442 RequestPriority priority_; | 465 RequestPriority priority_; |
443 NetLogWithSource net_log_; | 466 NetLogWithSource net_log_; |
444 std::unique_ptr<HttpRequestInfo> custom_request_; | 467 std::unique_ptr<HttpRequestInfo> custom_request_; |
445 HttpRequestHeaders request_headers_copy_; | 468 HttpRequestHeaders request_headers_copy_; |
446 // If extra_headers specified a "if-modified-since" or "if-none-match", | 469 // If extra_headers specified a "if-modified-since" or "if-none-match", |
447 // |external_validation_| contains the value of those headers. | 470 // |external_validation_| contains the value of those headers. |
448 ValidationHeaders external_validation_; | 471 ValidationHeaders external_validation_; |
449 base::WeakPtr<HttpCache> cache_; | 472 base::WeakPtr<HttpCache> cache_; |
450 HttpCache::ActiveEntry* entry_; | 473 HttpCache::ActiveEntry* entry_; |
451 HttpCache::ActiveEntry* new_entry_; | 474 HttpCache::ActiveEntry* new_entry_; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // case the transaction does not exist yet. | 530 // case the transaction does not exist yet. |
508 WebSocketHandshakeStreamBase::CreateHelper* | 531 WebSocketHandshakeStreamBase::CreateHelper* |
509 websocket_handshake_stream_base_create_helper_; | 532 websocket_handshake_stream_base_create_helper_; |
510 | 533 |
511 BeforeNetworkStartCallback before_network_start_callback_; | 534 BeforeNetworkStartCallback before_network_start_callback_; |
512 BeforeHeadersSentCallback before_headers_sent_callback_; | 535 BeforeHeadersSentCallback before_headers_sent_callback_; |
513 | 536 |
514 // True if the Transaction is currently processing the DoLoop. | 537 // True if the Transaction is currently processing the DoLoop. |
515 bool in_do_loop_; | 538 bool in_do_loop_; |
516 | 539 |
| 540 RestartInfo restart_info_; |
| 541 |
517 base::WeakPtrFactory<Transaction> weak_factory_; | 542 base::WeakPtrFactory<Transaction> weak_factory_; |
518 | 543 |
519 DISALLOW_COPY_AND_ASSIGN(Transaction); | 544 DISALLOW_COPY_AND_ASSIGN(Transaction); |
520 }; | 545 }; |
521 | 546 |
522 } // namespace net | 547 } // namespace net |
523 | 548 |
524 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 549 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |