OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // headers used to validate cache entries. | 89 // headers used to validate cache entries. |
90 struct ValidationHeaders { | 90 struct ValidationHeaders { |
91 ValidationHeaders() : initialized(false) {} | 91 ValidationHeaders() : initialized(false) {} |
92 | 92 |
93 std::string values[kNumValidationHeaders]; | 93 std::string values[kNumValidationHeaders]; |
94 bool initialized; | 94 bool initialized; |
95 }; | 95 }; |
96 | 96 |
97 enum State { | 97 enum State { |
98 STATE_NONE, | 98 STATE_NONE, |
99 STATE_START_REQUEST, | |
100 STATE_SEND_REQUEST, | 99 STATE_SEND_REQUEST, |
101 STATE_SEND_REQUEST_COMPLETE, | 100 STATE_SEND_REQUEST_COMPLETE, |
102 STATE_NETWORK_READ, | 101 STATE_NETWORK_READ, |
103 STATE_NETWORK_READ_COMPLETE, | 102 STATE_NETWORK_READ_COMPLETE, |
| 103 STATE_INIT_ENTRY, |
104 STATE_OPEN_ENTRY, | 104 STATE_OPEN_ENTRY, |
105 STATE_OPEN_ENTRY_COMPLETE, | 105 STATE_OPEN_ENTRY_COMPLETE, |
106 STATE_CREATE_ENTRY, | 106 STATE_CREATE_ENTRY, |
107 STATE_CREATE_ENTRY_COMPLETE, | 107 STATE_CREATE_ENTRY_COMPLETE, |
108 STATE_DOOM_ENTRY, | 108 STATE_DOOM_ENTRY, |
109 STATE_DOOM_ENTRY_COMPLETE, | 109 STATE_DOOM_ENTRY_COMPLETE, |
110 STATE_ADD_TO_ENTRY, | 110 STATE_ADD_TO_ENTRY, |
111 STATE_ADD_TO_ENTRY_COMPLETE, | |
112 STATE_ENTRY_AVAILABLE, | 111 STATE_ENTRY_AVAILABLE, |
| 112 STATE_PARTIAL_CACHE_VALIDATION, |
113 STATE_CACHE_READ_RESPONSE, | 113 STATE_CACHE_READ_RESPONSE, |
114 STATE_CACHE_READ_RESPONSE_COMPLETE, | 114 STATE_CACHE_READ_RESPONSE_COMPLETE, |
115 STATE_CACHE_WRITE_RESPONSE, | 115 STATE_CACHE_WRITE_RESPONSE, |
116 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 116 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
117 STATE_CACHE_QUERY_DATA, | 117 STATE_CACHE_QUERY_DATA, |
118 STATE_CACHE_QUERY_DATA_COMPLETE, | 118 STATE_CACHE_QUERY_DATA_COMPLETE, |
119 STATE_CACHE_READ_DATA, | 119 STATE_CACHE_READ_DATA, |
120 STATE_CACHE_READ_DATA_COMPLETE, | 120 STATE_CACHE_READ_DATA_COMPLETE, |
121 STATE_CACHE_WRITE_DATA, | 121 STATE_CACHE_WRITE_DATA, |
122 STATE_CACHE_WRITE_DATA_COMPLETE | 122 STATE_CACHE_WRITE_DATA_COMPLETE |
123 }; | 123 }; |
124 | 124 |
125 // This is a helper function used to trigger a completion callback. It may | 125 // This is a helper function used to trigger a completion callback. It may |
126 // only be called if callback_ is non-null. | 126 // only be called if callback_ is non-null. |
127 void DoCallback(int rv); | 127 void DoCallback(int rv); |
128 | 128 |
129 // This will trigger the completion callback if appropriate. | 129 // This will trigger the completion callback if appropriate. |
130 int HandleResult(int rv); | 130 int HandleResult(int rv); |
131 | 131 |
132 // Runs the state transition loop. | 132 // Runs the state transition loop. |
133 int DoLoop(int result); | 133 int DoLoop(int result); |
134 | 134 |
135 // Each of these methods corresponds to a State value. | 135 // Each of these methods corresponds to a State value. If there is an |
| 136 // argument, the value corresponds to the return of the previous state or |
| 137 // corresponding callback. |
136 int DoSendRequest(); | 138 int DoSendRequest(); |
137 int DoSendRequestComplete(int result); | 139 int DoSendRequestComplete(int result); |
138 int DoNetworkRead(); | 140 int DoNetworkRead(); |
139 int DoNetworkReadComplete(int result); | 141 int DoNetworkReadComplete(int result); |
| 142 int DoInitEntry(); |
| 143 int DoOpenEntry(); |
| 144 int DoOpenEntryComplete(); |
| 145 int DoCreateEntry(); |
| 146 int DoCreateEntryComplete(); |
| 147 int DoDoomEntry(); |
| 148 int DoDoomEntryComplete(); |
| 149 int DoAddToEntry(); |
| 150 int DoEntryAvailable(); |
| 151 int DoPartialCacheValidation(); |
140 int DoCacheReadData(); | 152 int DoCacheReadData(); |
141 int DoCacheReadDataComplete(int result); | 153 int DoCacheReadDataComplete(int result); |
142 int DoCacheQueryData(); | 154 int DoCacheQueryData(); |
143 int DoCacheQueryDataComplete(int result); | 155 int DoCacheQueryDataComplete(int result); |
144 int DoCacheWriteData(int num_bytes); | 156 int DoCacheWriteData(int num_bytes); |
145 int DoCacheWriteDataComplete(int result); | 157 int DoCacheWriteDataComplete(int result); |
146 | 158 |
147 // Sets request_ and fields derived from it. | 159 // Sets request_ and fields derived from it. |
148 void SetRequest(LoadLog* load_log, const HttpRequestInfo* request); | 160 void SetRequest(LoadLog* load_log, const HttpRequestInfo* request); |
149 | 161 |
150 // Returns true if the request should be handled exclusively by the network | 162 // Returns true if the request should be handled exclusively by the network |
151 // layer (skipping the cache entirely). | 163 // layer (skipping the cache entirely). |
152 bool ShouldPassThrough(); | 164 bool ShouldPassThrough(); |
153 | 165 |
154 // Called to begin reading from the cache. Returns network error code. | 166 // Called to begin reading from the cache. Returns network error code. |
155 int BeginCacheRead(); | 167 int BeginCacheRead(); |
156 | 168 |
157 // Called to begin validating the cache entry. Returns network error code. | 169 // Called to begin validating the cache entry. Returns network error code. |
158 int BeginCacheValidation(); | 170 int BeginCacheValidation(); |
159 | 171 |
160 // Called to begin validating an entry that stores partial content. Returns | 172 // Called to begin validating an entry that stores partial content. Returns |
161 // a network error code. | 173 // a network error code. |
162 int BeginPartialCacheValidation(); | 174 int BeginPartialCacheValidation(); |
163 | 175 |
164 // Validates the entry headers against the requested range and continues with | 176 // Validates the entry headers against the requested range and continues with |
165 // the validation of the rest of the entry. Returns a network error code. | 177 // the validation of the rest of the entry. Returns a network error code. |
166 int ValidateEntryHeadersAndContinue(bool byte_range_requested); | 178 int ValidateEntryHeadersAndContinue(bool byte_range_requested); |
167 | 179 |
168 // Performs the cache validation for the next chunk of data stored by the | |
169 // cache. If this chunk is not currently stored, starts the network request | |
170 // to fetch it. Returns a network error code. | |
171 int ContinuePartialCacheValidation(); | |
172 | |
173 // Called to start requests which were given an "if-modified-since" or | 180 // Called to start requests which were given an "if-modified-since" or |
174 // "if-none-match" validation header by the caller (NOT when the request was | 181 // "if-none-match" validation header by the caller (NOT when the request was |
175 // conditionalized internally in response to LOAD_VALIDATE_CACHE). | 182 // conditionalized internally in response to LOAD_VALIDATE_CACHE). |
176 // Returns a network error code. | 183 // Returns a network error code. |
177 int BeginExternallyConditionalizedRequest(); | 184 int BeginExternallyConditionalizedRequest(); |
178 | 185 |
179 // Called to begin a network transaction. Returns network error code. | 186 // Called to begin a network transaction. Returns network error code. |
180 int BeginNetworkRequest(); | 187 int BeginNetworkRequest(); |
181 | 188 |
182 // Called to restart a network transaction after an error. Returns network | 189 // Called to restart a network transaction after an error. Returns network |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 265 |
259 State next_state_; | 266 State next_state_; |
260 const HttpRequestInfo* request_; | 267 const HttpRequestInfo* request_; |
261 scoped_refptr<LoadLog> load_log_; | 268 scoped_refptr<LoadLog> load_log_; |
262 scoped_ptr<HttpRequestInfo> custom_request_; | 269 scoped_ptr<HttpRequestInfo> custom_request_; |
263 // If extra_headers specified a "if-modified-since" or "if-none-match", | 270 // If extra_headers specified a "if-modified-since" or "if-none-match", |
264 // |external_validation_| contains the value of those headers. | 271 // |external_validation_| contains the value of those headers. |
265 ValidationHeaders external_validation_; | 272 ValidationHeaders external_validation_; |
266 base::WeakPtr<HttpCache> cache_; | 273 base::WeakPtr<HttpCache> cache_; |
267 HttpCache::ActiveEntry* entry_; | 274 HttpCache::ActiveEntry* entry_; |
| 275 HttpCache::ActiveEntry* new_entry_; |
268 scoped_ptr<HttpTransaction> network_trans_; | 276 scoped_ptr<HttpTransaction> network_trans_; |
269 CompletionCallback* callback_; // Consumer's callback. | 277 CompletionCallback* callback_; // Consumer's callback. |
270 HttpResponseInfo response_; | 278 HttpResponseInfo response_; |
271 HttpResponseInfo auth_response_; | 279 HttpResponseInfo auth_response_; |
272 std::string cache_key_; | 280 std::string cache_key_; |
273 Mode mode_; | 281 Mode mode_; |
274 bool reading_; // We are already reading. | 282 bool reading_; // We are already reading. |
275 bool invalid_range_; // We may bypass the cache for this request. | 283 bool invalid_range_; // We may bypass the cache for this request. |
276 bool enable_range_support_; | 284 bool enable_range_support_; |
277 bool truncated_; // We don't have all the response data. | 285 bool truncated_; // We don't have all the response data. |
278 scoped_refptr<IOBuffer> read_buf_; | 286 scoped_refptr<IOBuffer> read_buf_; |
279 int read_buf_len_; | 287 int read_buf_len_; |
280 int read_offset_; | 288 int read_offset_; |
281 int effective_load_flags_; | 289 int effective_load_flags_; |
282 scoped_ptr<PartialData> partial_; // We are dealing with range requests. | 290 scoped_ptr<PartialData> partial_; // We are dealing with range requests. |
283 uint64 final_upload_progress_; | 291 uint64 final_upload_progress_; |
284 CompletionCallbackImpl<Transaction> network_callback_; | 292 CompletionCallbackImpl<Transaction> network_callback_; |
285 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_callback_; | 293 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_callback_; |
286 }; | 294 }; |
287 | 295 |
288 } // namespace net | 296 } // namespace net |
289 | 297 |
290 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 298 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |