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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 void PopulateNetErrorDetails(NetErrorDetails* details) const override; | 156 void PopulateNetErrorDetails(NetErrorDetails* details) const override; |
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 void SetValidatingCannotProceed(); |
166 | 167 |
167 // Returns the estimate of dynamically allocated memory in bytes. | 168 // Returns the estimate of dynamically allocated memory in bytes. |
168 size_t EstimateMemoryUsage() const; | 169 size_t EstimateMemoryUsage() const; |
169 | 170 |
170 private: | 171 private: |
171 static const size_t kNumValidationHeaders = 2; | 172 static const size_t kNumValidationHeaders = 2; |
172 // Helper struct to pair a header name with its value, for | 173 // Helper struct to pair a header name with its value, for |
173 // headers used to validate cache entries. | 174 // headers used to validate cache entries. |
174 struct ValidationHeaders { | 175 struct ValidationHeaders { |
175 ValidationHeaders() : initialized(false) {} | 176 ValidationHeaders() : initialized(false) {} |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 STATE_OVERWRITE_CACHED_RESPONSE, | 214 STATE_OVERWRITE_CACHED_RESPONSE, |
214 STATE_CACHE_WRITE_RESPONSE, | 215 STATE_CACHE_WRITE_RESPONSE, |
215 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 216 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
216 STATE_TRUNCATE_CACHED_DATA, | 217 STATE_TRUNCATE_CACHED_DATA, |
217 STATE_TRUNCATE_CACHED_DATA_COMPLETE, | 218 STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
218 STATE_TRUNCATE_CACHED_METADATA, | 219 STATE_TRUNCATE_CACHED_METADATA, |
219 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, | 220 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, |
220 STATE_PARTIAL_HEADERS_RECEIVED, | 221 STATE_PARTIAL_HEADERS_RECEIVED, |
221 STATE_CACHE_READ_METADATA, | 222 STATE_CACHE_READ_METADATA, |
222 STATE_CACHE_READ_METADATA_COMPLETE, | 223 STATE_CACHE_READ_METADATA_COMPLETE, |
| 224 STATE_WAIT_BEFORE_READ, |
| 225 STATE_WAIT_BEFORE_READ_COMPLETE, |
223 | 226 |
224 // These states are entered from Read/AddTruncatedFlag. | 227 // These states are entered from Read/AddTruncatedFlag. |
225 STATE_NETWORK_READ, | 228 STATE_NETWORK_READ, |
226 STATE_NETWORK_READ_COMPLETE, | 229 STATE_NETWORK_READ_COMPLETE, |
227 STATE_CACHE_READ_DATA, | 230 STATE_CACHE_READ_DATA, |
228 STATE_CACHE_READ_DATA_COMPLETE, | 231 STATE_CACHE_READ_DATA_COMPLETE, |
229 STATE_CACHE_WRITE_DATA, | 232 STATE_CACHE_WRITE_DATA, |
230 STATE_CACHE_WRITE_DATA_COMPLETE, | 233 STATE_CACHE_WRITE_DATA_COMPLETE, |
231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, | 234 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE | 235 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE |
233 }; | 236 }; |
234 | 237 |
235 // Used for categorizing validation triggers in histograms. | 238 // Used for categorizing validation triggers in histograms. |
236 // NOTE: This enumeration is used in histograms, so please do not add entries | 239 // NOTE: This enumeration is used in histograms, so please do not add entries |
237 // in the middle. | 240 // in the middle. |
238 enum ValidationCause { | 241 enum ValidationCause { |
239 VALIDATION_CAUSE_UNDEFINED, | 242 VALIDATION_CAUSE_UNDEFINED, |
240 VALIDATION_CAUSE_VARY_MISMATCH, | 243 VALIDATION_CAUSE_VARY_MISMATCH, |
241 VALIDATION_CAUSE_VALIDATE_FLAG, | 244 VALIDATION_CAUSE_VALIDATE_FLAG, |
242 VALIDATION_CAUSE_STALE, | 245 VALIDATION_CAUSE_STALE, |
243 VALIDATION_CAUSE_ZERO_FRESHNESS, | 246 VALIDATION_CAUSE_ZERO_FRESHNESS, |
244 VALIDATION_CAUSE_MAX | 247 VALIDATION_CAUSE_MAX |
245 }; | 248 }; |
246 | 249 |
247 // Runs the state transition loop. Resets and calls |callback_| on exit, | 250 // Runs the state transition loop. Resets and calls |callback_| on exit, |
248 // unless the return value is ERR_IO_PENDING. | 251 // unless the return value is ERR_IO_PENDING. |
249 int DoLoop(int result); | 252 int DoLoop(int result); |
| 253 int DoLoopImpl(int result); |
250 | 254 |
251 // Each of these methods corresponds to a State value. If there is an | 255 // Each of these methods corresponds to a State value. If there is an |
252 // argument, the value corresponds to the return of the previous state or | 256 // argument, the value corresponds to the return of the previous state or |
253 // corresponding callback. | 257 // corresponding callback. |
254 int DoGetBackend(); | 258 int DoGetBackend(); |
255 int DoGetBackendComplete(int result); | 259 int DoGetBackendComplete(int result); |
256 int DoInitEntry(); | 260 int DoInitEntry(); |
257 int DoOpenEntry(); | 261 int DoOpenEntry(); |
258 int DoOpenEntryComplete(int result); | 262 int DoOpenEntryComplete(int result); |
259 int DoDoomEntry(); | 263 int DoDoomEntry(); |
(...skipping 19 matching lines...) Expand all Loading... |
279 int DoCacheWriteUpdatedResponseComplete(int result); | 283 int DoCacheWriteUpdatedResponseComplete(int result); |
280 int DoUpdateCachedResponseComplete(int result); | 284 int DoUpdateCachedResponseComplete(int result); |
281 int DoOverwriteCachedResponse(); | 285 int DoOverwriteCachedResponse(); |
282 int DoCacheWriteResponse(); | 286 int DoCacheWriteResponse(); |
283 int DoCacheWriteResponseComplete(int result); | 287 int DoCacheWriteResponseComplete(int result); |
284 int DoTruncateCachedData(); | 288 int DoTruncateCachedData(); |
285 int DoTruncateCachedDataComplete(int result); | 289 int DoTruncateCachedDataComplete(int result); |
286 int DoTruncateCachedMetadata(); | 290 int DoTruncateCachedMetadata(); |
287 int DoTruncateCachedMetadataComplete(int result); | 291 int DoTruncateCachedMetadataComplete(int result); |
288 int DoPartialHeadersReceived(); | 292 int DoPartialHeadersReceived(); |
| 293 int DoWaitBeforeRead(); |
| 294 int DoWaitBeforeReadComplete(int result); |
289 int DoCacheReadMetadata(); | 295 int DoCacheReadMetadata(); |
290 int DoCacheReadMetadataComplete(int result); | 296 int DoCacheReadMetadataComplete(int result); |
291 int DoNetworkRead(); | 297 int DoNetworkRead(); |
292 int DoNetworkReadComplete(int result); | 298 int DoNetworkReadComplete(int result); |
293 int DoCacheReadData(); | 299 int DoCacheReadData(); |
294 int DoCacheReadDataComplete(int result); | 300 int DoCacheReadDataComplete(int result); |
295 int DoCacheWriteData(int num_bytes); | 301 int DoCacheWriteData(int num_bytes); |
296 int DoCacheWriteDataComplete(int result); | 302 int DoCacheWriteDataComplete(int result); |
297 int DoCacheWriteTruncatedResponse(); | 303 int DoCacheWriteTruncatedResponse(); |
298 int DoCacheWriteTruncatedResponseComplete(int result); | 304 int DoCacheWriteTruncatedResponseComplete(int result); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 int DoRestartPartialRequest(); | 413 int DoRestartPartialRequest(); |
408 | 414 |
409 // Resets the relavant internal state to remove traces of internal processing | 415 // Resets the relavant internal state to remove traces of internal processing |
410 // related to range requests. Deletes |partial_| if |delete_object| is true. | 416 // related to range requests. Deletes |partial_| if |delete_object| is true. |
411 void ResetPartialState(bool delete_object); | 417 void ResetPartialState(bool delete_object); |
412 | 418 |
413 // Resets |network_trans_|, which must be non-NULL. Also updates | 419 // Resets |network_trans_|, which must be non-NULL. Also updates |
414 // |old_network_trans_load_timing_|, which must be NULL when this is called. | 420 // |old_network_trans_load_timing_|, which must be NULL when this is called. |
415 void ResetNetworkTransaction(); | 421 void ResetNetworkTransaction(); |
416 | 422 |
| 423 // Since a transaction could be doing validation of request headers in |
| 424 // parallel with another request writing response data to the entry, failure |
| 425 // to write the data might lead to restarting this request. This function |
| 426 // resets all the required variables to be able to restart the transaction's |
| 427 // state machine. |
| 428 void RestartAfterValidationStarted(); |
| 429 |
417 // Returns true if we should bother attempting to resume this request if it is | 430 // Returns true if we should bother attempting to resume this request if it is |
418 // aborted while in progress. If |has_data| is true, the size of the stored | 431 // aborted while in progress. If |has_data| is true, the size of the stored |
419 // data is considered for the result. | 432 // data is considered for the result. |
420 bool CanResume(bool has_data); | 433 bool CanResume(bool has_data); |
421 | 434 |
422 // Setter for response_ and auth_response_. It updates its cache entry status, | 435 // Setter for response_ and auth_response_. It updates its cache entry status, |
423 // if needed. | 436 // if needed. |
424 void SetResponse(const HttpResponseInfo& new_response); | 437 void SetResponse(const HttpResponseInfo& new_response); |
425 void SetAuthResponse(const HttpResponseInfo& new_response); | 438 void SetAuthResponse(const HttpResponseInfo& new_response); |
426 | 439 |
(...skipping 16 matching lines...) Expand all Loading... |
443 RequestPriority priority_; | 456 RequestPriority priority_; |
444 NetLogWithSource net_log_; | 457 NetLogWithSource net_log_; |
445 std::unique_ptr<HttpRequestInfo> custom_request_; | 458 std::unique_ptr<HttpRequestInfo> custom_request_; |
446 HttpRequestHeaders request_headers_copy_; | 459 HttpRequestHeaders request_headers_copy_; |
447 // If extra_headers specified a "if-modified-since" or "if-none-match", | 460 // If extra_headers specified a "if-modified-since" or "if-none-match", |
448 // |external_validation_| contains the value of those headers. | 461 // |external_validation_| contains the value of those headers. |
449 ValidationHeaders external_validation_; | 462 ValidationHeaders external_validation_; |
450 base::WeakPtr<HttpCache> cache_; | 463 base::WeakPtr<HttpCache> cache_; |
451 HttpCache::ActiveEntry* entry_; | 464 HttpCache::ActiveEntry* entry_; |
452 HttpCache::ActiveEntry* new_entry_; | 465 HttpCache::ActiveEntry* new_entry_; |
| 466 bool created_entry_; |
453 std::unique_ptr<HttpTransaction> network_trans_; | 467 std::unique_ptr<HttpTransaction> network_trans_; |
454 CompletionCallback callback_; // Consumer's callback. | 468 CompletionCallback callback_; // Consumer's callback. |
455 HttpResponseInfo response_; | 469 HttpResponseInfo response_; |
456 HttpResponseInfo auth_response_; | 470 HttpResponseInfo auth_response_; |
457 const HttpResponseInfo* new_response_; | 471 const HttpResponseInfo* new_response_; |
458 std::string cache_key_; | 472 std::string cache_key_; |
459 Mode mode_; | 473 Mode mode_; |
| 474 Mode original_mode_; // Used when restarting the transaction. |
460 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. |
461 bool invalid_range_; // We may bypass the cache for this request. | 476 bool invalid_range_; // We may bypass the cache for this request. |
462 bool truncated_; // We don't have all the response data. | 477 bool truncated_; // We don't have all the response data. |
463 bool is_sparse_; // The data is stored in sparse byte ranges. | 478 bool is_sparse_; // The data is stored in sparse byte ranges. |
464 bool range_requested_; // The user requested a byte range. | 479 bool range_requested_; // The user requested a byte range. |
465 bool handling_206_; // We must deal with this 206 response. | 480 bool handling_206_; // We must deal with this 206 response. |
466 bool cache_pending_; // We are waiting for the HttpCache. | 481 bool cache_pending_; // We are waiting for the HttpCache. |
467 bool done_reading_; // All available data was read. | 482 bool done_reading_; // All available data was read. |
468 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. |
469 bool couldnt_conditionalize_request_; | 484 bool couldnt_conditionalize_request_; |
470 bool bypass_lock_for_test_; // A test is exercising the cache lock. | 485 bool bypass_lock_for_test_; // A test is exercising the cache lock. |
471 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. | 486 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. |
| 487 bool validating_cannot_proceed_; |
472 scoped_refptr<IOBuffer> read_buf_; | 488 scoped_refptr<IOBuffer> read_buf_; |
473 int io_buf_len_; | 489 int io_buf_len_; |
474 int read_offset_; | 490 int read_offset_; |
475 int effective_load_flags_; | 491 int effective_load_flags_; |
476 int write_len_; | 492 int write_len_; |
477 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. | 493 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. |
478 CompletionCallback io_callback_; | 494 CompletionCallback io_callback_; |
479 | 495 |
480 // Members used to track data for histograms. | 496 // Members used to track data for histograms. |
481 // This cache_entry_status_ takes precedence over | 497 // This cache_entry_status_ takes precedence over |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 bool in_do_loop_; | 532 bool in_do_loop_; |
517 | 533 |
518 base::WeakPtrFactory<Transaction> weak_factory_; | 534 base::WeakPtrFactory<Transaction> weak_factory_; |
519 | 535 |
520 DISALLOW_COPY_AND_ASSIGN(Transaction); | 536 DISALLOW_COPY_AND_ASSIGN(Transaction); |
521 }; | 537 }; |
522 | 538 |
523 } // namespace net | 539 } // namespace net |
524 | 540 |
525 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 541 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |