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 // 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 bool AddTruncatedFlag(); | 108 bool AddTruncatedFlag(); |
| 109 | 109 |
| 110 HttpCache::ActiveEntry* entry() { return entry_; } | 110 HttpCache::ActiveEntry* entry() { return entry_; } |
| 111 | 111 |
| 112 // Returns the LoadState of the writer transaction of a given ActiveEntry. In | 112 // Returns the LoadState of the writer transaction of a given ActiveEntry. In |
| 113 // other words, returns the LoadState of this transaction without asking the | 113 // other words, returns the LoadState of this transaction without asking the |
| 114 // http cache, because this transaction should be the one currently writing | 114 // http cache, because this transaction should be the one currently writing |
| 115 // to the cache entry. | 115 // to the cache entry. |
| 116 LoadState GetWriterLoadState() const; | 116 LoadState GetWriterLoadState() const; |
| 117 | 117 |
| 118 const CompletionCallback& io_callback() { return io_callback_; } | 118 const CompletionCallback& io_callback() { return io_callback_; } |
|
Randy Smith (Not in Mondays)
2017/03/31 19:26:12
Would you be willing to put a documentation commen
shivanisha
2017/04/03 20:16:49
Done.
| |
| 119 | 119 |
| 120 const NetLogWithSource& net_log() const; | 120 const NetLogWithSource& net_log() const; |
| 121 | 121 |
| 122 // Bypasses the cache lock whenever there is lock contention. | 122 // Bypasses the cache lock whenever there is lock contention. |
| 123 void BypassLockForTest() { | 123 void BypassLockForTest() { |
| 124 bypass_lock_for_test_ = true; | 124 bypass_lock_for_test_ = true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Generates a failure when attempting to conditionalize a network request. | 127 // Generates a failure when attempting to conditionalize a network request. |
| 128 void FailConditionalizationForTest() { | 128 void FailConditionalizationForTest() { |
| (...skipping 28 matching lines...) Expand all 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(); | |
|
Randy Smith (Not in Mondays)
2017/03/31 19:26:12
So conceptually this seems like the same thing as
shivanisha
2017/04/03 20:16:49
Combined the 2 in the following manner:
- Created
Randy Smith (Not in Mondays)
2017/04/04 21:21:16
Awesome! Thank you.
| |
| 170 | |
| 171 // Converts mode_ to read-only and resets if there is a network transaction. | |
| 172 void ConvertToReadMode(); | |
| 173 | |
| 167 // Returns the estimate of dynamically allocated memory in bytes. | 174 // Returns the estimate of dynamically allocated memory in bytes. |
| 168 size_t EstimateMemoryUsage() const; | 175 size_t EstimateMemoryUsage() const; |
| 169 | 176 |
| 170 private: | 177 private: |
| 171 static const size_t kNumValidationHeaders = 2; | 178 static const size_t kNumValidationHeaders = 2; |
| 172 // Helper struct to pair a header name with its value, for | 179 // Helper struct to pair a header name with its value, for |
| 173 // headers used to validate cache entries. | 180 // headers used to validate cache entries. |
| 174 struct ValidationHeaders { | 181 struct ValidationHeaders { |
| 175 ValidationHeaders() : initialized(false) {} | 182 ValidationHeaders() : initialized(false) {} |
| 176 | 183 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 STATE_OVERWRITE_CACHED_RESPONSE, | 220 STATE_OVERWRITE_CACHED_RESPONSE, |
| 214 STATE_CACHE_WRITE_RESPONSE, | 221 STATE_CACHE_WRITE_RESPONSE, |
| 215 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 222 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
| 216 STATE_TRUNCATE_CACHED_DATA, | 223 STATE_TRUNCATE_CACHED_DATA, |
| 217 STATE_TRUNCATE_CACHED_DATA_COMPLETE, | 224 STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
| 218 STATE_TRUNCATE_CACHED_METADATA, | 225 STATE_TRUNCATE_CACHED_METADATA, |
| 219 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, | 226 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, |
| 220 STATE_PARTIAL_HEADERS_RECEIVED, | 227 STATE_PARTIAL_HEADERS_RECEIVED, |
| 221 STATE_CACHE_READ_METADATA, | 228 STATE_CACHE_READ_METADATA, |
| 222 STATE_CACHE_READ_METADATA_COMPLETE, | 229 STATE_CACHE_READ_METADATA_COMPLETE, |
| 230 STATE_FINISH_HEADERS, | |
| 231 STATE_FINISH_HEADERS_COMPLETE, | |
| 223 | 232 |
| 224 // These states are entered from Read/AddTruncatedFlag. | 233 // These states are entered from Read/AddTruncatedFlag. |
| 225 STATE_NETWORK_READ, | 234 STATE_NETWORK_READ, |
| 226 STATE_NETWORK_READ_COMPLETE, | 235 STATE_NETWORK_READ_COMPLETE, |
| 227 STATE_CACHE_READ_DATA, | 236 STATE_CACHE_READ_DATA, |
| 228 STATE_CACHE_READ_DATA_COMPLETE, | 237 STATE_CACHE_READ_DATA_COMPLETE, |
| 229 STATE_CACHE_WRITE_DATA, | 238 STATE_CACHE_WRITE_DATA, |
| 230 STATE_CACHE_WRITE_DATA_COMPLETE, | 239 STATE_CACHE_WRITE_DATA_COMPLETE, |
| 231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, | 240 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
| 232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE | 241 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE |
| 233 }; | 242 }; |
| 234 | 243 |
| 235 // Used for categorizing validation triggers in histograms. | 244 // Used for categorizing validation triggers in histograms. |
| 236 // NOTE: This enumeration is used in histograms, so please do not add entries | 245 // NOTE: This enumeration is used in histograms, so please do not add entries |
| 237 // in the middle. | 246 // in the middle. |
| 238 enum ValidationCause { | 247 enum ValidationCause { |
| 239 VALIDATION_CAUSE_UNDEFINED, | 248 VALIDATION_CAUSE_UNDEFINED, |
| 240 VALIDATION_CAUSE_VARY_MISMATCH, | 249 VALIDATION_CAUSE_VARY_MISMATCH, |
| 241 VALIDATION_CAUSE_VALIDATE_FLAG, | 250 VALIDATION_CAUSE_VALIDATE_FLAG, |
| 242 VALIDATION_CAUSE_STALE, | 251 VALIDATION_CAUSE_STALE, |
| 243 VALIDATION_CAUSE_ZERO_FRESHNESS, | 252 VALIDATION_CAUSE_ZERO_FRESHNESS, |
| 244 VALIDATION_CAUSE_MAX | 253 VALIDATION_CAUSE_MAX |
| 245 }; | 254 }; |
| 246 | 255 |
| 247 // Runs the state transition loop. Resets and calls |callback_| on exit, | 256 // Runs the state transition loop. Resets and calls |callback_| on exit, |
| 248 // unless the return value is ERR_IO_PENDING. | 257 // unless the return value is ERR_IO_PENDING. |
| 249 int DoLoop(int result); | 258 int DoLoop(int result); |
| 259 int DoLoopImpl(int result); | |
|
Randy Smith (Not in Mondays)
2017/03/31 19:26:12
I don't think this exists anymore?
shivanisha
2017/04/03 20:16:49
Removed
| |
| 250 | 260 |
| 251 // Each of these methods corresponds to a State value. If there is an | 261 // 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 | 262 // argument, the value corresponds to the return of the previous state or |
| 253 // corresponding callback. | 263 // corresponding callback. |
| 254 int DoGetBackend(); | 264 int DoGetBackend(); |
| 255 int DoGetBackendComplete(int result); | 265 int DoGetBackendComplete(int result); |
| 256 int DoInitEntry(); | 266 int DoInitEntry(); |
| 257 int DoOpenEntry(); | 267 int DoOpenEntry(); |
| 258 int DoOpenEntryComplete(int result); | 268 int DoOpenEntryComplete(int result); |
| 259 int DoDoomEntry(); | 269 int DoDoomEntry(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 279 int DoCacheWriteUpdatedResponseComplete(int result); | 289 int DoCacheWriteUpdatedResponseComplete(int result); |
| 280 int DoUpdateCachedResponseComplete(int result); | 290 int DoUpdateCachedResponseComplete(int result); |
| 281 int DoOverwriteCachedResponse(); | 291 int DoOverwriteCachedResponse(); |
| 282 int DoCacheWriteResponse(); | 292 int DoCacheWriteResponse(); |
| 283 int DoCacheWriteResponseComplete(int result); | 293 int DoCacheWriteResponseComplete(int result); |
| 284 int DoTruncateCachedData(); | 294 int DoTruncateCachedData(); |
| 285 int DoTruncateCachedDataComplete(int result); | 295 int DoTruncateCachedDataComplete(int result); |
| 286 int DoTruncateCachedMetadata(); | 296 int DoTruncateCachedMetadata(); |
| 287 int DoTruncateCachedMetadataComplete(int result); | 297 int DoTruncateCachedMetadataComplete(int result); |
| 288 int DoPartialHeadersReceived(); | 298 int DoPartialHeadersReceived(); |
| 299 int DoFinishHeaders(int result); | |
| 300 int DoFinishHeadersComplete(int result); | |
| 289 int DoCacheReadMetadata(); | 301 int DoCacheReadMetadata(); |
| 290 int DoCacheReadMetadataComplete(int result); | 302 int DoCacheReadMetadataComplete(int result); |
| 291 int DoNetworkRead(); | 303 int DoNetworkRead(); |
| 292 int DoNetworkReadComplete(int result); | 304 int DoNetworkReadComplete(int result); |
| 293 int DoCacheReadData(); | 305 int DoCacheReadData(); |
| 294 int DoCacheReadDataComplete(int result); | 306 int DoCacheReadDataComplete(int result); |
| 295 int DoCacheWriteData(int num_bytes); | 307 int DoCacheWriteData(int num_bytes); |
| 296 int DoCacheWriteDataComplete(int result); | 308 int DoCacheWriteDataComplete(int result); |
| 297 int DoCacheWriteTruncatedResponse(); | 309 int DoCacheWriteTruncatedResponse(); |
| 298 int DoCacheWriteTruncatedResponseComplete(int result); | 310 int DoCacheWriteTruncatedResponseComplete(int result); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 int DoRestartPartialRequest(); | 419 int DoRestartPartialRequest(); |
| 408 | 420 |
| 409 // Resets the relavant internal state to remove traces of internal processing | 421 // Resets the relavant internal state to remove traces of internal processing |
| 410 // related to range requests. Deletes |partial_| if |delete_object| is true. | 422 // related to range requests. Deletes |partial_| if |delete_object| is true. |
| 411 void ResetPartialState(bool delete_object); | 423 void ResetPartialState(bool delete_object); |
| 412 | 424 |
| 413 // Resets |network_trans_|, which must be non-NULL. Also updates | 425 // Resets |network_trans_|, which must be non-NULL. Also updates |
| 414 // |old_network_trans_load_timing_|, which must be NULL when this is called. | 426 // |old_network_trans_load_timing_|, which must be NULL when this is called. |
| 415 void ResetNetworkTransaction(); | 427 void ResetNetworkTransaction(); |
| 416 | 428 |
| 429 // Since a transaction could be doing validation of request headers in | |
| 430 // parallel with another request writing response data to the entry, failure | |
| 431 // to write the data might lead to restarting this request. This function | |
| 432 // resets all the required variables to be able to restart the transaction's | |
| 433 // state machine. | |
| 434 void RestartAfterValidationStarted(); | |
| 435 | |
| 417 // Returns true if we should bother attempting to resume this request if it is | 436 // 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 | 437 // aborted while in progress. If |has_data| is true, the size of the stored |
| 419 // data is considered for the result. | 438 // data is considered for the result. |
| 420 bool CanResume(bool has_data); | 439 bool CanResume(bool has_data); |
| 421 | 440 |
| 422 // Setter for response_ and auth_response_. It updates its cache entry status, | 441 // Setter for response_ and auth_response_. It updates its cache entry status, |
| 423 // if needed. | 442 // if needed. |
| 424 void SetResponse(const HttpResponseInfo& new_response); | 443 void SetResponse(const HttpResponseInfo& new_response); |
| 425 void SetAuthResponse(const HttpResponseInfo& new_response); | 444 void SetAuthResponse(const HttpResponseInfo& new_response); |
| 426 | 445 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 450 base::WeakPtr<HttpCache> cache_; | 469 base::WeakPtr<HttpCache> cache_; |
| 451 HttpCache::ActiveEntry* entry_; | 470 HttpCache::ActiveEntry* entry_; |
| 452 HttpCache::ActiveEntry* new_entry_; | 471 HttpCache::ActiveEntry* new_entry_; |
| 453 std::unique_ptr<HttpTransaction> network_trans_; | 472 std::unique_ptr<HttpTransaction> network_trans_; |
| 454 CompletionCallback callback_; // Consumer's callback. | 473 CompletionCallback callback_; // Consumer's callback. |
| 455 HttpResponseInfo response_; | 474 HttpResponseInfo response_; |
| 456 HttpResponseInfo auth_response_; | 475 HttpResponseInfo auth_response_; |
| 457 const HttpResponseInfo* new_response_; | 476 const HttpResponseInfo* new_response_; |
| 458 std::string cache_key_; | 477 std::string cache_key_; |
| 459 Mode mode_; | 478 Mode mode_; |
| 479 Mode original_mode_; // Used when restarting the transaction. | |
| 460 bool reading_; // We are already reading. Never reverts to false once set. | 480 bool reading_; // We are already reading. Never reverts to false once set. |
| 461 bool invalid_range_; // We may bypass the cache for this request. | 481 bool invalid_range_; // We may bypass the cache for this request. |
| 462 bool truncated_; // We don't have all the response data. | 482 bool truncated_; // We don't have all the response data. |
| 463 bool is_sparse_; // The data is stored in sparse byte ranges. | 483 bool is_sparse_; // The data is stored in sparse byte ranges. |
| 464 bool range_requested_; // The user requested a byte range. | 484 bool range_requested_; // The user requested a byte range. |
| 465 bool handling_206_; // We must deal with this 206 response. | 485 bool handling_206_; // We must deal with this 206 response. |
| 466 bool cache_pending_; // We are waiting for the HttpCache. | 486 bool cache_pending_; // We are waiting for the HttpCache. |
| 467 bool done_reading_; // All available data was read. | 487 bool done_reading_; // All available data was read. |
| 468 bool vary_mismatch_; // The request doesn't match the stored vary data. | 488 bool vary_mismatch_; // The request doesn't match the stored vary data. |
| 469 bool couldnt_conditionalize_request_; | 489 bool couldnt_conditionalize_request_; |
| 470 bool bypass_lock_for_test_; // A test is exercising the cache lock. | 490 bool bypass_lock_for_test_; // A test is exercising the cache lock. |
| 471 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. | 491 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. |
| 492 // Parallel validation cannot proceed due to response failure, restart the | |
| 493 // transaction. | |
| 494 bool validating_cannot_proceed_; | |
| 472 scoped_refptr<IOBuffer> read_buf_; | 495 scoped_refptr<IOBuffer> read_buf_; |
| 473 int io_buf_len_; | 496 int io_buf_len_; |
| 474 int read_offset_; | 497 int read_offset_; |
| 475 int effective_load_flags_; | 498 int effective_load_flags_; |
| 476 int write_len_; | 499 int write_len_; |
| 477 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. | 500 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. |
| 478 CompletionCallback io_callback_; | 501 CompletionCallback io_callback_; |
| 479 | 502 |
| 480 // Members used to track data for histograms. | 503 // Members used to track data for histograms. |
| 481 // This cache_entry_status_ takes precedence over | 504 // 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_; | 539 bool in_do_loop_; |
| 517 | 540 |
| 518 base::WeakPtrFactory<Transaction> weak_factory_; | 541 base::WeakPtrFactory<Transaction> weak_factory_; |
| 519 | 542 |
| 520 DISALLOW_COPY_AND_ASSIGN(Transaction); | 543 DISALLOW_COPY_AND_ASSIGN(Transaction); |
| 521 }; | 544 }; |
| 522 | 545 |
| 523 } // namespace net | 546 } // namespace net |
| 524 | 547 |
| 525 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 548 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
| OLD | NEW |