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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after 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(); | |
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 Loading... | |
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_HEADERS_PHASE_CANNOT_PROCEED, | |
228 STATE_FINISH_HEADERS, | |
229 STATE_FINISH_HEADERS_COMPLETE, | |
223 | 230 |
224 // These states are entered from Read/AddTruncatedFlag. | 231 // These states are entered from Read/AddTruncatedFlag. |
225 STATE_NETWORK_READ, | 232 STATE_NETWORK_READ, |
226 STATE_NETWORK_READ_COMPLETE, | 233 STATE_NETWORK_READ_COMPLETE, |
227 STATE_CACHE_READ_DATA, | 234 STATE_CACHE_READ_DATA, |
228 STATE_CACHE_READ_DATA_COMPLETE, | 235 STATE_CACHE_READ_DATA_COMPLETE, |
229 STATE_CACHE_WRITE_DATA, | 236 STATE_CACHE_WRITE_DATA, |
230 STATE_CACHE_WRITE_DATA_COMPLETE, | 237 STATE_CACHE_WRITE_DATA_COMPLETE, |
231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, | 238 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE | 239 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE |
(...skipping 11 matching lines...) Expand all Loading... | |
244 VALIDATION_CAUSE_MAX | 251 VALIDATION_CAUSE_MAX |
245 }; | 252 }; |
246 | 253 |
247 // Runs the state transition loop. Resets and calls |callback_| on exit, | 254 // Runs the state transition loop. Resets and calls |callback_| on exit, |
248 // unless the return value is ERR_IO_PENDING. | 255 // unless the return value is ERR_IO_PENDING. |
249 int DoLoop(int result); | 256 int DoLoop(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. |
261 // | |
262 // Note that since headers and response body phases might be going on in | |
jkarlin
2017/04/20 15:05:29
s/might be going on in parallel/can occur in paral
shivanisha
2017/04/21 23:06:00
N/A now that this comment is not needed here.
| |
263 // parallel for two transactions, a transaction in one phase should not be | |
264 // accessing disk entry fields of the other index as that might lead to data | |
Randy Smith (Not in Mondays)
2017/04/19 17:26:34
I'm not sure what "of the other index" means in th
shivanisha
2017/04/21 23:06:00
N/A.
| |
265 // races in some backends (like block file cache). | |
Randy Smith (Not in Mondays)
2017/04/19 17:26:34
I'd rephrase this with to talk about what the cach
jkarlin
2017/04/20 15:05:29
I think what we really need is a DCHECK in the ent
shivanisha
2017/04/21 23:06:00
Added new functions in ActiveEntry for data size,
jkarlin
2017/04/25 16:00:51
Sorry, I meant meant putting the checks in the dis
| |
254 int DoGetBackend(); | 266 int DoGetBackend(); |
255 int DoGetBackendComplete(int result); | 267 int DoGetBackendComplete(int result); |
256 int DoInitEntry(); | 268 int DoInitEntry(); |
257 int DoOpenEntry(); | 269 int DoOpenEntry(); |
258 int DoOpenEntryComplete(int result); | 270 int DoOpenEntryComplete(int result); |
259 int DoDoomEntry(); | 271 int DoDoomEntry(); |
260 int DoDoomEntryComplete(int result); | 272 int DoDoomEntryComplete(int result); |
261 int DoCreateEntry(); | 273 int DoCreateEntry(); |
262 int DoCreateEntryComplete(int result); | 274 int DoCreateEntryComplete(int result); |
263 int DoAddToEntry(); | 275 int DoAddToEntry(); |
(...skipping 17 matching lines...) Expand all Loading... | |
281 int DoOverwriteCachedResponse(); | 293 int DoOverwriteCachedResponse(); |
282 int DoCacheWriteResponse(); | 294 int DoCacheWriteResponse(); |
283 int DoCacheWriteResponseComplete(int result); | 295 int DoCacheWriteResponseComplete(int result); |
284 int DoTruncateCachedData(); | 296 int DoTruncateCachedData(); |
285 int DoTruncateCachedDataComplete(int result); | 297 int DoTruncateCachedDataComplete(int result); |
286 int DoTruncateCachedMetadata(); | 298 int DoTruncateCachedMetadata(); |
287 int DoTruncateCachedMetadataComplete(int result); | 299 int DoTruncateCachedMetadataComplete(int result); |
288 int DoPartialHeadersReceived(); | 300 int DoPartialHeadersReceived(); |
289 int DoCacheReadMetadata(); | 301 int DoCacheReadMetadata(); |
290 int DoCacheReadMetadataComplete(int result); | 302 int DoCacheReadMetadataComplete(int result); |
303 int DoHeadersPhaseCannotProceed(); | |
304 int DoFinishHeaders(int result); | |
305 int DoFinishHeadersComplete(int result); | |
291 int DoNetworkRead(); | 306 int DoNetworkRead(); |
292 int DoNetworkReadComplete(int result); | 307 int DoNetworkReadComplete(int result); |
293 int DoCacheReadData(); | 308 int DoCacheReadData(); |
294 int DoCacheReadDataComplete(int result); | 309 int DoCacheReadDataComplete(int result); |
295 int DoCacheWriteData(int num_bytes); | 310 int DoCacheWriteData(int num_bytes); |
296 int DoCacheWriteDataComplete(int result); | 311 int DoCacheWriteDataComplete(int result); |
297 int DoCacheWriteTruncatedResponse(); | 312 int DoCacheWriteTruncatedResponse(); |
298 int DoCacheWriteTruncatedResponseComplete(int result); | 313 int DoCacheWriteTruncatedResponseComplete(int result); |
299 | 314 |
300 // Sets request_ and fields derived from it. | 315 // Sets request_ and fields derived from it. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 void SetResponse(const HttpResponseInfo& new_response); | 438 void SetResponse(const HttpResponseInfo& new_response); |
424 void SetAuthResponse(const HttpResponseInfo& new_response); | 439 void SetAuthResponse(const HttpResponseInfo& new_response); |
425 | 440 |
426 void UpdateCacheEntryStatus( | 441 void UpdateCacheEntryStatus( |
427 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); | 442 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); |
428 | 443 |
429 // Sets the response.cache_entry_status to the current cache_entry_status_. | 444 // Sets the response.cache_entry_status to the current cache_entry_status_. |
430 void SyncCacheEntryStatusToResponse(); | 445 void SyncCacheEntryStatusToResponse(); |
431 void RecordHistograms(); | 446 void RecordHistograms(); |
432 | 447 |
433 // Called to signal completion of asynchronous IO. | 448 // Called to signal completion of asynchronous IO. Note that this callback is |
449 // used in the conventional sense where one layer calls the callback of the | |
450 // layer above it e.g. this callback gets called from the network transaction | |
451 // layer. In addition, it is also used for HttpCache layer to let this | |
452 // transaction know when it is out of a queued state in ActiveEntry and can | |
453 // continue its processing. | |
434 void OnIOComplete(int result); | 454 void OnIOComplete(int result); |
435 | 455 |
436 // When in a DoLoop, use this to set the next state as it verifies that the | 456 // When in a DoLoop, use this to set the next state as it verifies that the |
437 // state isn't set twice. | 457 // state isn't set twice. |
438 void TransitionToState(State state); | 458 void TransitionToState(State state); |
439 | 459 |
440 State next_state_; | 460 State next_state_; |
441 const HttpRequestInfo* request_; | 461 const HttpRequestInfo* request_; |
442 RequestPriority priority_; | 462 RequestPriority priority_; |
443 NetLogWithSource net_log_; | 463 NetLogWithSource net_log_; |
444 std::unique_ptr<HttpRequestInfo> custom_request_; | 464 std::unique_ptr<HttpRequestInfo> custom_request_; |
445 HttpRequestHeaders request_headers_copy_; | 465 HttpRequestHeaders request_headers_copy_; |
446 // If extra_headers specified a "if-modified-since" or "if-none-match", | 466 // If extra_headers specified a "if-modified-since" or "if-none-match", |
447 // |external_validation_| contains the value of those headers. | 467 // |external_validation_| contains the value of those headers. |
448 ValidationHeaders external_validation_; | 468 ValidationHeaders external_validation_; |
449 base::WeakPtr<HttpCache> cache_; | 469 base::WeakPtr<HttpCache> cache_; |
450 HttpCache::ActiveEntry* entry_; | 470 HttpCache::ActiveEntry* entry_; |
451 HttpCache::ActiveEntry* new_entry_; | 471 HttpCache::ActiveEntry* new_entry_; |
452 std::unique_ptr<HttpTransaction> network_trans_; | 472 std::unique_ptr<HttpTransaction> network_trans_; |
453 CompletionCallback callback_; // Consumer's callback. | 473 CompletionCallback callback_; // Consumer's callback. |
454 HttpResponseInfo response_; | 474 HttpResponseInfo response_; |
455 HttpResponseInfo auth_response_; | 475 HttpResponseInfo auth_response_; |
456 const HttpResponseInfo* new_response_; | 476 const HttpResponseInfo* new_response_; |
457 std::string cache_key_; | 477 std::string cache_key_; |
458 Mode mode_; | 478 Mode mode_; |
479 Mode original_mode_; // Used when restarting the transaction. | |
459 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. |
460 bool invalid_range_; // We may bypass the cache for this request. | 481 bool invalid_range_; // We may bypass the cache for this request. |
461 bool truncated_; // We don't have all the response data. | 482 bool truncated_; // We don't have all the response data. |
462 bool is_sparse_; // The data is stored in sparse byte ranges. | 483 bool is_sparse_; // The data is stored in sparse byte ranges. |
463 bool range_requested_; // The user requested a byte range. | 484 bool range_requested_; // The user requested a byte range. |
464 bool handling_206_; // We must deal with this 206 response. | 485 bool handling_206_; // We must deal with this 206 response. |
465 bool cache_pending_; // We are waiting for the HttpCache. | 486 bool cache_pending_; // We are waiting for the HttpCache. |
466 bool done_reading_; // All available data was read. | 487 bool done_reading_; // All available data was read. |
467 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. |
468 bool couldnt_conditionalize_request_; | 489 bool couldnt_conditionalize_request_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 bool in_do_loop_; | 536 bool in_do_loop_; |
516 | 537 |
517 base::WeakPtrFactory<Transaction> weak_factory_; | 538 base::WeakPtrFactory<Transaction> weak_factory_; |
518 | 539 |
519 DISALLOW_COPY_AND_ASSIGN(Transaction); | 540 DISALLOW_COPY_AND_ASSIGN(Transaction); |
520 }; | 541 }; |
521 | 542 |
522 } // namespace net | 543 } // namespace net |
523 | 544 |
524 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 545 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |