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 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 STATE_OVERWRITE_CACHED_RESPONSE, | 217 STATE_OVERWRITE_CACHED_RESPONSE, |
214 STATE_CACHE_WRITE_RESPONSE, | 218 STATE_CACHE_WRITE_RESPONSE, |
215 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 219 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
216 STATE_TRUNCATE_CACHED_DATA, | 220 STATE_TRUNCATE_CACHED_DATA, |
217 STATE_TRUNCATE_CACHED_DATA_COMPLETE, | 221 STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
218 STATE_TRUNCATE_CACHED_METADATA, | 222 STATE_TRUNCATE_CACHED_METADATA, |
219 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, | 223 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, |
220 STATE_PARTIAL_HEADERS_RECEIVED, | 224 STATE_PARTIAL_HEADERS_RECEIVED, |
221 STATE_CACHE_READ_METADATA, | 225 STATE_CACHE_READ_METADATA, |
222 STATE_CACHE_READ_METADATA_COMPLETE, | 226 STATE_CACHE_READ_METADATA_COMPLETE, |
| 227 STATE_HEADERS_PHASE_CANNOT_PROCEED, |
| 228 STATE_FINISH_HEADERS, |
| 229 STATE_FINISH_HEADERS_COMPLETE, |
223 | 230 |
224 // These states are entered from Read/AddTruncatedFlag. | 231 // These states are entered from Read/AddTruncatedFlag. |
225 STATE_NETWORK_READ, | 232 STATE_NETWORK_READ, |
226 STATE_NETWORK_READ_COMPLETE, | 233 STATE_NETWORK_READ_COMPLETE, |
227 STATE_CACHE_READ_DATA, | 234 STATE_CACHE_READ_DATA, |
228 STATE_CACHE_READ_DATA_COMPLETE, | 235 STATE_CACHE_READ_DATA_COMPLETE, |
229 STATE_CACHE_WRITE_DATA, | 236 STATE_CACHE_WRITE_DATA, |
230 STATE_CACHE_WRITE_DATA_COMPLETE, | 237 STATE_CACHE_WRITE_DATA_COMPLETE, |
231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, | 238 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE | 239 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 int DoOverwriteCachedResponse(); | 288 int DoOverwriteCachedResponse(); |
282 int DoCacheWriteResponse(); | 289 int DoCacheWriteResponse(); |
283 int DoCacheWriteResponseComplete(int result); | 290 int DoCacheWriteResponseComplete(int result); |
284 int DoTruncateCachedData(); | 291 int DoTruncateCachedData(); |
285 int DoTruncateCachedDataComplete(int result); | 292 int DoTruncateCachedDataComplete(int result); |
286 int DoTruncateCachedMetadata(); | 293 int DoTruncateCachedMetadata(); |
287 int DoTruncateCachedMetadataComplete(int result); | 294 int DoTruncateCachedMetadataComplete(int result); |
288 int DoPartialHeadersReceived(); | 295 int DoPartialHeadersReceived(); |
289 int DoCacheReadMetadata(); | 296 int DoCacheReadMetadata(); |
290 int DoCacheReadMetadataComplete(int result); | 297 int DoCacheReadMetadataComplete(int result); |
| 298 int DoHeadersPhaseCannotProceed(); |
| 299 int DoFinishHeaders(int result); |
| 300 int DoFinishHeadersComplete(int result); |
291 int DoNetworkRead(); | 301 int DoNetworkRead(); |
292 int DoNetworkReadComplete(int result); | 302 int DoNetworkReadComplete(int result); |
293 int DoCacheReadData(); | 303 int DoCacheReadData(); |
294 int DoCacheReadDataComplete(int result); | 304 int DoCacheReadDataComplete(int result); |
295 int DoCacheWriteData(int num_bytes); | 305 int DoCacheWriteData(int num_bytes); |
296 int DoCacheWriteDataComplete(int result); | 306 int DoCacheWriteDataComplete(int result); |
297 int DoCacheWriteTruncatedResponse(); | 307 int DoCacheWriteTruncatedResponse(); |
298 int DoCacheWriteTruncatedResponseComplete(int result); | 308 int DoCacheWriteTruncatedResponseComplete(int result); |
299 | 309 |
300 // Sets request_ and fields derived from it. | 310 // 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); | 433 void SetResponse(const HttpResponseInfo& new_response); |
424 void SetAuthResponse(const HttpResponseInfo& new_response); | 434 void SetAuthResponse(const HttpResponseInfo& new_response); |
425 | 435 |
426 void UpdateCacheEntryStatus( | 436 void UpdateCacheEntryStatus( |
427 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); | 437 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); |
428 | 438 |
429 // Sets the response.cache_entry_status to the current cache_entry_status_. | 439 // Sets the response.cache_entry_status to the current cache_entry_status_. |
430 void SyncCacheEntryStatusToResponse(); | 440 void SyncCacheEntryStatusToResponse(); |
431 void RecordHistograms(); | 441 void RecordHistograms(); |
432 | 442 |
433 // Called to signal completion of asynchronous IO. | 443 // Called to signal completion of asynchronous IO. Note that this callback is |
| 444 // used in the conventional sense where one layer calls the callback of the |
| 445 // layer above it e.g. this callback gets called from the network transaction |
| 446 // layer. In addition, it is also used for HttpCache layer to let this |
| 447 // transaction know when it is out of a queued state in ActiveEntry and can |
| 448 // continue its processing. |
434 void OnIOComplete(int result); | 449 void OnIOComplete(int result); |
435 | 450 |
436 // When in a DoLoop, use this to set the next state as it verifies that the | 451 // When in a DoLoop, use this to set the next state as it verifies that the |
437 // state isn't set twice. | 452 // state isn't set twice. |
438 void TransitionToState(State state); | 453 void TransitionToState(State state); |
439 | 454 |
440 State next_state_; | 455 State next_state_; |
441 const HttpRequestInfo* request_; | 456 const HttpRequestInfo* request_; |
442 RequestPriority priority_; | 457 RequestPriority priority_; |
443 NetLogWithSource net_log_; | 458 NetLogWithSource net_log_; |
444 std::unique_ptr<HttpRequestInfo> custom_request_; | 459 std::unique_ptr<HttpRequestInfo> custom_request_; |
445 HttpRequestHeaders request_headers_copy_; | 460 HttpRequestHeaders request_headers_copy_; |
446 // If extra_headers specified a "if-modified-since" or "if-none-match", | 461 // If extra_headers specified a "if-modified-since" or "if-none-match", |
447 // |external_validation_| contains the value of those headers. | 462 // |external_validation_| contains the value of those headers. |
448 ValidationHeaders external_validation_; | 463 ValidationHeaders external_validation_; |
449 base::WeakPtr<HttpCache> cache_; | 464 base::WeakPtr<HttpCache> cache_; |
450 HttpCache::ActiveEntry* entry_; | 465 HttpCache::ActiveEntry* entry_; |
451 HttpCache::ActiveEntry* new_entry_; | 466 HttpCache::ActiveEntry* new_entry_; |
452 std::unique_ptr<HttpTransaction> network_trans_; | 467 std::unique_ptr<HttpTransaction> network_trans_; |
453 CompletionCallback callback_; // Consumer's callback. | 468 CompletionCallback callback_; // Consumer's callback. |
454 HttpResponseInfo response_; | 469 HttpResponseInfo response_; |
455 HttpResponseInfo auth_response_; | 470 HttpResponseInfo auth_response_; |
456 const HttpResponseInfo* new_response_; | 471 const HttpResponseInfo* new_response_; |
457 std::string cache_key_; | 472 std::string cache_key_; |
458 Mode mode_; | 473 Mode mode_; |
| 474 Mode original_mode_; // Used when restarting the transaction. |
459 bool reading_; // We are already reading. Never reverts to false once set. | 475 bool reading_; // We are already reading. Never reverts to false once set. |
460 bool invalid_range_; // We may bypass the cache for this request. | 476 bool invalid_range_; // We may bypass the cache for this request. |
461 bool truncated_; // We don't have all the response data. | 477 bool truncated_; // We don't have all the response data. |
462 bool is_sparse_; // The data is stored in sparse byte ranges. | 478 bool is_sparse_; // The data is stored in sparse byte ranges. |
463 bool range_requested_; // The user requested a byte range. | 479 bool range_requested_; // The user requested a byte range. |
464 bool handling_206_; // We must deal with this 206 response. | 480 bool handling_206_; // We must deal with this 206 response. |
465 bool cache_pending_; // We are waiting for the HttpCache. | 481 bool cache_pending_; // We are waiting for the HttpCache. |
466 bool done_reading_; // All available data was read. | 482 bool done_reading_; // All available data was read. |
467 bool vary_mismatch_; // The request doesn't match the stored vary data. | 483 bool vary_mismatch_; // The request doesn't match the stored vary data. |
468 bool couldnt_conditionalize_request_; | 484 bool couldnt_conditionalize_request_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 bool in_do_loop_; | 531 bool in_do_loop_; |
516 | 532 |
517 base::WeakPtrFactory<Transaction> weak_factory_; | 533 base::WeakPtrFactory<Transaction> weak_factory_; |
518 | 534 |
519 DISALLOW_COPY_AND_ASSIGN(Transaction); | 535 DISALLOW_COPY_AND_ASSIGN(Transaction); |
520 }; | 536 }; |
521 | 537 |
522 } // namespace net | 538 } // namespace net |
523 | 539 |
524 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 540 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |