Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: net/http/http_cache_transaction.h

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: HttpCache::IsCancelResponseBody added. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_WAIT_BEFORE_READ,
228 STATE_WAIT_BEFORE_READ_COMPLETE,
223 229
224 // These states are entered from Read/AddTruncatedFlag. 230 // These states are entered from Read/AddTruncatedFlag.
225 STATE_NETWORK_READ, 231 STATE_NETWORK_READ,
226 STATE_NETWORK_READ_COMPLETE, 232 STATE_NETWORK_READ_COMPLETE,
227 STATE_CACHE_READ_DATA, 233 STATE_CACHE_READ_DATA,
228 STATE_CACHE_READ_DATA_COMPLETE, 234 STATE_CACHE_READ_DATA_COMPLETE,
229 STATE_CACHE_WRITE_DATA, 235 STATE_CACHE_WRITE_DATA,
230 STATE_CACHE_WRITE_DATA_COMPLETE, 236 STATE_CACHE_WRITE_DATA_COMPLETE,
231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, 237 STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE 238 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE
233 }; 239 };
234 240
235 // Used for categorizing validation triggers in histograms. 241 // Used for categorizing validation triggers in histograms.
236 // NOTE: This enumeration is used in histograms, so please do not add entries 242 // NOTE: This enumeration is used in histograms, so please do not add entries
237 // in the middle. 243 // in the middle.
238 enum ValidationCause { 244 enum ValidationCause {
239 VALIDATION_CAUSE_UNDEFINED, 245 VALIDATION_CAUSE_UNDEFINED,
240 VALIDATION_CAUSE_VARY_MISMATCH, 246 VALIDATION_CAUSE_VARY_MISMATCH,
241 VALIDATION_CAUSE_VALIDATE_FLAG, 247 VALIDATION_CAUSE_VALIDATE_FLAG,
242 VALIDATION_CAUSE_STALE, 248 VALIDATION_CAUSE_STALE,
243 VALIDATION_CAUSE_ZERO_FRESHNESS, 249 VALIDATION_CAUSE_ZERO_FRESHNESS,
244 VALIDATION_CAUSE_MAX 250 VALIDATION_CAUSE_MAX
245 }; 251 };
246 252
247 // Runs the state transition loop. Resets and calls |callback_| on exit, 253 // Runs the state transition loop. Resets and calls |callback_| on exit,
248 // unless the return value is ERR_IO_PENDING. 254 // unless the return value is ERR_IO_PENDING.
249 int DoLoop(int result); 255 int DoLoop(int result);
256 int DoLoopImpl(int result);
250 257
251 // Each of these methods corresponds to a State value. If there is an 258 // 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 259 // argument, the value corresponds to the return of the previous state or
253 // corresponding callback. 260 // corresponding callback.
254 int DoGetBackend(); 261 int DoGetBackend();
255 int DoGetBackendComplete(int result); 262 int DoGetBackendComplete(int result);
256 int DoInitEntry(); 263 int DoInitEntry();
257 int DoOpenEntry(); 264 int DoOpenEntry();
258 int DoOpenEntryComplete(int result); 265 int DoOpenEntryComplete(int result);
259 int DoDoomEntry(); 266 int DoDoomEntry();
(...skipping 19 matching lines...) Expand all
279 int DoCacheWriteUpdatedResponseComplete(int result); 286 int DoCacheWriteUpdatedResponseComplete(int result);
280 int DoUpdateCachedResponseComplete(int result); 287 int DoUpdateCachedResponseComplete(int result);
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();
296 int DoWaitBeforeRead();
297 int DoWaitBeforeReadComplete(int result);
289 int DoCacheReadMetadata(); 298 int DoCacheReadMetadata();
290 int DoCacheReadMetadataComplete(int result); 299 int DoCacheReadMetadataComplete(int result);
291 int DoNetworkRead(); 300 int DoNetworkRead();
292 int DoNetworkReadComplete(int result); 301 int DoNetworkReadComplete(int result);
293 int DoCacheReadData(); 302 int DoCacheReadData();
294 int DoCacheReadDataComplete(int result); 303 int DoCacheReadDataComplete(int result);
295 int DoCacheWriteData(int num_bytes); 304 int DoCacheWriteData(int num_bytes);
296 int DoCacheWriteDataComplete(int result); 305 int DoCacheWriteDataComplete(int result);
297 int DoCacheWriteTruncatedResponse(); 306 int DoCacheWriteTruncatedResponse();
298 int DoCacheWriteTruncatedResponseComplete(int result); 307 int DoCacheWriteTruncatedResponseComplete(int result);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 int DoRestartPartialRequest(); 416 int DoRestartPartialRequest();
408 417
409 // Resets the relavant internal state to remove traces of internal processing 418 // Resets the relavant internal state to remove traces of internal processing
410 // related to range requests. Deletes |partial_| if |delete_object| is true. 419 // related to range requests. Deletes |partial_| if |delete_object| is true.
411 void ResetPartialState(bool delete_object); 420 void ResetPartialState(bool delete_object);
412 421
413 // Resets |network_trans_|, which must be non-NULL. Also updates 422 // Resets |network_trans_|, which must be non-NULL. Also updates
414 // |old_network_trans_load_timing_|, which must be NULL when this is called. 423 // |old_network_trans_load_timing_|, which must be NULL when this is called.
415 void ResetNetworkTransaction(); 424 void ResetNetworkTransaction();
416 425
426 // Since a transaction could be doing validation of request headers in
427 // parallel with another request writing response data to the entry, failure
428 // to write the data might lead to restarting this request. This function
429 // resets all the required variables to be able to restart the transaction's
430 // state machine.
431 void RestartAfterValidationStarted();
432
417 // Returns true if we should bother attempting to resume this request if it is 433 // 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 434 // aborted while in progress. If |has_data| is true, the size of the stored
419 // data is considered for the result. 435 // data is considered for the result.
420 bool CanResume(bool has_data); 436 bool CanResume(bool has_data);
421 437
422 // Setter for response_ and auth_response_. It updates its cache entry status, 438 // Setter for response_ and auth_response_. It updates its cache entry status,
423 // if needed. 439 // if needed.
424 void SetResponse(const HttpResponseInfo& new_response); 440 void SetResponse(const HttpResponseInfo& new_response);
425 void SetAuthResponse(const HttpResponseInfo& new_response); 441 void SetAuthResponse(const HttpResponseInfo& new_response);
426 442
(...skipping 23 matching lines...) Expand all
450 base::WeakPtr<HttpCache> cache_; 466 base::WeakPtr<HttpCache> cache_;
451 HttpCache::ActiveEntry* entry_; 467 HttpCache::ActiveEntry* entry_;
452 HttpCache::ActiveEntry* new_entry_; 468 HttpCache::ActiveEntry* new_entry_;
453 std::unique_ptr<HttpTransaction> network_trans_; 469 std::unique_ptr<HttpTransaction> network_trans_;
454 CompletionCallback callback_; // Consumer's callback. 470 CompletionCallback callback_; // Consumer's callback.
455 HttpResponseInfo response_; 471 HttpResponseInfo response_;
456 HttpResponseInfo auth_response_; 472 HttpResponseInfo auth_response_;
457 const HttpResponseInfo* new_response_; 473 const HttpResponseInfo* new_response_;
458 std::string cache_key_; 474 std::string cache_key_;
459 Mode mode_; 475 Mode mode_;
476 Mode original_mode_; // Used when restarting the transaction.
460 bool reading_; // We are already reading. Never reverts to false once set. 477 bool reading_; // We are already reading. Never reverts to false once set.
461 bool invalid_range_; // We may bypass the cache for this request. 478 bool invalid_range_; // We may bypass the cache for this request.
462 bool truncated_; // We don't have all the response data. 479 bool truncated_; // We don't have all the response data.
463 bool is_sparse_; // The data is stored in sparse byte ranges. 480 bool is_sparse_; // The data is stored in sparse byte ranges.
464 bool range_requested_; // The user requested a byte range. 481 bool range_requested_; // The user requested a byte range.
465 bool handling_206_; // We must deal with this 206 response. 482 bool handling_206_; // We must deal with this 206 response.
466 bool cache_pending_; // We are waiting for the HttpCache. 483 bool cache_pending_; // We are waiting for the HttpCache.
467 bool done_reading_; // All available data was read. 484 bool done_reading_; // All available data was read.
468 bool vary_mismatch_; // The request doesn't match the stored vary data. 485 bool vary_mismatch_; // The request doesn't match the stored vary data.
469 bool couldnt_conditionalize_request_; 486 bool couldnt_conditionalize_request_;
470 bool bypass_lock_for_test_; // A test is exercising the cache lock. 487 bool bypass_lock_for_test_; // A test is exercising the cache lock.
471 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. 488 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
489 // Parallel validation cannot proceed due to response failure, restart the
490 // transaction.
491 bool validating_cannot_proceed_;
472 scoped_refptr<IOBuffer> read_buf_; 492 scoped_refptr<IOBuffer> read_buf_;
473 int io_buf_len_; 493 int io_buf_len_;
474 int read_offset_; 494 int read_offset_;
475 int effective_load_flags_; 495 int effective_load_flags_;
476 int write_len_; 496 int write_len_;
477 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. 497 std::unique_ptr<PartialData> partial_; // We are dealing with range requests.
478 CompletionCallback io_callback_; 498 CompletionCallback io_callback_;
479 499
480 // Members used to track data for histograms. 500 // Members used to track data for histograms.
481 // This cache_entry_status_ takes precedence over 501 // This cache_entry_status_ takes precedence over
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 bool in_do_loop_; 536 bool in_do_loop_;
517 537
518 base::WeakPtrFactory<Transaction> weak_factory_; 538 base::WeakPtrFactory<Transaction> weak_factory_;
519 539
520 DISALLOW_COPY_AND_ASSIGN(Transaction); 540 DISALLOW_COPY_AND_ASSIGN(Transaction);
521 }; 541 };
522 542
523 } // namespace net 543 } // namespace net
524 544
525 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 545 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698