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

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

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Simplified ActiveEntry's state transitions Created 3 years, 9 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 STATE_OVERWRITE_CACHED_RESPONSE, 212 STATE_OVERWRITE_CACHED_RESPONSE,
212 STATE_CACHE_WRITE_RESPONSE, 213 STATE_CACHE_WRITE_RESPONSE,
213 STATE_CACHE_WRITE_RESPONSE_COMPLETE, 214 STATE_CACHE_WRITE_RESPONSE_COMPLETE,
214 STATE_TRUNCATE_CACHED_DATA, 215 STATE_TRUNCATE_CACHED_DATA,
215 STATE_TRUNCATE_CACHED_DATA_COMPLETE, 216 STATE_TRUNCATE_CACHED_DATA_COMPLETE,
216 STATE_TRUNCATE_CACHED_METADATA, 217 STATE_TRUNCATE_CACHED_METADATA,
217 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, 218 STATE_TRUNCATE_CACHED_METADATA_COMPLETE,
218 STATE_PARTIAL_HEADERS_RECEIVED, 219 STATE_PARTIAL_HEADERS_RECEIVED,
219 STATE_CACHE_READ_METADATA, 220 STATE_CACHE_READ_METADATA,
220 STATE_CACHE_READ_METADATA_COMPLETE, 221 STATE_CACHE_READ_METADATA_COMPLETE,
222 STATE_WAIT_BEFORE_READ,
223 STATE_WAIT_BEFORE_READ_COMPLETE,
221 224
222 // These states are entered from Read/AddTruncatedFlag. 225 // These states are entered from Read/AddTruncatedFlag.
223 STATE_NETWORK_READ, 226 STATE_NETWORK_READ,
224 STATE_NETWORK_READ_COMPLETE, 227 STATE_NETWORK_READ_COMPLETE,
225 STATE_CACHE_READ_DATA, 228 STATE_CACHE_READ_DATA,
226 STATE_CACHE_READ_DATA_COMPLETE, 229 STATE_CACHE_READ_DATA_COMPLETE,
227 STATE_CACHE_WRITE_DATA, 230 STATE_CACHE_WRITE_DATA,
228 STATE_CACHE_WRITE_DATA_COMPLETE, 231 STATE_CACHE_WRITE_DATA_COMPLETE,
229 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, 232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
230 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE 233 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE
231 }; 234 };
232 235
233 // Used for categorizing validation triggers in histograms. 236 // Used for categorizing validation triggers in histograms.
234 // NOTE: This enumeration is used in histograms, so please do not add entries 237 // NOTE: This enumeration is used in histograms, so please do not add entries
235 // in the middle. 238 // in the middle.
236 enum ValidationCause { 239 enum ValidationCause {
237 VALIDATION_CAUSE_UNDEFINED, 240 VALIDATION_CAUSE_UNDEFINED,
238 VALIDATION_CAUSE_VARY_MISMATCH, 241 VALIDATION_CAUSE_VARY_MISMATCH,
239 VALIDATION_CAUSE_VALIDATE_FLAG, 242 VALIDATION_CAUSE_VALIDATE_FLAG,
240 VALIDATION_CAUSE_STALE, 243 VALIDATION_CAUSE_STALE,
241 VALIDATION_CAUSE_ZERO_FRESHNESS, 244 VALIDATION_CAUSE_ZERO_FRESHNESS,
242 VALIDATION_CAUSE_MAX 245 VALIDATION_CAUSE_MAX
243 }; 246 };
244 247
245 // Runs the state transition loop. Resets and calls |callback_| on exit, 248 // Runs the state transition loop. Resets and calls |callback_| on exit,
246 // unless the return value is ERR_IO_PENDING. 249 // unless the return value is ERR_IO_PENDING.
247 int DoLoop(int result); 250 int DoLoop(int result);
251 int DoLoopImpl(int result);
248 252
249 // Each of these methods corresponds to a State value. If there is an 253 // Each of these methods corresponds to a State value. If there is an
250 // argument, the value corresponds to the return of the previous state or 254 // argument, the value corresponds to the return of the previous state or
251 // corresponding callback. 255 // corresponding callback.
252 int DoGetBackend(); 256 int DoGetBackend();
253 int DoGetBackendComplete(int result); 257 int DoGetBackendComplete(int result);
254 int DoInitEntry(); 258 int DoInitEntry();
255 int DoOpenEntry(); 259 int DoOpenEntry();
256 int DoOpenEntryComplete(int result); 260 int DoOpenEntryComplete(int result);
257 int DoDoomEntry(); 261 int DoDoomEntry();
(...skipping 19 matching lines...) Expand all
277 int DoCacheWriteUpdatedResponseComplete(int result); 281 int DoCacheWriteUpdatedResponseComplete(int result);
278 int DoUpdateCachedResponseComplete(int result); 282 int DoUpdateCachedResponseComplete(int result);
279 int DoOverwriteCachedResponse(); 283 int DoOverwriteCachedResponse();
280 int DoCacheWriteResponse(); 284 int DoCacheWriteResponse();
281 int DoCacheWriteResponseComplete(int result); 285 int DoCacheWriteResponseComplete(int result);
282 int DoTruncateCachedData(); 286 int DoTruncateCachedData();
283 int DoTruncateCachedDataComplete(int result); 287 int DoTruncateCachedDataComplete(int result);
284 int DoTruncateCachedMetadata(); 288 int DoTruncateCachedMetadata();
285 int DoTruncateCachedMetadataComplete(int result); 289 int DoTruncateCachedMetadataComplete(int result);
286 int DoPartialHeadersReceived(); 290 int DoPartialHeadersReceived();
291 int DoWaitBeforeRead();
292 int DoWaitBeforeReadComplete(int result);
287 int DoCacheReadMetadata(); 293 int DoCacheReadMetadata();
288 int DoCacheReadMetadataComplete(int result); 294 int DoCacheReadMetadataComplete(int result);
289 int DoNetworkRead(); 295 int DoNetworkRead();
290 int DoNetworkReadComplete(int result); 296 int DoNetworkReadComplete(int result);
291 int DoCacheReadData(); 297 int DoCacheReadData();
292 int DoCacheReadDataComplete(int result); 298 int DoCacheReadDataComplete(int result);
293 int DoCacheWriteData(int num_bytes); 299 int DoCacheWriteData(int num_bytes);
294 int DoCacheWriteDataComplete(int result); 300 int DoCacheWriteDataComplete(int result);
295 int DoCacheWriteTruncatedResponse(); 301 int DoCacheWriteTruncatedResponse();
296 int DoCacheWriteTruncatedResponseComplete(int result); 302 int DoCacheWriteTruncatedResponseComplete(int result);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 int DoRestartPartialRequest(); 411 int DoRestartPartialRequest();
406 412
407 // Resets the relavant internal state to remove traces of internal processing 413 // Resets the relavant internal state to remove traces of internal processing
408 // related to range requests. Deletes |partial_| if |delete_object| is true. 414 // related to range requests. Deletes |partial_| if |delete_object| is true.
409 void ResetPartialState(bool delete_object); 415 void ResetPartialState(bool delete_object);
410 416
411 // Resets |network_trans_|, which must be non-NULL. Also updates 417 // Resets |network_trans_|, which must be non-NULL. Also updates
412 // |old_network_trans_load_timing_|, which must be NULL when this is called. 418 // |old_network_trans_load_timing_|, which must be NULL when this is called.
413 void ResetNetworkTransaction(); 419 void ResetNetworkTransaction();
414 420
421 // Since a transaction could be doing validation of request headers in
422 // parallel with another request writing response data to the entry, failure
423 // to write the data might lead to restarting this request. This function
424 // resets all the required variables to be able to restart the transaction's
425 // state machine.
426 void RestartAfterValidationStarted();
427
415 // Returns true if we should bother attempting to resume this request if it is 428 // Returns true if we should bother attempting to resume this request if it is
416 // aborted while in progress. If |has_data| is true, the size of the stored 429 // aborted while in progress. If |has_data| is true, the size of the stored
417 // data is considered for the result. 430 // data is considered for the result.
418 bool CanResume(bool has_data); 431 bool CanResume(bool has_data);
419 432
420 // Setter for response_ and auth_response_. It updates its cache entry status, 433 // Setter for response_ and auth_response_. It updates its cache entry status,
421 // if needed. 434 // if needed.
422 void SetResponse(const HttpResponseInfo& new_response); 435 void SetResponse(const HttpResponseInfo& new_response);
423 void SetAuthResponse(const HttpResponseInfo& new_response); 436 void SetAuthResponse(const HttpResponseInfo& new_response);
424 437
(...skipping 19 matching lines...) Expand all
444 base::WeakPtr<HttpCache> cache_; 457 base::WeakPtr<HttpCache> cache_;
445 HttpCache::ActiveEntry* entry_; 458 HttpCache::ActiveEntry* entry_;
446 HttpCache::ActiveEntry* new_entry_; 459 HttpCache::ActiveEntry* new_entry_;
447 std::unique_ptr<HttpTransaction> network_trans_; 460 std::unique_ptr<HttpTransaction> network_trans_;
448 CompletionCallback callback_; // Consumer's callback. 461 CompletionCallback callback_; // Consumer's callback.
449 HttpResponseInfo response_; 462 HttpResponseInfo response_;
450 HttpResponseInfo auth_response_; 463 HttpResponseInfo auth_response_;
451 const HttpResponseInfo* new_response_; 464 const HttpResponseInfo* new_response_;
452 std::string cache_key_; 465 std::string cache_key_;
453 Mode mode_; 466 Mode mode_;
467 Mode original_mode_; // Used when restarting the transaction.
454 bool reading_; // We are already reading. Never reverts to false once set. 468 bool reading_; // We are already reading. Never reverts to false once set.
455 bool invalid_range_; // We may bypass the cache for this request. 469 bool invalid_range_; // We may bypass the cache for this request.
456 bool truncated_; // We don't have all the response data. 470 bool truncated_; // We don't have all the response data.
457 bool is_sparse_; // The data is stored in sparse byte ranges. 471 bool is_sparse_; // The data is stored in sparse byte ranges.
458 bool range_requested_; // The user requested a byte range. 472 bool range_requested_; // The user requested a byte range.
459 bool handling_206_; // We must deal with this 206 response. 473 bool handling_206_; // We must deal with this 206 response.
460 bool cache_pending_; // We are waiting for the HttpCache. 474 bool cache_pending_; // We are waiting for the HttpCache.
461 bool done_reading_; // All available data was read. 475 bool done_reading_; // All available data was read.
462 bool vary_mismatch_; // The request doesn't match the stored vary data. 476 bool vary_mismatch_; // The request doesn't match the stored vary data.
463 bool couldnt_conditionalize_request_; 477 bool couldnt_conditionalize_request_;
464 bool bypass_lock_for_test_; // A test is exercising the cache lock. 478 bool bypass_lock_for_test_; // A test is exercising the cache lock.
465 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. 479 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
480 bool validating_cannot_proceed_;
466 scoped_refptr<IOBuffer> read_buf_; 481 scoped_refptr<IOBuffer> read_buf_;
467 int io_buf_len_; 482 int io_buf_len_;
468 int read_offset_; 483 int read_offset_;
469 int effective_load_flags_; 484 int effective_load_flags_;
470 int write_len_; 485 int write_len_;
471 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. 486 std::unique_ptr<PartialData> partial_; // We are dealing with range requests.
472 CompletionCallback io_callback_; 487 CompletionCallback io_callback_;
473 488
474 // Members used to track data for histograms. 489 // Members used to track data for histograms.
475 // This cache_entry_status_ takes precedence over 490 // This cache_entry_status_ takes precedence over
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 BeforeHeadersSentCallback before_headers_sent_callback_; 522 BeforeHeadersSentCallback before_headers_sent_callback_;
508 523
509 base::WeakPtrFactory<Transaction> weak_factory_; 524 base::WeakPtrFactory<Transaction> weak_factory_;
510 525
511 DISALLOW_COPY_AND_ASSIGN(Transaction); 526 DISALLOW_COPY_AND_ASSIGN(Transaction);
512 }; 527 };
513 528
514 } // namespace net 529 } // namespace net
515 530
516 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 531 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698