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