[email protected] | 93fe7516 | 2012-02-09 21:51:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // This file declares HttpCache::Transaction, a private class of HttpCache so |
| 6 | // it should only be included by http_cache.cc |
| 7 | |
| 8 | #ifndef NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
| 9 | #define NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
| 10 | |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 11 | #include <stddef.h> |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 12 | #include <stdint.h> |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 13 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14 | #include <memory> |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 15 | #include <string> |
| 16 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 17 | #include "base/macros.h" |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
[email protected] | 66e96c4 | 2013-06-28 15:20:31 | [diff] [blame] | 20 | #include "base/time/time.h" |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 21 | #include "net/base/completion_once_callback.h" |
Bence Béky | 61f756c | 2018-04-25 14:17:53 | [diff] [blame] | 22 | #include "net/base/completion_repeating_callback.h" |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 23 | #include "net/base/io_buffer.h" |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 24 | #include "net/base/ip_endpoint.h" |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 25 | #include "net/base/load_states.h" |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 26 | #include "net/base/net_error_details.h" |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 27 | #include "net/base/request_priority.h" |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 28 | #include "net/http/http_cache.h" |
[email protected] | 5aa2013 | 2011-04-27 23:11:34 | [diff] [blame] | 29 | #include "net/http/http_request_headers.h" |
ricea | 64c07d79 | 2014-10-08 03:37:00 | [diff] [blame] | 30 | #include "net/http/http_response_headers.h" |
[email protected] | 66e96c4 | 2013-06-28 15:20:31 | [diff] [blame] | 31 | #include "net/http/http_response_info.h" |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 32 | #include "net/http/http_transaction.h" |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 33 | #include "net/http/partial_data.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 34 | #include "net/log/net_log_with_source.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 35 | #include "net/socket/connection_attempts.h" |
ricea | d4470367 | 2015-06-18 05:47:57 | [diff] [blame] | 36 | #include "net/websockets/websocket_handshake_stream_base.h" |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 37 | |
| 38 | namespace net { |
| 39 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 40 | class PartialData; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 41 | struct HttpRequestInfo; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 42 | struct LoadTimingInfo; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 43 | class SSLPrivateKey; |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 44 | |
| 45 | // This is the transaction that is returned by the HttpCache transaction |
| 46 | // factory. |
shivanisha | c6582e1 | 2017-07-14 22:18:19 | [diff] [blame] | 47 | class NET_EXPORT_PRIVATE HttpCache::Transaction : public HttpTransaction { |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 48 | public: |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 49 | // The transaction has the following modes, which apply to how it may access |
| 50 | // its cache entry. |
| 51 | // |
| 52 | // o If the mode of the transaction is NONE, then it is in "pass through" |
| 53 | // mode and all methods just forward to the inner network transaction. |
| 54 | // |
| 55 | // o If the mode of the transaction is only READ, then it may only read from |
| 56 | // the cache entry. |
| 57 | // |
| 58 | // o If the mode of the transaction is only WRITE, then it may only write to |
| 59 | // the cache entry. |
| 60 | // |
| 61 | // o If the mode of the transaction is READ_WRITE, then the transaction may |
| 62 | // optionally modify the cache entry (e.g., possibly corresponding to |
| 63 | // cache validation). |
| 64 | // |
| 65 | // o If the mode of the transaction is UPDATE, then the transaction may |
| 66 | // update existing cache entries, but will never create a new entry or |
| 67 | // respond using the entry read from the cache. |
| 68 | enum Mode { |
| 69 | NONE = 0, |
| 70 | READ_META = 1 << 0, |
| 71 | READ_DATA = 1 << 1, |
| 72 | READ = READ_META | READ_DATA, |
| 73 | WRITE = 1 << 2, |
| 74 | READ_WRITE = READ | WRITE, |
| 75 | UPDATE = READ_META | WRITE, // READ_WRITE & ~READ_DATA |
| 76 | }; |
| 77 | |
Yao Xiao | a08ecc8 | 2019-09-19 20:05:16 | [diff] [blame] | 78 | // This enum backs a histogram. Please keep enums.xml up to date with any |
| 79 | // changes, and new entries should be appended at the end. Never re-arrange / |
| 80 | // re-use values. |
| 81 | enum class NetworkIsolationKeyPresent { |
| 82 | kNotPresentCacheableRequest = 0, |
| 83 | kNotPresentNonCacheableRequest = 1, |
| 84 | kPresent = 2, |
| 85 | kMaxValue = kPresent, |
| 86 | }; |
| 87 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 88 | Transaction(RequestPriority priority, |
[email protected] | 027bd85a | 2013-12-27 22:39:10 | [diff] [blame] | 89 | HttpCache* cache); |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 90 | ~Transaction() override; |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 91 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 92 | // Virtual so it can be extended for testing. |
| 93 | virtual Mode mode() const; |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 94 | |
shivanisha | 8061c420 | 2017-06-13 23:35:52 | [diff] [blame] | 95 | std::string& method() { return method_; } |
| 96 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 97 | const std::string& key() const { return cache_key_; } |
| 98 | |
[email protected] | 767c2c9d | 2012-05-09 23:44:27 | [diff] [blame] | 99 | HttpCache::ActiveEntry* entry() { return entry_; } |
| 100 | |
[email protected] | fbf5047 | 2010-07-15 22:53:53 | [diff] [blame] | 101 | // Returns the LoadState of the writer transaction of a given ActiveEntry. In |
| 102 | // other words, returns the LoadState of this transaction without asking the |
| 103 | // http cache, because this transaction should be the one currently writing |
| 104 | // to the cache entry. |
| 105 | LoadState GetWriterLoadState() const; |
| 106 | |
Bence Béky | a4a5093 | 2018-08-10 13:39:41 | [diff] [blame] | 107 | const CompletionRepeatingCallback& io_callback() { return io_callback_; } |
[email protected] | 7e6a4f3 | 2010-02-11 21:06:24 | [diff] [blame] | 108 | |
Steven Bingler | b6917f3 | 2019-02-09 00:37:24 | [diff] [blame] | 109 | void SetIOCallBackForTest(CompletionRepeatingCallback cb) { |
| 110 | io_callback_ = cb; |
| 111 | } |
| 112 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 113 | const NetLogWithSource& net_log() const; |
[email protected] | f6f1bebc | 2011-01-07 03:04:54 | [diff] [blame] | 114 | |
[email protected] | 8aacaf38 | 2014-06-24 05:33:41 | [diff] [blame] | 115 | // Bypasses the cache lock whenever there is lock contention. |
| 116 | void BypassLockForTest() { |
| 117 | bypass_lock_for_test_ = true; |
| 118 | } |
| 119 | |
shivanisha | bc3b71b | 2017-06-24 07:21:14 | [diff] [blame] | 120 | void BypassLockAfterHeadersForTest() { |
| 121 | bypass_lock_after_headers_for_test_ = true; |
| 122 | } |
| 123 | |
rvargas | 43dc8fd | 2015-01-07 23:03:25 | [diff] [blame] | 124 | // Generates a failure when attempting to conditionalize a network request. |
| 125 | void FailConditionalizationForTest() { |
| 126 | fail_conditionalization_for_test_ = true; |
| 127 | } |
| 128 | |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 129 | // HttpTransaction methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 130 | int Start(const HttpRequestInfo* request_info, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 131 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 132 | const NetLogWithSource& net_log) override; |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 133 | int RestartIgnoringLastError(CompletionOnceCallback callback) override; |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 134 | int RestartWithCertificate(scoped_refptr<X509Certificate> client_cert, |
| 135 | scoped_refptr<SSLPrivateKey> client_private_key, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 136 | CompletionOnceCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 137 | int RestartWithAuth(const AuthCredentials& credentials, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 138 | CompletionOnceCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 139 | bool IsReadyToRestartForAuth() override; |
| 140 | int Read(IOBuffer* buf, |
| 141 | int buf_len, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 142 | CompletionOnceCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 143 | void StopCaching() override; |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 144 | int64_t GetTotalReceivedBytes() const override; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 145 | int64_t GetTotalSentBytes() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 146 | void DoneReading() override; |
| 147 | const HttpResponseInfo* GetResponseInfo() const override; |
| 148 | LoadState GetLoadState() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 149 | void SetQuicServerInfo(QuicServerInfo* quic_server_info) override; |
| 150 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 151 | bool GetRemoteEndpoint(IPEndPoint* endpoint) const override; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 152 | void PopulateNetErrorDetails(NetErrorDetails* details) const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 153 | void SetPriority(RequestPriority priority) override; |
| 154 | void SetWebSocketHandshakeStreamCreateHelper( |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 155 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 156 | void SetBeforeNetworkStartCallback( |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 157 | const BeforeNetworkStartCallback& callback) override; |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 158 | void SetBeforeHeadersSentCallback( |
| 159 | const BeforeHeadersSentCallback& callback) override; |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 160 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override; |
| 161 | void SetResponseHeadersCallback(ResponseHeadersCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 162 | int ResumeNetworkStart() override; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 163 | void GetConnectionAttempts(ConnectionAttempts* out) const override; |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 164 | |
shivanisha | 8061c420 | 2017-06-13 23:35:52 | [diff] [blame] | 165 | // Invoked when parallel validation cannot proceed due to response failure |
| 166 | // and this transaction needs to be restarted. |
| 167 | void SetValidatingCannotProceed(); |
| 168 | |
shivanisha | 36a816e | 2017-07-05 22:27:45 | [diff] [blame] | 169 | // Invoked to remove the association between a transaction waiting to be |
| 170 | // added to an entry and the entry. |
| 171 | void ResetCachePendingState() { cache_pending_ = false; } |
| 172 | |
xunjieli | a0166f4 | 2017-02-23 17:44:57 | [diff] [blame] | 173 | // Returns the estimate of dynamically allocated memory in bytes. |
| 174 | size_t EstimateMemoryUsage() const; |
| 175 | |
shivanisha | c6582e1 | 2017-07-14 22:18:19 | [diff] [blame] | 176 | RequestPriority priority() const { return priority_; } |
| 177 | PartialData* partial() { return partial_.get(); } |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 178 | bool is_truncated() { return truncated_; } |
| 179 | |
| 180 | // Invoked when this writer transaction is about to be removed from entry. |
| 181 | // If result is an error code, a future Read should fail with |result|. |
| 182 | void WriterAboutToBeRemovedFromEntry(int result); |
shivanisha | c6582e1 | 2017-07-14 22:18:19 | [diff] [blame] | 183 | |
Shivani Sharma | edd8dd28 | 2017-10-30 14:04:45 | [diff] [blame] | 184 | // Invoked when this transaction is about to become a reader because the cache |
| 185 | // entry has finished writing. |
| 186 | void WriteModeTransactionAboutToBecomeReader(); |
| 187 | |
Shivani Sharma | 8170b77 | 2017-12-08 15:59:42 | [diff] [blame] | 188 | // Invoked when HttpCache decides whether this transaction should join |
| 189 | // parallel writing or create a new writers object. This is then used |
| 190 | // for logging metrics. Can be called repeatedly, but doesn't change once the |
| 191 | // value has been set to something other than PARALLEL_WRITING_NONE. |
| 192 | void MaybeSetParallelWritingPatternForMetrics(ParallelWritingPattern pattern); |
| 193 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 194 | private: |
| 195 | static const size_t kNumValidationHeaders = 2; |
| 196 | // Helper struct to pair a header name with its value, for |
| 197 | // headers used to validate cache entries. |
| 198 | struct ValidationHeaders { |
| 199 | ValidationHeaders() : initialized(false) {} |
| 200 | |
| 201 | std::string values[kNumValidationHeaders]; |
shivanisha | 54d4504 | 2017-06-15 16:52:44 | [diff] [blame] | 202 | void Reset() { |
| 203 | initialized = false; |
| 204 | for (auto& value : values) |
| 205 | value.clear(); |
| 206 | } |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 207 | bool initialized; |
| 208 | }; |
| 209 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 210 | struct NetworkTransactionInfo { |
| 211 | NetworkTransactionInfo(); |
| 212 | ~NetworkTransactionInfo(); |
| 213 | |
| 214 | // Load timing information for the last network request, if any. Set in the |
| 215 | // 304 and 206 response cases, as the network transaction may be destroyed |
| 216 | // before the caller requests load timing information. |
| 217 | std::unique_ptr<LoadTimingInfo> old_network_trans_load_timing; |
| 218 | int64_t total_received_bytes = 0; |
| 219 | int64_t total_sent_bytes = 0; |
| 220 | ConnectionAttempts old_connection_attempts; |
| 221 | IPEndPoint old_remote_endpoint; |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 222 | |
| 223 | DISALLOW_COPY_AND_ASSIGN(NetworkTransactionInfo); |
| 224 | }; |
| 225 | |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 226 | enum State { |
jkarlin | fa6b5af | 2017-03-22 16:08:59 | [diff] [blame] | 227 | STATE_UNSET, |
| 228 | |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 229 | // Normally, states are traversed in approximately this order. |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 230 | STATE_NONE, |
[email protected] | 4677316 | 2010-05-07 22:31:20 | [diff] [blame] | 231 | STATE_GET_BACKEND, |
| 232 | STATE_GET_BACKEND_COMPLETE, |
[email protected] | b68f1b25 | 2009-12-05 01:37:18 | [diff] [blame] | 233 | STATE_INIT_ENTRY, |
Steven Bingler | 861855dc | 2019-03-22 20:53:46 | [diff] [blame] | 234 | STATE_OPEN_OR_CREATE_ENTRY, |
| 235 | STATE_OPEN_OR_CREATE_ENTRY_COMPLETE, |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 236 | STATE_DOOM_ENTRY, |
| 237 | STATE_DOOM_ENTRY_COMPLETE, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 238 | STATE_CREATE_ENTRY, |
| 239 | STATE_CREATE_ENTRY_COMPLETE, |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 240 | STATE_ADD_TO_ENTRY, |
[email protected] | 7e6a4f3 | 2010-02-11 21:06:24 | [diff] [blame] | 241 | STATE_ADD_TO_ENTRY_COMPLETE, |
shivanisha | 36a816e | 2017-07-05 22:27:45 | [diff] [blame] | 242 | STATE_DONE_HEADERS_ADD_TO_ENTRY_COMPLETE, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 243 | STATE_CACHE_READ_RESPONSE, |
| 244 | STATE_CACHE_READ_RESPONSE_COMPLETE, |
Dominic Farolino | c78b763 | 2019-08-29 07:56:07 | [diff] [blame] | 245 | STATE_WRITE_UPDATED_PREFETCH_RESPONSE, |
| 246 | STATE_WRITE_UPDATED_PREFETCH_RESPONSE_COMPLETE, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 247 | STATE_CACHE_DISPATCH_VALIDATION, |
| 248 | STATE_CACHE_QUERY_DATA, |
| 249 | STATE_CACHE_QUERY_DATA_COMPLETE, |
[email protected] | 034740a | 2010-06-11 17:16:48 | [diff] [blame] | 250 | STATE_START_PARTIAL_CACHE_VALIDATION, |
| 251 | STATE_COMPLETE_PARTIAL_CACHE_VALIDATION, |
Dave Tapuska | 57b4f9d | 2018-06-12 01:55:05 | [diff] [blame] | 252 | STATE_CACHE_UPDATE_STALE_WHILE_REVALIDATE_TIMEOUT, |
| 253 | STATE_CACHE_UPDATE_STALE_WHILE_REVALIDATE_TIMEOUT_COMPLETE, |
| 254 | STATE_SETUP_ENTRY_FOR_READ, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 255 | STATE_SEND_REQUEST, |
| 256 | STATE_SEND_REQUEST_COMPLETE, |
| 257 | STATE_SUCCESSFUL_SEND_REQUEST, |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 258 | STATE_UPDATE_CACHED_RESPONSE, |
hubbe | 6083454 | 2015-07-15 17:41:58 | [diff] [blame] | 259 | STATE_CACHE_WRITE_UPDATED_RESPONSE, |
| 260 | STATE_CACHE_WRITE_UPDATED_RESPONSE_COMPLETE, |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 261 | STATE_UPDATE_CACHED_RESPONSE_COMPLETE, |
| 262 | STATE_OVERWRITE_CACHED_RESPONSE, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 263 | STATE_CACHE_WRITE_RESPONSE, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 264 | STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 265 | STATE_TRUNCATE_CACHED_DATA, |
| 266 | STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
[email protected] | 02e7a01 | 2010-05-10 23:06:33 | [diff] [blame] | 267 | STATE_TRUNCATE_CACHED_METADATA, |
| 268 | STATE_TRUNCATE_CACHED_METADATA_COMPLETE, |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 269 | STATE_PARTIAL_HEADERS_RECEIVED, |
shivanisha | 8061c420 | 2017-06-13 23:35:52 | [diff] [blame] | 270 | STATE_HEADERS_PHASE_CANNOT_PROCEED, |
| 271 | STATE_FINISH_HEADERS, |
| 272 | STATE_FINISH_HEADERS_COMPLETE, |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 273 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 274 | // These states are entered from Read. |
| 275 | STATE_NETWORK_READ_CACHE_WRITE, |
| 276 | STATE_NETWORK_READ_CACHE_WRITE_COMPLETE, |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 277 | STATE_CACHE_READ_DATA, |
| 278 | STATE_CACHE_READ_DATA_COMPLETE, |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 279 | // These states are entered if the request should be handled exclusively |
| 280 | // by the network layer (skipping the cache entirely). |
| 281 | STATE_NETWORK_READ, |
| 282 | STATE_NETWORK_READ_COMPLETE, |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 283 | }; |
| 284 | |
jkarlin | 9e50a0f | 2016-05-13 18:05:20 | [diff] [blame] | 285 | // Used for categorizing validation triggers in histograms. |
| 286 | // NOTE: This enumeration is used in histograms, so please do not add entries |
| 287 | // in the middle. |
| 288 | enum ValidationCause { |
| 289 | VALIDATION_CAUSE_UNDEFINED, |
| 290 | VALIDATION_CAUSE_VARY_MISMATCH, |
| 291 | VALIDATION_CAUSE_VALIDATE_FLAG, |
| 292 | VALIDATION_CAUSE_STALE, |
| 293 | VALIDATION_CAUSE_ZERO_FRESHNESS, |
| 294 | VALIDATION_CAUSE_MAX |
| 295 | }; |
| 296 | |
Maks Orlovich | d036d702 | 2017-11-17 15:51:18 | [diff] [blame] | 297 | enum MemoryEntryDataHints { |
| 298 | // If this hint is set, the caching headers indicate we can't do anything |
| 299 | // with this entry (unless we are ignoring them thanks to a loadflag), |
| 300 | // i.e. it's expired and has nothing that permits validations. |
| 301 | HINT_UNUSABLE_PER_CACHING_HEADERS = (1 << 0), |
| 302 | }; |
| 303 | |
hubbe | d5a2132 | 2015-07-15 17:51:18 | [diff] [blame] | 304 | // Runs the state transition loop. Resets and calls |callback_| on exit, |
| 305 | // unless the return value is ERR_IO_PENDING. |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 306 | int DoLoop(int result); |
| 307 | |
[email protected] | b68f1b25 | 2009-12-05 01:37:18 | [diff] [blame] | 308 | // Each of these methods corresponds to a State value. If there is an |
| 309 | // argument, the value corresponds to the return of the previous state or |
| 310 | // corresponding callback. |
[email protected] | 4677316 | 2010-05-07 22:31:20 | [diff] [blame] | 311 | int DoGetBackend(); |
| 312 | int DoGetBackendComplete(int result); |
[email protected] | b68f1b25 | 2009-12-05 01:37:18 | [diff] [blame] | 313 | int DoInitEntry(); |
Steven Bingler | 861855dc | 2019-03-22 20:53:46 | [diff] [blame] | 314 | int DoOpenOrCreateEntry(); |
| 315 | int DoOpenOrCreateEntryComplete(int result); |
[email protected] | b68f1b25 | 2009-12-05 01:37:18 | [diff] [blame] | 316 | int DoDoomEntry(); |
[email protected] | 7d7ad6e4 | 2010-01-14 01:30:53 | [diff] [blame] | 317 | int DoDoomEntryComplete(int result); |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 318 | int DoCreateEntry(); |
| 319 | int DoCreateEntryComplete(int result); |
[email protected] | b68f1b25 | 2009-12-05 01:37:18 | [diff] [blame] | 320 | int DoAddToEntry(); |
[email protected] | 7e6a4f3 | 2010-02-11 21:06:24 | [diff] [blame] | 321 | int DoAddToEntryComplete(int result); |
shivanisha | 36a816e | 2017-07-05 22:27:45 | [diff] [blame] | 322 | int DoDoneHeadersAddToEntryComplete(int result); |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 323 | int DoCacheReadResponse(); |
| 324 | int DoCacheReadResponseComplete(int result); |
Dominic Farolino | c78b763 | 2019-08-29 07:56:07 | [diff] [blame] | 325 | int DoCacheWriteUpdatedPrefetchResponse(int result); |
| 326 | int DoCacheWriteUpdatedPrefetchResponseComplete(int result); |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 327 | int DoCacheDispatchValidation(); |
| 328 | int DoCacheQueryData(); |
| 329 | int DoCacheQueryDataComplete(int result); |
Dave Tapuska | 57b4f9d | 2018-06-12 01:55:05 | [diff] [blame] | 330 | int DoCacheUpdateStaleWhileRevalidateTimeout(); |
| 331 | int DoCacheUpdateStaleWhileRevalidateTimeoutComplete(int result); |
| 332 | int DoSetupEntryForRead(); |
[email protected] | 034740a | 2010-06-11 17:16:48 | [diff] [blame] | 333 | int DoStartPartialCacheValidation(); |
| 334 | int DoCompletePartialCacheValidation(int result); |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 335 | int DoSendRequest(); |
| 336 | int DoSendRequestComplete(int result); |
| 337 | int DoSuccessfulSendRequest(); |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 338 | int DoUpdateCachedResponse(); |
hubbe | 6083454 | 2015-07-15 17:41:58 | [diff] [blame] | 339 | int DoCacheWriteUpdatedResponse(); |
| 340 | int DoCacheWriteUpdatedResponseComplete(int result); |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 341 | int DoUpdateCachedResponseComplete(int result); |
| 342 | int DoOverwriteCachedResponse(); |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 343 | int DoCacheWriteResponse(); |
hubbe | 7b8cfb9 | 2015-07-13 21:11:55 | [diff] [blame] | 344 | int DoCacheWriteResponseComplete(int result); |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 345 | int DoTruncateCachedData(); |
| 346 | int DoTruncateCachedDataComplete(int result); |
[email protected] | 02e7a01 | 2010-05-10 23:06:33 | [diff] [blame] | 347 | int DoTruncateCachedMetadata(); |
| 348 | int DoTruncateCachedMetadataComplete(int result); |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 349 | int DoPartialHeadersReceived(); |
shivanisha | bc3b71b | 2017-06-24 07:21:14 | [diff] [blame] | 350 | int DoHeadersPhaseCannotProceed(int result); |
shivanisha | 8061c420 | 2017-06-13 23:35:52 | [diff] [blame] | 351 | int DoFinishHeaders(int result); |
| 352 | int DoFinishHeadersComplete(int result); |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 353 | int DoNetworkReadCacheWrite(); |
| 354 | int DoNetworkReadCacheWriteComplete(int result); |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 355 | int DoCacheReadData(); |
| 356 | int DoCacheReadDataComplete(int result); |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 357 | int DoNetworkRead(); |
| 358 | int DoNetworkReadComplete(int result); |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 359 | |
shivanisha | bc3b71b | 2017-06-24 07:21:14 | [diff] [blame] | 360 | // Adds time out handling while waiting to be added to entry or after headers |
| 361 | // phase is complete. |
| 362 | void AddCacheLockTimeoutHandler(ActiveEntry* entry); |
| 363 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 364 | // Sets request_ and fields derived from it. |
shivanisha | 54d4504 | 2017-06-15 16:52:44 | [diff] [blame] | 365 | void SetRequest(const NetLogWithSource& net_log); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 366 | |
| 367 | // Returns true if the request should be handled exclusively by the network |
| 368 | // layer (skipping the cache entirely). |
| 369 | bool ShouldPassThrough(); |
| 370 | |
| 371 | // Called to begin reading from the cache. Returns network error code. |
| 372 | int BeginCacheRead(); |
| 373 | |
| 374 | // Called to begin validating the cache entry. Returns network error code. |
| 375 | int BeginCacheValidation(); |
| 376 | |
| 377 | // Called to begin validating an entry that stores partial content. Returns |
| 378 | // a network error code. |
| 379 | int BeginPartialCacheValidation(); |
| 380 | |
| 381 | // Validates the entry headers against the requested range and continues with |
| 382 | // the validation of the rest of the entry. Returns a network error code. |
[email protected] | 4a62071 | 2011-07-22 17:41:09 | [diff] [blame] | 383 | int ValidateEntryHeadersAndContinue(); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 384 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 385 | // Called to start requests which were given an "if-modified-since" or |
| 386 | // "if-none-match" validation header by the caller (NOT when the request was |
| 387 | // conditionalized internally in response to LOAD_VALIDATE_CACHE). |
| 388 | // Returns a network error code. |
| 389 | int BeginExternallyConditionalizedRequest(); |
| 390 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 391 | // Called to restart a network transaction after an error. Returns network |
| 392 | // error code. |
| 393 | int RestartNetworkRequest(); |
| 394 | |
| 395 | // Called to restart a network transaction with a client certificate. |
| 396 | // Returns network error code. |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 397 | int RestartNetworkRequestWithCertificate( |
| 398 | scoped_refptr<X509Certificate> client_cert, |
| 399 | scoped_refptr<SSLPrivateKey> client_private_key); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 400 | |
| 401 | // Called to restart a network transaction with authentication credentials. |
| 402 | // Returns network error code. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 403 | int RestartNetworkRequestWithAuth(const AuthCredentials& credentials); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 404 | |
Dave Tapuska | 57b4f9d | 2018-06-12 01:55:05 | [diff] [blame] | 405 | // Called to determine if we need to validate the cache entry before using it, |
| 406 | // and whether the validation should be synchronous or asynchronous. |
| 407 | ValidationType RequiresValidation(); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 408 | |
| 409 | // Called to make the request conditional (to ask the server if the cached |
| 410 | // copy is valid). Returns true if able to make the request conditional. |
| 411 | bool ConditionalizeRequest(); |
| 412 | |
Maks Orlovich | d036d702 | 2017-11-17 15:51:18 | [diff] [blame] | 413 | // Determines if saved response permits conditionalization, and extracts |
| 414 | // etag/last-modified values. Only depends on |response_.headers|. |
| 415 | // |*etag_value| and |*last_modified_value| will be set if true is returned, |
| 416 | // but may also be modified in other cases. |
| 417 | bool IsResponseConditionalizable(std::string* etag_value, |
| 418 | std::string* last_modified_value) const; |
| 419 | |
Steven Bingler | 861855dc | 2019-03-22 20:53:46 | [diff] [blame] | 420 | // Returns true if |method_| indicates that we should only try to open an |
| 421 | // entry and not attempt to create. |
| 422 | bool ShouldOpenOnlyMethods() const; |
| 423 | |
Maks Orlovich | d036d702 | 2017-11-17 15:51:18 | [diff] [blame] | 424 | // Returns true if the resource info MemoryEntryDataHints bit flags in |
| 425 | // |in_memory_info| and the current request & load flags suggest that |
| 426 | // the cache entry in question is not actually usable for HTTP |
| 427 | // (i.e. already expired, and nothing is forcing us to disregard that). |
| 428 | bool MaybeRejectBasedOnEntryInMemoryData(uint8_t in_memory_info); |
| 429 | |
| 430 | // Returns true if response_ is such that, if saved to cache, it would only |
| 431 | // be usable if load flags asked us to ignore caching headers. |
| 432 | // (return value of false makes no statement as to suitability of the entry). |
| 433 | bool ComputeUnusablePerCachingHeaders(); |
| 434 | |
[email protected] | a189bce | 2009-12-01 01:59:12 | [diff] [blame] | 435 | // Makes sure that a 206 response is expected. Returns true on success. |
[email protected] | cbf91ef2 | 2011-07-19 18:10:06 | [diff] [blame] | 436 | // On success, handling_206_ will be set to true if we are processing a |
[email protected] | a189bce | 2009-12-01 01:59:12 | [diff] [blame] | 437 | // partial entry. |
[email protected] | cbf91ef2 | 2011-07-19 18:10:06 | [diff] [blame] | 438 | bool ValidatePartialResponse(); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 439 | |
| 440 | // Handles a response validation error by bypassing the cache. |
| 441 | void IgnoreRangeRequest(); |
| 442 | |
rvargas | ee8204a | 2015-02-11 21:28:11 | [diff] [blame] | 443 | // Fixes the response headers to match expectations for a HEAD request. |
[email protected] | b53a412 | 2014-07-31 00:06:46 | [diff] [blame] | 444 | void FixHeadersForHead(); |
| 445 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 446 | // Called to write data to the cache entry. If the write fails, then the |
| 447 | // cache entry is destroyed. Future calls to this function will just do |
| 448 | // nothing without side-effect. Returns a network error code. |
Bence Béky | a4a5093 | 2018-08-10 13:39:41 | [diff] [blame] | 449 | int WriteToEntry(int index, |
| 450 | int offset, |
| 451 | IOBuffer* data, |
| 452 | int data_len, |
| 453 | CompletionOnceCallback callback); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 454 | |
Dominic Farolino | c78b763 | 2019-08-29 07:56:07 | [diff] [blame] | 455 | // Called to write a response to the cache entry. |truncated| indicates if the |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 456 | // entry should be marked as incomplete. |
Dominic Farolino | c78b763 | 2019-08-29 07:56:07 | [diff] [blame] | 457 | int WriteResponseInfoToEntry(const HttpResponseInfo& response, |
| 458 | bool truncated); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 459 | |
hubbe | 6083454 | 2015-07-15 17:41:58 | [diff] [blame] | 460 | // Helper function, should be called with result of WriteResponseInfoToEntry |
| 461 | // (or the result of the callback, when WriteResponseInfoToEntry returns |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 462 | // ERR_IO_PENDING). Calls DoneWithEntry if |result| is not the right |
hubbe | 6083454 | 2015-07-15 17:41:58 | [diff] [blame] | 463 | // number of bytes. It is expected that the state that calls this will |
| 464 | // return whatever net error code this function returns, which currently |
| 465 | // is always "OK". |
| 466 | int OnWriteResponseInfoToEntryComplete(int result); |
| 467 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 468 | // Configures the transaction to read from the network and stop writing to the |
| 469 | // entry. It will release the entry if possible. Returns true if caching could |
| 470 | // be stopped successfully. It will not be stopped if there are multiple |
| 471 | // transactions writing to the cache simultaneously. |
| 472 | bool StopCachingImpl(bool success); |
| 473 | |
| 474 | // Informs the HttpCache that this transaction is done with the entry and |
| 475 | // changes the mode to NONE. Set |entry_is_complete| to false if the |
| 476 | // transaction has not yet finished fully writing or reading the request |
| 477 | // to/from the entry. If |entry_is_complete| is false the result may be either |
| 478 | // a truncated or a doomed entry based on whether the stored response can be |
| 479 | // resumed or not. |
| 480 | void DoneWithEntry(bool did_finish); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 481 | |
[email protected] | 93fe7516 | 2012-02-09 21:51:31 | [diff] [blame] | 482 | // Returns an error to signal the caller that the current read failed. The |
[email protected] | 40caa4c | 2012-03-20 20:42:58 | [diff] [blame] | 483 | // current operation |result| is also logged. If |restart| is true, the |
| 484 | // transaction should be restarted. |
| 485 | int OnCacheReadError(int result, bool restart); |
[email protected] | 93fe7516 | 2012-02-09 21:51:31 | [diff] [blame] | 486 | |
[email protected] | 8aacaf38 | 2014-06-24 05:33:41 | [diff] [blame] | 487 | // Called when the cache lock timeout fires. |
shivanisha | bc3b71b | 2017-06-24 07:21:14 | [diff] [blame] | 488 | void OnCacheLockTimeout(base::TimeTicks start_time); |
[email protected] | 8aacaf38 | 2014-06-24 05:33:41 | [diff] [blame] | 489 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 490 | // Deletes the current partial cache entry (sparse), and optionally removes |
| 491 | // the control object (partial_). |
| 492 | void DoomPartialEntry(bool delete_object); |
| 493 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 494 | // Performs the needed work after receiving data from the network, when |
| 495 | // working with range requests. |
| 496 | int DoPartialNetworkReadCompleted(int result); |
| 497 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 498 | // Performs the needed work after receiving data from the cache, when |
| 499 | // working with range requests. |
| 500 | int DoPartialCacheReadCompleted(int result); |
| 501 | |
[email protected] | 9f03cb7a | 2012-07-30 23:15:20 | [diff] [blame] | 502 | // Restarts this transaction after deleting the cached data. It is meant to |
| 503 | // be used when the current request cannot be fulfilled due to conflicts |
| 504 | // between the byte range request and the cached entry. |
| 505 | int DoRestartPartialRequest(); |
| 506 | |
rvargas | b499156 | 2015-01-07 21:59:57 | [diff] [blame] | 507 | // Resets the relavant internal state to remove traces of internal processing |
| 508 | // related to range requests. Deletes |partial_| if |delete_object| is true. |
| 509 | void ResetPartialState(bool delete_object); |
| 510 | |
[email protected] | b8982bf7 | 2013-09-11 00:36:55 | [diff] [blame] | 511 | // Resets |network_trans_|, which must be non-NULL. Also updates |
| 512 | // |old_network_trans_load_timing_|, which must be NULL when this is called. |
| 513 | void ResetNetworkTransaction(); |
| 514 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 515 | // Returns the currently active network transaction. |
| 516 | const HttpTransaction* network_transaction() const; |
| 517 | HttpTransaction* network_transaction(); |
| 518 | |
Shivani Sharma | edd8dd28 | 2017-10-30 14:04:45 | [diff] [blame] | 519 | // Returns the network transaction from |this| or from writers only if it was |
| 520 | // moved from |this| to writers. This is so that statistics of the network |
| 521 | // transaction are not attributed to any other writer member. |
| 522 | const HttpTransaction* GetOwnedOrMovedNetworkTransaction() const; |
| 523 | |
jamartin | 19ff6f1b | 2016-07-26 23:37:41 | [diff] [blame] | 524 | // Returns true if we should bother attempting to resume this request if it is |
| 525 | // aborted while in progress. If |has_data| is true, the size of the stored |
[email protected] | 8a30114 | 2011-04-13 18:33:40 | [diff] [blame] | 526 | // data is considered for the result. |
| 527 | bool CanResume(bool has_data); |
| 528 | |
jamartin | 19ff6f1b | 2016-07-26 23:37:41 | [diff] [blame] | 529 | // Setter for response_ and auth_response_. It updates its cache entry status, |
| 530 | // if needed. |
| 531 | void SetResponse(const HttpResponseInfo& new_response); |
| 532 | void SetAuthResponse(const HttpResponseInfo& new_response); |
| 533 | |
| 534 | void UpdateCacheEntryStatus( |
| 535 | HttpResponseInfo::CacheEntryStatus new_cache_entry_status); |
| 536 | |
| 537 | // Sets the response.cache_entry_status to the current cache_entry_status_. |
| 538 | void SyncCacheEntryStatusToResponse(); |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 539 | |
| 540 | // Logs histograms for this transaction. It is invoked when the transaction is |
| 541 | // either complete or is done writing to entry and will continue in |
| 542 | // network-only mode. |
[email protected] | 6e14396 | 2012-08-09 21:34:33 | [diff] [blame] | 543 | void RecordHistograms(); |
[email protected] | 5a07c19 | 2012-07-30 20:18:22 | [diff] [blame] | 544 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 545 | // Returns true if this transaction is a member of entry_->writers. |
| 546 | bool InWriters() const; |
| 547 | |
shivanisha | 8061c420 | 2017-06-13 23:35:52 | [diff] [blame] | 548 | // Called to signal completion of asynchronous IO. Note that this callback is |
| 549 | // used in the conventional sense where one layer calls the callback of the |
| 550 | // layer above it e.g. this callback gets called from the network transaction |
| 551 | // layer. In addition, it is also used for HttpCache layer to let this |
| 552 | // transaction know when it is out of a queued state in ActiveEntry and can |
| 553 | // continue its processing. |
[email protected] | 027bd85a | 2013-12-27 22:39:10 | [diff] [blame] | 554 | void OnIOComplete(int result); |
| 555 | |
jkarlin | 5de449fd | 2017-03-22 19:31:43 | [diff] [blame] | 556 | // When in a DoLoop, use this to set the next state as it verifies that the |
| 557 | // state isn't set twice. |
| 558 | void TransitionToState(State state); |
| 559 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 560 | // Helper function to decide the next reading state. |
| 561 | int TransitionToReadingState(); |
| 562 | |
| 563 | // Saves network transaction info using |transaction|. |
| 564 | void SaveNetworkTransactionInfo(const HttpTransaction& transaction); |
| 565 | |
Shawn Pickett | 0b47071 | 2019-08-15 00:43:45 | [diff] [blame] | 566 | // Disables caching for media content when running on battery. |
| 567 | bool ShouldDisableMediaCaching(const HttpResponseHeaders* headers) const; |
| 568 | |
[email protected] | ab3e58a | 2009-12-04 00:55:17 | [diff] [blame] | 569 | State next_state_; |
shivanisha | 54d4504 | 2017-06-15 16:52:44 | [diff] [blame] | 570 | |
| 571 | // Initial request with which Start() was invoked. |
| 572 | const HttpRequestInfo* initial_request_; |
| 573 | |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 574 | const HttpRequestInfo* request_; |
shivanisha | 54d4504 | 2017-06-15 16:52:44 | [diff] [blame] | 575 | |
shivanisha | 8061c420 | 2017-06-13 23:35:52 | [diff] [blame] | 576 | std::string method_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 577 | RequestPriority priority_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 578 | NetLogWithSource net_log_; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 579 | std::unique_ptr<HttpRequestInfo> custom_request_; |
[email protected] | 5aa2013 | 2011-04-27 23:11:34 | [diff] [blame] | 580 | HttpRequestHeaders request_headers_copy_; |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 581 | // If extra_headers specified a "if-modified-since" or "if-none-match", |
| 582 | // |external_validation_| contains the value of those headers. |
| 583 | ValidationHeaders external_validation_; |
| 584 | base::WeakPtr<HttpCache> cache_; |
| 585 | HttpCache::ActiveEntry* entry_; |
[email protected] | b68f1b25 | 2009-12-05 01:37:18 | [diff] [blame] | 586 | HttpCache::ActiveEntry* new_entry_; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 587 | std::unique_ptr<HttpTransaction> network_trans_; |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 588 | CompletionOnceCallback callback_; // Consumer's callback. |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 589 | HttpResponseInfo response_; |
| 590 | HttpResponseInfo auth_response_; |
Dominic Farolino | c78b763 | 2019-08-29 07:56:07 | [diff] [blame] | 591 | |
| 592 | // This is only populated when we want to modify a prefetch request in some |
| 593 | // way for future transactions, while leaving it untouched for the current |
| 594 | // one. DoCacheReadResponseComplete() sets this to a copy of |response_|, |
| 595 | // and modifies the members for future transactions. Then, |
| 596 | // WriteResponseInfoToEntry() writes |updated_prefetch_response_| to the cache |
| 597 | // entry if it is populated, or |response_| otherwise. Finally, |
| 598 | // WriteResponseInfoToEntry() resets this to base::nullopt. |
| 599 | std::unique_ptr<HttpResponseInfo> updated_prefetch_response_; |
| 600 | |
[email protected] | b79d7ab | 2009-12-17 18:28:08 | [diff] [blame] | 601 | const HttpResponseInfo* new_response_; |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 602 | std::string cache_key_; |
| 603 | Mode mode_; |
[email protected] | d7358ba | 2014-01-04 01:39:49 | [diff] [blame] | 604 | bool reading_; // We are already reading. Never reverts to false once set. |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 605 | bool invalid_range_; // We may bypass the cache for this request. |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 606 | bool truncated_; // We don't have all the response data. |
[email protected] | 06c351a | 2010-12-03 19:11:29 | [diff] [blame] | 607 | bool is_sparse_; // The data is stored in sparse byte ranges. |
[email protected] | 4a62071 | 2011-07-22 17:41:09 | [diff] [blame] | 608 | bool range_requested_; // The user requested a byte range. |
[email protected] | cbf91ef2 | 2011-07-19 18:10:06 | [diff] [blame] | 609 | bool handling_206_; // We must deal with this 206 response. |
[email protected] | 7d7ad6e4 | 2010-01-14 01:30:53 | [diff] [blame] | 610 | bool cache_pending_; // We are waiting for the HttpCache. |
shivanisha | 36a816e | 2017-07-05 22:27:45 | [diff] [blame] | 611 | |
| 612 | // Headers have been received from the network and it's not a match with the |
| 613 | // existing entry. |
| 614 | bool done_headers_create_new_entry_; |
| 615 | |
[email protected] | 9bb9f99 | 2013-01-11 01:43:16 | [diff] [blame] | 616 | bool vary_mismatch_; // The request doesn't match the stored vary data. |
[email protected] | 2ef5d00e | 2013-03-23 16:17:27 | [diff] [blame] | 617 | bool couldnt_conditionalize_request_; |
[email protected] | 8aacaf38 | 2014-06-24 05:33:41 | [diff] [blame] | 618 | bool bypass_lock_for_test_; // A test is exercising the cache lock. |
shivanisha | bc3b71b | 2017-06-24 07:21:14 | [diff] [blame] | 619 | bool bypass_lock_after_headers_for_test_; // A test is exercising the cache |
| 620 | // lock. |
rvargas | 43dc8fd | 2015-01-07 23:03:25 | [diff] [blame] | 621 | bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 622 | scoped_refptr<IOBuffer> read_buf_; |
Shivani Sharma | 67e27fe0 | 2019-08-12 19:34:27 | [diff] [blame] | 623 | |
| 624 | // Length of the buffer passed in Read(). |
| 625 | int read_buf_len_; |
| 626 | |
[email protected] | 5048294 | 2009-12-21 18:57:01 | [diff] [blame] | 627 | int io_buf_len_; |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 628 | int read_offset_; |
| 629 | int effective_load_flags_; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 630 | std::unique_ptr<PartialData> partial_; // We are dealing with range requests. |
Bence Béky | 61f756c | 2018-04-25 14:17:53 | [diff] [blame] | 631 | CompletionRepeatingCallback io_callback_; |
[email protected] | 6e14396 | 2012-08-09 21:34:33 | [diff] [blame] | 632 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 633 | // Error code to be returned from a subsequent Read call if shared writing |
| 634 | // failed in a separate transaction. |
| 635 | int shared_writing_error_; |
| 636 | |
[email protected] | 6e14396 | 2012-08-09 21:34:33 | [diff] [blame] | 637 | // Members used to track data for histograms. |
jamartin | 19ff6f1b | 2016-07-26 23:37:41 | [diff] [blame] | 638 | // This cache_entry_status_ takes precedence over |
| 639 | // response_.cache_entry_status. In fact, response_.cache_entry_status must be |
| 640 | // kept in sync with cache_entry_status_ (via SetResponse and |
| 641 | // UpdateCacheEntryStatus). |
| 642 | HttpResponseInfo::CacheEntryStatus cache_entry_status_; |
jkarlin | 9e50a0f | 2016-05-13 18:05:20 | [diff] [blame] | 643 | ValidationCause validation_cause_; |
[email protected] | 6e14396 | 2012-08-09 21:34:33 | [diff] [blame] | 644 | base::TimeTicks entry_lock_waiting_since_; |
| 645 | base::TimeTicks first_cache_access_since_; |
| 646 | base::TimeTicks send_request_since_; |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 647 | base::TimeTicks read_headers_since_; |
jkarlin | 91ae360 | 2016-05-25 14:05:38 | [diff] [blame] | 648 | base::Time open_entry_last_used_; |
Maks Orlovich | d036d702 | 2017-11-17 15:51:18 | [diff] [blame] | 649 | bool cant_conditionalize_zero_freshness_from_memhint_; |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 650 | bool recorded_histograms_; |
Shivani Sharma | 8170b77 | 2017-12-08 15:59:42 | [diff] [blame] | 651 | ParallelWritingPattern parallel_writing_pattern_; |
[email protected] | 6e14396 | 2012-08-09 21:34:33 | [diff] [blame] | 652 | |
Shivani Sharma | c18f976 | 2017-10-23 16:43:23 | [diff] [blame] | 653 | NetworkTransactionInfo network_transaction_info_; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 654 | |
Shivani Sharma | edd8dd28 | 2017-10-30 14:04:45 | [diff] [blame] | 655 | // True if this transaction created the network transaction that is now being |
| 656 | // used by writers. This is used to check that only this transaction should |
| 657 | // account for the network bytes and other statistics of the network |
| 658 | // transaction. |
| 659 | // TODO(shivanisha) Note that if this transaction dies mid-way and there are |
| 660 | // other writer transactions, no transaction then accounts for those |
| 661 | // statistics. |
| 662 | bool moved_network_transaction_to_writers_; |
| 663 | |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 664 | // The helper object to use to create WebSocketHandshakeStreamBase |
| 665 | // objects. Only relevant when establishing a WebSocket connection. |
| 666 | // This is passed to the underlying network transaction. It is stored here in |
| 667 | // case the transaction does not exist yet. |
| 668 | WebSocketHandshakeStreamBase::CreateHelper* |
| 669 | websocket_handshake_stream_base_create_helper_; |
| 670 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 671 | BeforeNetworkStartCallback before_network_start_callback_; |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 672 | BeforeHeadersSentCallback before_headers_sent_callback_; |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 673 | RequestHeadersCallback request_headers_callback_; |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 674 | ResponseHeadersCallback response_headers_callback_; |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 675 | |
jkarlin | 5de449fd | 2017-03-22 19:31:43 | [diff] [blame] | 676 | // True if the Transaction is currently processing the DoLoop. |
| 677 | bool in_do_loop_; |
| 678 | |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 679 | base::WeakPtrFactory<Transaction> weak_factory_{this}; |
kulkarni.a | cd7b446 | 2014-08-28 07:41:34 | [diff] [blame] | 680 | |
[email protected] | 40f16922 | 2013-11-22 09:08:54 | [diff] [blame] | 681 | DISALLOW_COPY_AND_ASSIGN(Transaction); |
[email protected] | 983a1da | 2009-11-11 19:59:23 | [diff] [blame] | 682 | }; |
| 683 | |
| 684 | } // namespace net |
| 685 | |
| 686 | #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |