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

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

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: jkarlin feedback + remove a dcheck based on a crash Created 3 years, 6 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 READ_WRITE = READ | WRITE, 73 READ_WRITE = READ | WRITE,
74 UPDATE = READ_META | WRITE, // READ_WRITE & ~READ_DATA 74 UPDATE = READ_META | WRITE, // READ_WRITE & ~READ_DATA
75 }; 75 };
76 76
77 Transaction(RequestPriority priority, 77 Transaction(RequestPriority priority,
78 HttpCache* cache); 78 HttpCache* cache);
79 ~Transaction() override; 79 ~Transaction() override;
80 80
81 Mode mode() const { return mode_; } 81 Mode mode() const { return mode_; }
82 82
83 std::string& method() { return method_; }
84
83 const std::string& key() const { return cache_key_; } 85 const std::string& key() const { return cache_key_; }
84 86
85 // Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the 87 // Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the
86 // HTTP cache entry that backs this transaction (if any). 88 // HTTP cache entry that backs this transaction (if any).
87 // Returns the number of bytes actually written, or a net error code. If the 89 // Returns the number of bytes actually written, or a net error code. If the
88 // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a 90 // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a
89 // reference to the buffer (until completion), and notifies the caller using 91 // reference to the buffer (until completion), and notifies the caller using
90 // the provided |callback| when the operation finishes. 92 // the provided |callback| when the operation finishes.
91 // 93 //
92 // The first time this method is called for a given transaction, previous 94 // The first time this method is called for a given transaction, previous
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void SetPriority(RequestPriority priority) override; 159 void SetPriority(RequestPriority priority) override;
158 void SetWebSocketHandshakeStreamCreateHelper( 160 void SetWebSocketHandshakeStreamCreateHelper(
159 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; 161 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override;
160 void SetBeforeNetworkStartCallback( 162 void SetBeforeNetworkStartCallback(
161 const BeforeNetworkStartCallback& callback) override; 163 const BeforeNetworkStartCallback& callback) override;
162 void SetBeforeHeadersSentCallback( 164 void SetBeforeHeadersSentCallback(
163 const BeforeHeadersSentCallback& callback) override; 165 const BeforeHeadersSentCallback& callback) override;
164 int ResumeNetworkStart() override; 166 int ResumeNetworkStart() override;
165 void GetConnectionAttempts(ConnectionAttempts* out) const override; 167 void GetConnectionAttempts(ConnectionAttempts* out) const override;
166 168
169 // Invoked when parallel validation cannot proceed due to response failure
170 // and this transaction needs to be restarted.
171 void SetValidatingCannotProceed();
172
167 // Returns the estimate of dynamically allocated memory in bytes. 173 // Returns the estimate of dynamically allocated memory in bytes.
168 size_t EstimateMemoryUsage() const; 174 size_t EstimateMemoryUsage() const;
169 175
170 private: 176 private:
171 static const size_t kNumValidationHeaders = 2; 177 static const size_t kNumValidationHeaders = 2;
172 // Helper struct to pair a header name with its value, for 178 // Helper struct to pair a header name with its value, for
173 // headers used to validate cache entries. 179 // headers used to validate cache entries.
174 struct ValidationHeaders { 180 struct ValidationHeaders {
175 ValidationHeaders() : initialized(false) {} 181 ValidationHeaders() : initialized(false) {}
176 182
177 std::string values[kNumValidationHeaders]; 183 std::string values[kNumValidationHeaders];
178 bool initialized; 184 bool initialized;
179 }; 185 };
180 186
187 // A snapshot of pieces of the transaction before entering the state machine
188 // so that the state can be restored when restarting the state machine.
189 struct RestartInfo {
190 Mode mode = NONE;
191 HttpResponseInfo::CacheEntryStatus cache_entry_status =
192 HttpResponseInfo::CacheEntryStatus::ENTRY_UNDEFINED;
193 };
194
181 enum State { 195 enum State {
182 STATE_UNSET, 196 STATE_UNSET,
183 197
184 // Normally, states are traversed in approximately this order. 198 // Normally, states are traversed in approximately this order.
185 STATE_NONE, 199 STATE_NONE,
186 STATE_GET_BACKEND, 200 STATE_GET_BACKEND,
187 STATE_GET_BACKEND_COMPLETE, 201 STATE_GET_BACKEND_COMPLETE,
188 STATE_INIT_ENTRY, 202 STATE_INIT_ENTRY,
189 STATE_OPEN_ENTRY, 203 STATE_OPEN_ENTRY,
190 STATE_OPEN_ENTRY_COMPLETE, 204 STATE_OPEN_ENTRY_COMPLETE,
(...skipping 22 matching lines...) Expand all
213 STATE_OVERWRITE_CACHED_RESPONSE, 227 STATE_OVERWRITE_CACHED_RESPONSE,
214 STATE_CACHE_WRITE_RESPONSE, 228 STATE_CACHE_WRITE_RESPONSE,
215 STATE_CACHE_WRITE_RESPONSE_COMPLETE, 229 STATE_CACHE_WRITE_RESPONSE_COMPLETE,
216 STATE_TRUNCATE_CACHED_DATA, 230 STATE_TRUNCATE_CACHED_DATA,
217 STATE_TRUNCATE_CACHED_DATA_COMPLETE, 231 STATE_TRUNCATE_CACHED_DATA_COMPLETE,
218 STATE_TRUNCATE_CACHED_METADATA, 232 STATE_TRUNCATE_CACHED_METADATA,
219 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, 233 STATE_TRUNCATE_CACHED_METADATA_COMPLETE,
220 STATE_PARTIAL_HEADERS_RECEIVED, 234 STATE_PARTIAL_HEADERS_RECEIVED,
221 STATE_CACHE_READ_METADATA, 235 STATE_CACHE_READ_METADATA,
222 STATE_CACHE_READ_METADATA_COMPLETE, 236 STATE_CACHE_READ_METADATA_COMPLETE,
237 STATE_HEADERS_PHASE_CANNOT_PROCEED,
238 STATE_FINISH_HEADERS,
239 STATE_FINISH_HEADERS_COMPLETE,
223 240
224 // These states are entered from Read/AddTruncatedFlag. 241 // These states are entered from Read/AddTruncatedFlag.
225 STATE_NETWORK_READ, 242 STATE_NETWORK_READ,
226 STATE_NETWORK_READ_COMPLETE, 243 STATE_NETWORK_READ_COMPLETE,
227 STATE_CACHE_READ_DATA, 244 STATE_CACHE_READ_DATA,
228 STATE_CACHE_READ_DATA_COMPLETE, 245 STATE_CACHE_READ_DATA_COMPLETE,
229 STATE_CACHE_WRITE_DATA, 246 STATE_CACHE_WRITE_DATA,
230 STATE_CACHE_WRITE_DATA_COMPLETE, 247 STATE_CACHE_WRITE_DATA_COMPLETE,
231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, 248 STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE 249 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 int DoOverwriteCachedResponse(); 298 int DoOverwriteCachedResponse();
282 int DoCacheWriteResponse(); 299 int DoCacheWriteResponse();
283 int DoCacheWriteResponseComplete(int result); 300 int DoCacheWriteResponseComplete(int result);
284 int DoTruncateCachedData(); 301 int DoTruncateCachedData();
285 int DoTruncateCachedDataComplete(int result); 302 int DoTruncateCachedDataComplete(int result);
286 int DoTruncateCachedMetadata(); 303 int DoTruncateCachedMetadata();
287 int DoTruncateCachedMetadataComplete(int result); 304 int DoTruncateCachedMetadataComplete(int result);
288 int DoPartialHeadersReceived(); 305 int DoPartialHeadersReceived();
289 int DoCacheReadMetadata(); 306 int DoCacheReadMetadata();
290 int DoCacheReadMetadataComplete(int result); 307 int DoCacheReadMetadataComplete(int result);
308 int DoHeadersPhaseCannotProceed();
309 int DoFinishHeaders(int result);
310 int DoFinishHeadersComplete(int result);
291 int DoNetworkRead(); 311 int DoNetworkRead();
292 int DoNetworkReadComplete(int result); 312 int DoNetworkReadComplete(int result);
293 int DoCacheReadData(); 313 int DoCacheReadData();
294 int DoCacheReadDataComplete(int result); 314 int DoCacheReadDataComplete(int result);
295 int DoCacheWriteData(int num_bytes); 315 int DoCacheWriteData(int num_bytes);
296 int DoCacheWriteDataComplete(int result); 316 int DoCacheWriteDataComplete(int result);
297 int DoCacheWriteTruncatedResponse(); 317 int DoCacheWriteTruncatedResponse();
298 int DoCacheWriteTruncatedResponseComplete(int result); 318 int DoCacheWriteTruncatedResponseComplete(int result);
299 319
300 // Sets request_ and fields derived from it. 320 // Sets request_ and fields derived from it.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 void SetResponse(const HttpResponseInfo& new_response); 443 void SetResponse(const HttpResponseInfo& new_response);
424 void SetAuthResponse(const HttpResponseInfo& new_response); 444 void SetAuthResponse(const HttpResponseInfo& new_response);
425 445
426 void UpdateCacheEntryStatus( 446 void UpdateCacheEntryStatus(
427 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); 447 HttpResponseInfo::CacheEntryStatus new_cache_entry_status);
428 448
429 // Sets the response.cache_entry_status to the current cache_entry_status_. 449 // Sets the response.cache_entry_status to the current cache_entry_status_.
430 void SyncCacheEntryStatusToResponse(); 450 void SyncCacheEntryStatusToResponse();
431 void RecordHistograms(); 451 void RecordHistograms();
432 452
433 // Called to signal completion of asynchronous IO. 453 // Called to signal completion of asynchronous IO. Note that this callback is
454 // used in the conventional sense where one layer calls the callback of the
455 // layer above it e.g. this callback gets called from the network transaction
456 // layer. In addition, it is also used for HttpCache layer to let this
457 // transaction know when it is out of a queued state in ActiveEntry and can
458 // continue its processing.
434 void OnIOComplete(int result); 459 void OnIOComplete(int result);
435 460
436 // When in a DoLoop, use this to set the next state as it verifies that the 461 // When in a DoLoop, use this to set the next state as it verifies that the
437 // state isn't set twice. 462 // state isn't set twice.
438 void TransitionToState(State state); 463 void TransitionToState(State state);
439 464
440 State next_state_; 465 State next_state_;
441 const HttpRequestInfo* request_; 466 const HttpRequestInfo* request_;
467 std::string method_;
442 RequestPriority priority_; 468 RequestPriority priority_;
443 NetLogWithSource net_log_; 469 NetLogWithSource net_log_;
444 std::unique_ptr<HttpRequestInfo> custom_request_; 470 std::unique_ptr<HttpRequestInfo> custom_request_;
445 HttpRequestHeaders request_headers_copy_; 471 HttpRequestHeaders request_headers_copy_;
446 // If extra_headers specified a "if-modified-since" or "if-none-match", 472 // If extra_headers specified a "if-modified-since" or "if-none-match",
447 // |external_validation_| contains the value of those headers. 473 // |external_validation_| contains the value of those headers.
448 ValidationHeaders external_validation_; 474 ValidationHeaders external_validation_;
449 base::WeakPtr<HttpCache> cache_; 475 base::WeakPtr<HttpCache> cache_;
450 HttpCache::ActiveEntry* entry_; 476 HttpCache::ActiveEntry* entry_;
451 HttpCache::ActiveEntry* new_entry_; 477 HttpCache::ActiveEntry* new_entry_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 // case the transaction does not exist yet. 533 // case the transaction does not exist yet.
508 WebSocketHandshakeStreamBase::CreateHelper* 534 WebSocketHandshakeStreamBase::CreateHelper*
509 websocket_handshake_stream_base_create_helper_; 535 websocket_handshake_stream_base_create_helper_;
510 536
511 BeforeNetworkStartCallback before_network_start_callback_; 537 BeforeNetworkStartCallback before_network_start_callback_;
512 BeforeHeadersSentCallback before_headers_sent_callback_; 538 BeforeHeadersSentCallback before_headers_sent_callback_;
513 539
514 // True if the Transaction is currently processing the DoLoop. 540 // True if the Transaction is currently processing the DoLoop.
515 bool in_do_loop_; 541 bool in_do_loop_;
516 542
543 // Used to restore some members when the state machine is restarted after it
544 // has already been added to an entry e.g after |this| has completed
545 // validation and the writer transaction fails to completely write the
546 // response to the cache.
547 RestartInfo restart_info_;
548
517 base::WeakPtrFactory<Transaction> weak_factory_; 549 base::WeakPtrFactory<Transaction> weak_factory_;
518 550
519 DISALLOW_COPY_AND_ASSIGN(Transaction); 551 DISALLOW_COPY_AND_ASSIGN(Transaction);
520 }; 552 };
521 553
522 } // namespace net 554 } // namespace net
523 555
524 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 556 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698