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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 const CompletionCallback& io_callback() { return io_callback_; } | 122 const CompletionCallback& io_callback() { return io_callback_; } |
123 | 123 |
124 const NetLogWithSource& net_log() const; | 124 const NetLogWithSource& net_log() const; |
125 | 125 |
126 // Bypasses the cache lock whenever there is lock contention. | 126 // Bypasses the cache lock whenever there is lock contention. |
127 void BypassLockForTest() { | 127 void BypassLockForTest() { |
128 bypass_lock_for_test_ = true; | 128 bypass_lock_for_test_ = true; |
129 } | 129 } |
130 | 130 |
| 131 void BypassLockAfterHeadersForTest() { |
| 132 bypass_lock_after_headers_for_test_ = true; |
| 133 } |
| 134 |
131 // Generates a failure when attempting to conditionalize a network request. | 135 // Generates a failure when attempting to conditionalize a network request. |
132 void FailConditionalizationForTest() { | 136 void FailConditionalizationForTest() { |
133 fail_conditionalization_for_test_ = true; | 137 fail_conditionalization_for_test_ = true; |
134 } | 138 } |
135 | 139 |
136 // HttpTransaction methods: | 140 // HttpTransaction methods: |
137 int Start(const HttpRequestInfo* request_info, | 141 int Start(const HttpRequestInfo* request_info, |
138 const CompletionCallback& callback, | 142 const CompletionCallback& callback, |
139 const NetLogWithSource& net_log) override; | 143 const NetLogWithSource& net_log) override; |
140 int RestartIgnoringLastError(const CompletionCallback& callback) override; | 144 int RestartIgnoringLastError(const CompletionCallback& callback) override; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 188 |
185 std::string values[kNumValidationHeaders]; | 189 std::string values[kNumValidationHeaders]; |
186 void Reset() { | 190 void Reset() { |
187 initialized = false; | 191 initialized = false; |
188 for (auto& value : values) | 192 for (auto& value : values) |
189 value.clear(); | 193 value.clear(); |
190 } | 194 } |
191 bool initialized; | 195 bool initialized; |
192 }; | 196 }; |
193 | 197 |
194 // A snapshot of pieces of the transaction before entering the state machine | |
195 // so that the state can be restored when restarting the state machine. | |
196 struct RestartInfo { | |
197 Mode mode = NONE; | |
198 HttpResponseInfo::CacheEntryStatus cache_entry_status = | |
199 HttpResponseInfo::CacheEntryStatus::ENTRY_UNDEFINED; | |
200 }; | |
201 | |
202 enum State { | 198 enum State { |
203 STATE_UNSET, | 199 STATE_UNSET, |
204 | 200 |
205 // Normally, states are traversed in approximately this order. | 201 // Normally, states are traversed in approximately this order. |
206 STATE_NONE, | 202 STATE_NONE, |
207 STATE_GET_BACKEND, | 203 STATE_GET_BACKEND, |
208 STATE_GET_BACKEND_COMPLETE, | 204 STATE_GET_BACKEND_COMPLETE, |
209 STATE_INIT_ENTRY, | 205 STATE_INIT_ENTRY, |
210 STATE_OPEN_ENTRY, | 206 STATE_OPEN_ENTRY, |
211 STATE_OPEN_ENTRY_COMPLETE, | 207 STATE_OPEN_ENTRY_COMPLETE, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 int DoOverwriteCachedResponse(); | 301 int DoOverwriteCachedResponse(); |
306 int DoCacheWriteResponse(); | 302 int DoCacheWriteResponse(); |
307 int DoCacheWriteResponseComplete(int result); | 303 int DoCacheWriteResponseComplete(int result); |
308 int DoTruncateCachedData(); | 304 int DoTruncateCachedData(); |
309 int DoTruncateCachedDataComplete(int result); | 305 int DoTruncateCachedDataComplete(int result); |
310 int DoTruncateCachedMetadata(); | 306 int DoTruncateCachedMetadata(); |
311 int DoTruncateCachedMetadataComplete(int result); | 307 int DoTruncateCachedMetadataComplete(int result); |
312 int DoPartialHeadersReceived(); | 308 int DoPartialHeadersReceived(); |
313 int DoCacheReadMetadata(); | 309 int DoCacheReadMetadata(); |
314 int DoCacheReadMetadataComplete(int result); | 310 int DoCacheReadMetadataComplete(int result); |
315 int DoHeadersPhaseCannotProceed(); | 311 int DoHeadersPhaseCannotProceed(int result); |
316 int DoFinishHeaders(int result); | 312 int DoFinishHeaders(int result); |
317 int DoFinishHeadersComplete(int result); | 313 int DoFinishHeadersComplete(int result); |
318 int DoNetworkRead(); | 314 int DoNetworkRead(); |
319 int DoNetworkReadComplete(int result); | 315 int DoNetworkReadComplete(int result); |
320 int DoCacheReadData(); | 316 int DoCacheReadData(); |
321 int DoCacheReadDataComplete(int result); | 317 int DoCacheReadDataComplete(int result); |
322 int DoCacheWriteData(int num_bytes); | 318 int DoCacheWriteData(int num_bytes); |
323 int DoCacheWriteDataComplete(int result); | 319 int DoCacheWriteDataComplete(int result); |
324 int DoCacheWriteTruncatedResponse(); | 320 int DoCacheWriteTruncatedResponse(); |
325 int DoCacheWriteTruncatedResponseComplete(int result); | 321 int DoCacheWriteTruncatedResponseComplete(int result); |
326 | 322 |
| 323 // Adds time out handling while waiting to be added to entry or after headers |
| 324 // phase is complete. |
| 325 void AddCacheLockTimeoutHandler(ActiveEntry* entry); |
| 326 |
327 // Sets request_ and fields derived from it. | 327 // Sets request_ and fields derived from it. |
328 void SetRequest(const NetLogWithSource& net_log); | 328 void SetRequest(const NetLogWithSource& net_log); |
329 | 329 |
330 // Returns true if the request should be handled exclusively by the network | 330 // Returns true if the request should be handled exclusively by the network |
331 // layer (skipping the cache entirely). | 331 // layer (skipping the cache entirely). |
332 bool ShouldPassThrough(); | 332 bool ShouldPassThrough(); |
333 | 333 |
334 // Called to begin reading from the cache. Returns network error code. | 334 // Called to begin reading from the cache. Returns network error code. |
335 int BeginCacheRead(); | 335 int BeginCacheRead(); |
336 | 336 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 // Called when we are done writing to the cache entry. | 407 // Called when we are done writing to the cache entry. |
408 void DoneWritingToEntry(bool success); | 408 void DoneWritingToEntry(bool success); |
409 | 409 |
410 // Returns an error to signal the caller that the current read failed. The | 410 // Returns an error to signal the caller that the current read failed. The |
411 // current operation |result| is also logged. If |restart| is true, the | 411 // current operation |result| is also logged. If |restart| is true, the |
412 // transaction should be restarted. | 412 // transaction should be restarted. |
413 int OnCacheReadError(int result, bool restart); | 413 int OnCacheReadError(int result, bool restart); |
414 | 414 |
415 // Called when the cache lock timeout fires. | 415 // Called when the cache lock timeout fires. |
416 void OnAddToEntryTimeout(base::TimeTicks start_time); | 416 void OnCacheLockTimeout(base::TimeTicks start_time); |
417 | 417 |
418 // Deletes the current partial cache entry (sparse), and optionally removes | 418 // Deletes the current partial cache entry (sparse), and optionally removes |
419 // the control object (partial_). | 419 // the control object (partial_). |
420 void DoomPartialEntry(bool delete_object); | 420 void DoomPartialEntry(bool delete_object); |
421 | 421 |
422 // Performs the needed work after receiving data from the network, when | 422 // Performs the needed work after receiving data from the network, when |
423 // working with range requests. | 423 // working with range requests. |
424 int DoPartialNetworkReadCompleted(int result); | 424 int DoPartialNetworkReadCompleted(int result); |
425 | 425 |
426 // Performs the needed work after receiving data from the cache, when | 426 // Performs the needed work after receiving data from the cache, when |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 bool invalid_range_; // We may bypass the cache for this request. | 498 bool invalid_range_; // We may bypass the cache for this request. |
499 bool truncated_; // We don't have all the response data. | 499 bool truncated_; // We don't have all the response data. |
500 bool is_sparse_; // The data is stored in sparse byte ranges. | 500 bool is_sparse_; // The data is stored in sparse byte ranges. |
501 bool range_requested_; // The user requested a byte range. | 501 bool range_requested_; // The user requested a byte range. |
502 bool handling_206_; // We must deal with this 206 response. | 502 bool handling_206_; // We must deal with this 206 response. |
503 bool cache_pending_; // We are waiting for the HttpCache. | 503 bool cache_pending_; // We are waiting for the HttpCache. |
504 bool done_reading_; // All available data was read. | 504 bool done_reading_; // All available data was read. |
505 bool vary_mismatch_; // The request doesn't match the stored vary data. | 505 bool vary_mismatch_; // The request doesn't match the stored vary data. |
506 bool couldnt_conditionalize_request_; | 506 bool couldnt_conditionalize_request_; |
507 bool bypass_lock_for_test_; // A test is exercising the cache lock. | 507 bool bypass_lock_for_test_; // A test is exercising the cache lock. |
| 508 bool bypass_lock_after_headers_for_test_; // A test is exercising the cache |
| 509 // lock. |
508 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. | 510 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. |
509 scoped_refptr<IOBuffer> read_buf_; | 511 scoped_refptr<IOBuffer> read_buf_; |
510 int io_buf_len_; | 512 int io_buf_len_; |
511 int read_offset_; | 513 int read_offset_; |
512 int effective_load_flags_; | 514 int effective_load_flags_; |
513 int write_len_; | 515 int write_len_; |
514 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. | 516 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. |
515 CompletionCallback io_callback_; | 517 CompletionCallback io_callback_; |
516 | 518 |
517 // Members used to track data for histograms. | 519 // Members used to track data for histograms. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 bool in_do_loop_; | 555 bool in_do_loop_; |
554 | 556 |
555 base::WeakPtrFactory<Transaction> weak_factory_; | 557 base::WeakPtrFactory<Transaction> weak_factory_; |
556 | 558 |
557 DISALLOW_COPY_AND_ASSIGN(Transaction); | 559 DISALLOW_COPY_AND_ASSIGN(Transaction); |
558 }; | 560 }; |
559 | 561 |
560 } // namespace net | 562 } // namespace net |
561 | 563 |
562 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 564 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |