| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_SEND_REQUEST, | 99 STATE_SEND_REQUEST, |
| 100 STATE_SEND_REQUEST_COMPLETE, | 100 STATE_SEND_REQUEST_COMPLETE, |
| 101 STATE_SUCCESSFUL_SEND_REQUEST, |
| 101 STATE_NETWORK_READ, | 102 STATE_NETWORK_READ, |
| 102 STATE_NETWORK_READ_COMPLETE, | 103 STATE_NETWORK_READ_COMPLETE, |
| 103 STATE_INIT_ENTRY, | 104 STATE_INIT_ENTRY, |
| 104 STATE_OPEN_ENTRY, | 105 STATE_OPEN_ENTRY, |
| 105 STATE_OPEN_ENTRY_COMPLETE, | 106 STATE_OPEN_ENTRY_COMPLETE, |
| 106 STATE_CREATE_ENTRY, | 107 STATE_CREATE_ENTRY, |
| 107 STATE_CREATE_ENTRY_COMPLETE, | 108 STATE_CREATE_ENTRY_COMPLETE, |
| 108 STATE_DOOM_ENTRY, | 109 STATE_DOOM_ENTRY, |
| 109 STATE_DOOM_ENTRY_COMPLETE, | 110 STATE_DOOM_ENTRY_COMPLETE, |
| 110 STATE_ADD_TO_ENTRY, | 111 STATE_ADD_TO_ENTRY, |
| 111 STATE_ENTRY_AVAILABLE, | 112 STATE_ENTRY_AVAILABLE, |
| 112 STATE_PARTIAL_CACHE_VALIDATION, | 113 STATE_PARTIAL_CACHE_VALIDATION, |
| 114 STATE_UPDATE_CACHED_RESPONSE, |
| 115 STATE_UPDATE_CACHED_RESPONSE_COMPLETE, |
| 116 STATE_OVERWRITE_CACHED_RESPONSE, |
| 117 STATE_TRUNCATE_CACHED_DATA, |
| 118 STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
| 119 STATE_PARTIAL_HEADERS_RECEIVED, |
| 113 STATE_CACHE_READ_RESPONSE, | 120 STATE_CACHE_READ_RESPONSE, |
| 114 STATE_CACHE_READ_RESPONSE_COMPLETE, | 121 STATE_CACHE_READ_RESPONSE_COMPLETE, |
| 115 STATE_CACHE_WRITE_RESPONSE, | 122 STATE_CACHE_WRITE_RESPONSE, |
| 123 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
| 116 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 124 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
| 117 STATE_CACHE_QUERY_DATA, | 125 STATE_CACHE_QUERY_DATA, |
| 118 STATE_CACHE_QUERY_DATA_COMPLETE, | 126 STATE_CACHE_QUERY_DATA_COMPLETE, |
| 119 STATE_CACHE_READ_DATA, | 127 STATE_CACHE_READ_DATA, |
| 120 STATE_CACHE_READ_DATA_COMPLETE, | 128 STATE_CACHE_READ_DATA_COMPLETE, |
| 121 STATE_CACHE_WRITE_DATA, | 129 STATE_CACHE_WRITE_DATA, |
| 122 STATE_CACHE_WRITE_DATA_COMPLETE | 130 STATE_CACHE_WRITE_DATA_COMPLETE |
| 123 }; | 131 }; |
| 124 | 132 |
| 125 // This is a helper function used to trigger a completion callback. It may | 133 // This is a helper function used to trigger a completion callback. It may |
| 126 // only be called if callback_ is non-null. | 134 // only be called if callback_ is non-null. |
| 127 void DoCallback(int rv); | 135 void DoCallback(int rv); |
| 128 | 136 |
| 129 // This will trigger the completion callback if appropriate. | 137 // This will trigger the completion callback if appropriate. |
| 130 int HandleResult(int rv); | 138 int HandleResult(int rv); |
| 131 | 139 |
| 132 // Runs the state transition loop. | 140 // Runs the state transition loop. |
| 133 int DoLoop(int result); | 141 int DoLoop(int result); |
| 134 | 142 |
| 135 // Each of these methods corresponds to a State value. If there is an | 143 // 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 | 144 // argument, the value corresponds to the return of the previous state or |
| 137 // corresponding callback. | 145 // corresponding callback. |
| 138 int DoSendRequest(); | 146 int DoSendRequest(); |
| 139 int DoSendRequestComplete(int result); | 147 int DoSendRequestComplete(int result); |
| 148 int DoSuccessfulSendRequest(); |
| 140 int DoNetworkRead(); | 149 int DoNetworkRead(); |
| 141 int DoNetworkReadComplete(int result); | 150 int DoNetworkReadComplete(int result); |
| 142 int DoInitEntry(); | 151 int DoInitEntry(); |
| 143 int DoOpenEntry(); | 152 int DoOpenEntry(); |
| 144 int DoOpenEntryComplete(); | 153 int DoOpenEntryComplete(); |
| 145 int DoCreateEntry(); | 154 int DoCreateEntry(); |
| 146 int DoCreateEntryComplete(); | 155 int DoCreateEntryComplete(); |
| 147 int DoDoomEntry(); | 156 int DoDoomEntry(); |
| 148 int DoDoomEntryComplete(); | 157 int DoDoomEntryComplete(); |
| 149 int DoAddToEntry(); | 158 int DoAddToEntry(); |
| 150 int DoEntryAvailable(); | 159 int DoEntryAvailable(); |
| 151 int DoPartialCacheValidation(); | 160 int DoPartialCacheValidation(); |
| 161 int DoUpdateCachedResponse(); |
| 162 int DoUpdateCachedResponseComplete(int result); |
| 163 int DoOverwriteCachedResponse(); |
| 164 int DoTruncateCachedData(); |
| 165 int DoTruncateCachedDataComplete(int result); |
| 166 int DoPartialHeadersReceived(); |
| 167 int DoCacheReadResponse(); |
| 168 int DoCacheReadResponseComplete(); |
| 169 int DoCacheWriteResponse(); |
| 170 int DoCacheWriteTruncatedResponse(); |
| 171 int DoCacheWriteResponseComplete(int result); |
| 172 int DoCacheQueryData(); |
| 173 int DoCacheQueryDataComplete(int result); |
| 152 int DoCacheReadData(); | 174 int DoCacheReadData(); |
| 153 int DoCacheReadDataComplete(int result); | 175 int DoCacheReadDataComplete(int result); |
| 154 int DoCacheQueryData(); | |
| 155 int DoCacheQueryDataComplete(int result); | |
| 156 int DoCacheWriteData(int num_bytes); | 176 int DoCacheWriteData(int num_bytes); |
| 157 int DoCacheWriteDataComplete(int result); | 177 int DoCacheWriteDataComplete(int result); |
| 158 | 178 |
| 159 // Sets request_ and fields derived from it. | 179 // Sets request_ and fields derived from it. |
| 160 void SetRequest(LoadLog* load_log, const HttpRequestInfo* request); | 180 void SetRequest(LoadLog* load_log, const HttpRequestInfo* request); |
| 161 | 181 |
| 162 // Returns true if the request should be handled exclusively by the network | 182 // Returns true if the request should be handled exclusively by the network |
| 163 // layer (skipping the cache entirely). | 183 // layer (skipping the cache entirely). |
| 164 bool ShouldPassThrough(); | 184 bool ShouldPassThrough(); |
| 165 | 185 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 234 |
| 215 // Handles a response validation error by bypassing the cache. | 235 // Handles a response validation error by bypassing the cache. |
| 216 void IgnoreRangeRequest(); | 236 void IgnoreRangeRequest(); |
| 217 | 237 |
| 218 // Reads data from the network. | 238 // Reads data from the network. |
| 219 int ReadFromNetwork(IOBuffer* data, int data_len); | 239 int ReadFromNetwork(IOBuffer* data, int data_len); |
| 220 | 240 |
| 221 // Reads data from the cache entry. | 241 // Reads data from the cache entry. |
| 222 int ReadFromEntry(IOBuffer* data, int data_len); | 242 int ReadFromEntry(IOBuffer* data, int data_len); |
| 223 | 243 |
| 224 // Called to populate response_ from the cache entry. | |
| 225 int ReadResponseInfoFromEntry(); | |
| 226 | |
| 227 // Called to write data to the cache entry. If the write fails, then the | 244 // Called to write data to the cache entry. If the write fails, then the |
| 228 // cache entry is destroyed. Future calls to this function will just do | 245 // cache entry is destroyed. Future calls to this function will just do |
| 229 // nothing without side-effect. Returns a network error code. | 246 // nothing without side-effect. Returns a network error code. |
| 230 int WriteToEntry(int index, int offset, IOBuffer* data, int data_len, | 247 int WriteToEntry(int index, int offset, IOBuffer* data, int data_len, |
| 231 CompletionCallback* callback); | 248 CompletionCallback* callback); |
| 232 | 249 |
| 233 // Called to write response_ to the cache entry. |truncated| indicates if the | 250 // Called to write response_ to the cache entry. |truncated| indicates if the |
| 234 // entry should be marked as incomplete. | 251 // entry should be marked as incomplete. |
| 235 void WriteResponseInfoToEntry(bool truncated); | 252 int WriteResponseInfoToEntry(bool truncated); |
| 236 | 253 |
| 237 // Called to append response data to the cache entry. Returns a network error | 254 // Called to append response data to the cache entry. Returns a network error |
| 238 // code. | 255 // code. |
| 239 int AppendResponseDataToEntry(IOBuffer* data, int data_len, | 256 int AppendResponseDataToEntry(IOBuffer* data, int data_len, |
| 240 CompletionCallback* callback); | 257 CompletionCallback* callback); |
| 241 | 258 |
| 242 // Called to truncate response content in the entry. | |
| 243 void TruncateResponseData(); | |
| 244 | |
| 245 // Called when we are done writing to the cache entry. | 259 // Called when we are done writing to the cache entry. |
| 246 void DoneWritingToEntry(bool success); | 260 void DoneWritingToEntry(bool success); |
| 247 | 261 |
| 248 // Deletes the current partial cache entry (sparse), and optionally removes | 262 // Deletes the current partial cache entry (sparse), and optionally removes |
| 249 // the control object (partial_). | 263 // the control object (partial_). |
| 250 void DoomPartialEntry(bool delete_object); | 264 void DoomPartialEntry(bool delete_object); |
| 251 | 265 |
| 252 // Performs the needed work after receiving data from the network, when | 266 // Performs the needed work after receiving data from the network, when |
| 253 // working with range requests. | 267 // working with range requests. |
| 254 int DoPartialNetworkReadCompleted(int result); | 268 int DoPartialNetworkReadCompleted(int result); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 270 // If extra_headers specified a "if-modified-since" or "if-none-match", | 284 // If extra_headers specified a "if-modified-since" or "if-none-match", |
| 271 // |external_validation_| contains the value of those headers. | 285 // |external_validation_| contains the value of those headers. |
| 272 ValidationHeaders external_validation_; | 286 ValidationHeaders external_validation_; |
| 273 base::WeakPtr<HttpCache> cache_; | 287 base::WeakPtr<HttpCache> cache_; |
| 274 HttpCache::ActiveEntry* entry_; | 288 HttpCache::ActiveEntry* entry_; |
| 275 HttpCache::ActiveEntry* new_entry_; | 289 HttpCache::ActiveEntry* new_entry_; |
| 276 scoped_ptr<HttpTransaction> network_trans_; | 290 scoped_ptr<HttpTransaction> network_trans_; |
| 277 CompletionCallback* callback_; // Consumer's callback. | 291 CompletionCallback* callback_; // Consumer's callback. |
| 278 HttpResponseInfo response_; | 292 HttpResponseInfo response_; |
| 279 HttpResponseInfo auth_response_; | 293 HttpResponseInfo auth_response_; |
| 294 const HttpResponseInfo* new_response_; |
| 280 std::string cache_key_; | 295 std::string cache_key_; |
| 281 Mode mode_; | 296 Mode mode_; |
| 297 State target_state_; |
| 282 bool reading_; // We are already reading. | 298 bool reading_; // We are already reading. |
| 283 bool invalid_range_; // We may bypass the cache for this request. | 299 bool invalid_range_; // We may bypass the cache for this request. |
| 284 bool enable_range_support_; | 300 bool enable_range_support_; |
| 285 bool truncated_; // We don't have all the response data. | 301 bool truncated_; // We don't have all the response data. |
| 302 bool server_responded_206_; |
| 286 scoped_refptr<IOBuffer> read_buf_; | 303 scoped_refptr<IOBuffer> read_buf_; |
| 287 int read_buf_len_; | 304 int read_buf_len_; |
| 288 int read_offset_; | 305 int read_offset_; |
| 289 int effective_load_flags_; | 306 int effective_load_flags_; |
| 290 scoped_ptr<PartialData> partial_; // We are dealing with range requests. | 307 scoped_ptr<PartialData> partial_; // We are dealing with range requests. |
| 291 uint64 final_upload_progress_; | 308 uint64 final_upload_progress_; |
| 292 CompletionCallbackImpl<Transaction> network_callback_; | 309 CompletionCallbackImpl<Transaction> network_callback_; |
| 293 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_callback_; | 310 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_callback_; |
| 294 }; | 311 }; |
| 295 | 312 |
| 296 } // namespace net | 313 } // namespace net |
| 297 | 314 |
| 298 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 315 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
| OLD | NEW |