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

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

Issue 10907241: Revert 156846 - Http Cache: Add code for simulating an infinite HTTP cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months 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 | « net/http/http_cache_transaction.h ('k') | net/http/infinite_cache.h » ('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) 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 #include "net/http/http_cache_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return true; 107 return true;
108 } 108 }
109 } 109 }
110 return false; 110 return false;
111 } 111 }
112 112
113 //----------------------------------------------------------------------------- 113 //-----------------------------------------------------------------------------
114 114
115 HttpCache::Transaction::Transaction( 115 HttpCache::Transaction::Transaction(
116 HttpCache* cache, 116 HttpCache* cache,
117 HttpTransactionDelegate* transaction_delegate, 117 HttpTransactionDelegate* transaction_delegate)
118 InfiniteCacheTransaction* infinite_cache_transaction)
119 : next_state_(STATE_NONE), 118 : next_state_(STATE_NONE),
120 request_(NULL), 119 request_(NULL),
121 cache_(cache->AsWeakPtr()), 120 cache_(cache->AsWeakPtr()),
122 entry_(NULL), 121 entry_(NULL),
123 new_entry_(NULL), 122 new_entry_(NULL),
124 network_trans_(NULL), 123 network_trans_(NULL),
125 infinite_cache_transaction_(infinite_cache_transaction),
126 new_response_(NULL), 124 new_response_(NULL),
127 mode_(NONE), 125 mode_(NONE),
128 target_state_(STATE_NONE), 126 target_state_(STATE_NONE),
129 reading_(false), 127 reading_(false),
130 invalid_range_(false), 128 invalid_range_(false),
131 truncated_(false), 129 truncated_(false),
132 is_sparse_(false), 130 is_sparse_(false),
133 range_requested_(false), 131 range_requested_(false),
134 handling_206_(false), 132 handling_206_(false),
135 cache_pending_(false), 133 cache_pending_(false),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (partial_.get() && !truncated_) 204 if (partial_.get() && !truncated_)
207 return true; 205 return true;
208 206
209 if (!CanResume(true)) 207 if (!CanResume(true))
210 return false; 208 return false;
211 209
212 // We may have received the whole resource already. 210 // We may have received the whole resource already.
213 if (done_reading_) 211 if (done_reading_)
214 return true; 212 return true;
215 213
216 if (infinite_cache_transaction_.get())
217 infinite_cache_transaction_->OnTruncatedResponse();
218
219 truncated_ = true; 214 truncated_ = true;
220 target_state_ = STATE_NONE; 215 target_state_ = STATE_NONE;
221 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE; 216 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE;
222 DoLoop(OK); 217 DoLoop(OK);
223 return true; 218 return true;
224 } 219 }
225 220
226 LoadState HttpCache::Transaction::GetWriterLoadState() const { 221 LoadState HttpCache::Transaction::GetWriterLoadState() const {
227 if (network_trans_.get()) 222 if (network_trans_.get())
228 return network_trans_->GetLoadState(); 223 return network_trans_->GetLoadState();
(...skipping 15 matching lines...) Expand all
244 // Ensure that we only have one asynchronous call at a time. 239 // Ensure that we only have one asynchronous call at a time.
245 DCHECK(callback_.is_null()); 240 DCHECK(callback_.is_null());
246 DCHECK(!reading_); 241 DCHECK(!reading_);
247 DCHECK(!network_trans_.get()); 242 DCHECK(!network_trans_.get());
248 DCHECK(!entry_); 243 DCHECK(!entry_);
249 244
250 if (!cache_) 245 if (!cache_)
251 return ERR_UNEXPECTED; 246 return ERR_UNEXPECTED;
252 247
253 SetRequest(net_log, request); 248 SetRequest(net_log, request);
254 if (infinite_cache_transaction_.get()) {
255 if ((effective_load_flags_ & LOAD_BYPASS_CACHE) ||
256 (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) ||
257 (effective_load_flags_ & LOAD_DISABLE_CACHE) ||
258 (effective_load_flags_ & LOAD_VALIDATE_CACHE) ||
259 (effective_load_flags_ & LOAD_PREFERRING_CACHE) ||
260 partial_.get()) {
261 infinite_cache_transaction_.reset();
262 } else {
263 infinite_cache_transaction_->OnRequestStart(request);
264 }
265 }
266 249
267 // We have to wait until the backend is initialized so we start the SM. 250 // We have to wait until the backend is initialized so we start the SM.
268 next_state_ = STATE_GET_BACKEND; 251 next_state_ = STATE_GET_BACKEND;
269 int rv = DoLoop(OK); 252 int rv = DoLoop(OK);
270 253
271 // Setting this here allows us to check for the existence of a callback_ to 254 // Setting this here allows us to check for the existence of a callback_ to
272 // determine if we are still inside Start. 255 // determine if we are still inside Start.
273 if (rv == ERR_IO_PENDING) 256 if (rv == ERR_IO_PENDING)
274 callback_ = callback; 257 callback_ = callback;
275 258
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 DCHECK(response); 777 DCHECK(response);
795 response_.cert_request_info = response->cert_request_info; 778 response_.cert_request_info = response->cert_request_info;
796 } 779 }
797 return result; 780 return result;
798 } 781 }
799 782
800 // We received the response headers and there is no error. 783 // We received the response headers and there is no error.
801 int HttpCache::Transaction::DoSuccessfulSendRequest() { 784 int HttpCache::Transaction::DoSuccessfulSendRequest() {
802 DCHECK(!new_response_); 785 DCHECK(!new_response_);
803 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); 786 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo();
804 if (infinite_cache_transaction_.get())
805 infinite_cache_transaction_->OnResponseReceived(new_response);
806
807 if (new_response->headers->response_code() == 401 || 787 if (new_response->headers->response_code() == 401 ||
808 new_response->headers->response_code() == 407) { 788 new_response->headers->response_code() == 407) {
809 auth_response_ = *new_response; 789 auth_response_ = *new_response;
810 return OK; 790 return OK;
811 } 791 }
812 792
813 new_response_ = new_response; 793 new_response_ = new_response;
814 if (!ValidatePartialResponse() && !auth_response_.headers) { 794 if (!ValidatePartialResponse() && !auth_response_.headers) {
815 // Something went wrong with this request and we have to restart it. 795 // Something went wrong with this request and we have to restart it.
816 // If we have an authentication response, we are exposed to weird things 796 // If we have an authentication response, we are exposed to weird things
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 DCHECK(mode_ & WRITE || mode_ == NONE); 853 DCHECK(mode_ & WRITE || mode_ == NONE);
874 854
875 ReportNetworkActionFinish(); 855 ReportNetworkActionFinish();
876 856
877 if (!cache_) 857 if (!cache_)
878 return ERR_UNEXPECTED; 858 return ERR_UNEXPECTED;
879 859
880 if (result > 0) 860 if (result > 0)
881 bytes_read_from_network_ += result; 861 bytes_read_from_network_ += result;
882 862
883 if (infinite_cache_transaction_.get())
884 infinite_cache_transaction_->OnDataRead(read_buf_->data(), result);
885
886 // If there is an error or we aren't saving the data, we are done; just wait 863 // If there is an error or we aren't saving the data, we are done; just wait
887 // until the destructor runs to see if we can keep the data. 864 // until the destructor runs to see if we can keep the data.
888 if (mode_ == NONE || result < 0) 865 if (mode_ == NONE || result < 0)
889 return result; 866 return result;
890 867
891 next_state_ = STATE_CACHE_WRITE_DATA; 868 next_state_ = STATE_CACHE_WRITE_DATA;
892 return result; 869 return result;
893 } 870 }
894 871
895 int HttpCache::Transaction::DoInitEntry() { 872 int HttpCache::Transaction::DoInitEntry() {
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 if (!cache_) 1388 if (!cache_)
1412 return ERR_UNEXPECTED; 1389 return ERR_UNEXPECTED;
1413 1390
1414 return ValidateEntryHeadersAndContinue(); 1391 return ValidateEntryHeadersAndContinue();
1415 } 1392 }
1416 1393
1417 int HttpCache::Transaction::DoCacheReadData() { 1394 int HttpCache::Transaction::DoCacheReadData() {
1418 DCHECK(entry_); 1395 DCHECK(entry_);
1419 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; 1396 next_state_ = STATE_CACHE_READ_DATA_COMPLETE;
1420 1397
1421 if (infinite_cache_transaction_.get())
1422 infinite_cache_transaction_->OnServedFromCache();
1423
1424 if (net_log_.IsLoggingAllEvents()) 1398 if (net_log_.IsLoggingAllEvents())
1425 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); 1399 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA);
1426 ReportCacheActionStart(); 1400 ReportCacheActionStart();
1427 if (partial_.get()) { 1401 if (partial_.get()) {
1428 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, 1402 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_,
1429 io_callback_); 1403 io_callback_);
1430 } 1404 }
1431 1405
1432 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, 1406 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_,
1433 read_buf_, io_buf_len_, io_callback_); 1407 read_buf_, io_buf_len_, io_callback_);
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 before_send_percent); 2378 before_send_percent);
2405 } 2379 }
2406 break; 2380 break;
2407 } 2381 }
2408 default: 2382 default:
2409 NOTREACHED(); 2383 NOTREACHED();
2410 } 2384 }
2411 } 2385 }
2412 2386
2413 } // namespace net 2387 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.h ('k') | net/http/infinite_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698