Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: net/http/http_cache_transaction.h

Issue 410005: Http cache: First pass to move the HttpCache::Transaction to a sate machine.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/http/http_cache_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 static const size_t kNumValidationHeaders = 2; 87 static const size_t kNumValidationHeaders = 2;
88 // Helper struct to pair a header name with its value, for 88 // Helper struct to pair a header name with its value, for
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 {
98 STATE_NONE,
99 STATE_START_REQUEST,
100 STATE_SEND_REQUEST,
101 STATE_SEND_REQUEST_COMPLETE,
102 STATE_NETWORK_READ,
103 STATE_NETWORK_READ_COMPLETE,
104 STATE_OPEN_ENTRY,
105 STATE_OPEN_ENTRY_COMPLETE,
106 STATE_CREATE_ENTRY,
107 STATE_CREATE_ENTRY_COMPLETE,
108 STATE_DOOM_ENTRY,
109 STATE_DOOM_ENTRY_COMPLETE,
110 STATE_ADD_TO_ENTRY,
111 STATE_ADD_TO_ENTRY_COMPLETE,
112 STATE_ENTRY_AVAILABLE,
113 STATE_CACHE_READ_RESPONSE,
114 STATE_CACHE_READ_RESPONSE_COMPLETE,
115 STATE_CACHE_WRITE_RESPONSE,
116 STATE_CACHE_WRITE_RESPONSE_COMPLETE,
117 STATE_CACHE_QUERY_DATA,
118 STATE_CACHE_QUERY_DATA_COMPLETE,
119 STATE_CACHE_READ_DATA,
120 STATE_CACHE_READ_DATA_COMPLETE,
121 STATE_CACHE_WRITE_DATA,
122 STATE_CACHE_WRITE_DATA_COMPLETE
123 };
124
97 // 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
98 // only be called if callback_ is non-null. 126 // only be called if callback_ is non-null.
99 void DoCallback(int rv); 127 void DoCallback(int rv);
100 128
101 // This will trigger the completion callback if appropriate. 129 // This will trigger the completion callback if appropriate.
102 int HandleResult(int rv); 130 int HandleResult(int rv);
103 131
132 // Runs the state transition loop.
133 int DoLoop(int result);
134
135 // Each of these methods corresponds to a State value.
136 int DoSendRequest();
137 int DoSendRequestComplete(int result);
138 int DoNetworkRead();
139 int DoNetworkReadComplete(int result);
140 int DoCacheReadData();
141 int DoCacheReadDataComplete(int result);
142 int DoCacheQueryData();
143 int DoCacheQueryDataComplete(int result);
144 int DoCacheWriteData(int num_bytes);
145 int DoCacheWriteDataComplete(int result);
146
104 // Sets request_ and fields derived from it. 147 // Sets request_ and fields derived from it.
105 void SetRequest(LoadLog* load_log, const HttpRequestInfo* request); 148 void SetRequest(LoadLog* load_log, const HttpRequestInfo* request);
106 149
107 // Returns true if the request should be handled exclusively by the network 150 // Returns true if the request should be handled exclusively by the network
108 // layer (skipping the cache entirely). 151 // layer (skipping the cache entirely).
109 bool ShouldPassThrough(); 152 bool ShouldPassThrough();
110 153
111 // Called to begin reading from the cache. Returns network error code. 154 // Called to begin reading from the cache. Returns network error code.
112 int BeginCacheRead(); 155 int BeginCacheRead();
113 156
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Called to truncate response content in the entry. 235 // Called to truncate response content in the entry.
193 void TruncateResponseData(); 236 void TruncateResponseData();
194 237
195 // Called when we are done writing to the cache entry. 238 // Called when we are done writing to the cache entry.
196 void DoneWritingToEntry(bool success); 239 void DoneWritingToEntry(bool success);
197 240
198 // Deletes the current partial cache entry (sparse), and optionally removes 241 // Deletes the current partial cache entry (sparse), and optionally removes
199 // the control object (partial_). 242 // the control object (partial_).
200 void DoomPartialEntry(bool delete_object); 243 void DoomPartialEntry(bool delete_object);
201 244
202 // Performs the needed work after receiving data from the network.
203 int DoNetworkReadCompleted(int result);
204
205 // Performs the needed work after receiving data from the network, when 245 // Performs the needed work after receiving data from the network, when
206 // working with range requests. 246 // working with range requests.
207 int DoPartialNetworkReadCompleted(int result); 247 int DoPartialNetworkReadCompleted(int result);
208 248
209 // Performs the needed work after receiving data from the cache.
210 int DoCacheReadCompleted(int result);
211
212 // Performs the needed work after receiving data from the cache, when 249 // Performs the needed work after receiving data from the cache, when
213 // working with range requests. 250 // working with range requests.
214 int DoPartialCacheReadCompleted(int result); 251 int DoPartialCacheReadCompleted(int result);
215 252
216 // Performs the needed work after writing data to the cache. 253 // Performs the needed work after writing data to the cache.
217 int DoCacheWriteCompleted(int result); 254 int DoCacheWriteCompleted(int result);
218 255
219 // Called to signal completion of the network transaction's Start method: 256 // Called to signal completion of asynchronous IO.
220 void OnNetworkInfoAvailable(int result); 257 void OnIOComplete(int result);
221 258
222 // Called to signal completion of the network transaction's Read method: 259 State next_state_;
223 void OnNetworkReadCompleted(int result); 260 const HttpRequestInfo* request_;
224
225 // Called to signal completion of the cache's ReadData method:
226 void OnCacheReadCompleted(int result);
227
228 // Called to signal completion of the cache's WriteData method:
229 void OnCacheWriteCompleted(int result);
230
231 // Called to signal completion of the cache entry's ReadyForSparseIO method:
232 void OnCacheEntryReady(int result);
233
234 scoped_refptr<LoadLog> load_log_; 261 scoped_refptr<LoadLog> load_log_;
235 const HttpRequestInfo* request_;
236 scoped_ptr<HttpRequestInfo> custom_request_; 262 scoped_ptr<HttpRequestInfo> custom_request_;
237 // If extra_headers specified a "if-modified-since" or "if-none-match", 263 // If extra_headers specified a "if-modified-since" or "if-none-match",
238 // |external_validation_| contains the value of those headers. 264 // |external_validation_| contains the value of those headers.
239 ValidationHeaders external_validation_; 265 ValidationHeaders external_validation_;
240 base::WeakPtr<HttpCache> cache_; 266 base::WeakPtr<HttpCache> cache_;
241 HttpCache::ActiveEntry* entry_; 267 HttpCache::ActiveEntry* entry_;
242 scoped_ptr<HttpTransaction> network_trans_; 268 scoped_ptr<HttpTransaction> network_trans_;
243 CompletionCallback* callback_; // Consumer's callback. 269 CompletionCallback* callback_; // Consumer's callback.
244 HttpResponseInfo response_; 270 HttpResponseInfo response_;
245 HttpResponseInfo auth_response_; 271 HttpResponseInfo auth_response_;
246 std::string cache_key_; 272 std::string cache_key_;
247 Mode mode_; 273 Mode mode_;
248 bool reading_; // We are already reading. 274 bool reading_; // We are already reading.
249 bool invalid_range_; // We may bypass the cache for this request. 275 bool invalid_range_; // We may bypass the cache for this request.
250 bool enable_range_support_; 276 bool enable_range_support_;
251 bool truncated_; // We don't have all the response data. 277 bool truncated_; // We don't have all the response data.
252 scoped_refptr<IOBuffer> read_buf_; 278 scoped_refptr<IOBuffer> read_buf_;
253 int read_buf_len_; 279 int read_buf_len_;
254 int read_offset_; 280 int read_offset_;
255 int effective_load_flags_; 281 int effective_load_flags_;
256 scoped_ptr<PartialData> partial_; // We are dealing with range requests. 282 scoped_ptr<PartialData> partial_; // We are dealing with range requests.
257 uint64 final_upload_progress_; 283 uint64 final_upload_progress_;
258 CompletionCallbackImpl<Transaction> network_info_callback_; 284 CompletionCallbackImpl<Transaction> network_callback_;
259 CompletionCallbackImpl<Transaction> network_read_callback_; 285 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_callback_;
260 scoped_refptr<CancelableCompletionCallback<Transaction> >
261 cache_read_callback_;
262 scoped_refptr<CancelableCompletionCallback<Transaction> >
263 cache_write_callback_;
264 scoped_refptr<CancelableCompletionCallback<Transaction> >
265 entry_ready_callback_;
266 }; 286 };
267 287
268 } // namespace net 288 } // namespace net
269 289
270 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 290 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/http_cache_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698