| 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 #include "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 | 10 |
| 11 #if defined(OS_POSIX) | 11 #if defined(OS_POSIX) |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/pickle.h" | 16 #include "base/pickle.h" |
| 17 #include "base/ref_counted.h" | 17 #include "base/ref_counted.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/time.h" | 19 #include "base/time.h" |
| 20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/base/ssl_cert_request_info.h" |
| 23 #include "net/disk_cache/disk_cache.h" | 24 #include "net/disk_cache/disk_cache.h" |
| 24 #include "net/http/http_network_layer.h" | 25 #include "net/http/http_network_layer.h" |
| 25 #include "net/http/http_network_session.h" | 26 #include "net/http/http_network_session.h" |
| 26 #include "net/http/http_request_info.h" | 27 #include "net/http/http_request_info.h" |
| 27 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 28 #include "net/http/http_response_info.h" | 29 #include "net/http/http_response_info.h" |
| 29 #include "net/http/http_transaction.h" | 30 #include "net/http/http_transaction.h" |
| 30 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
| 31 #include "net/http/partial_data.h" | 32 #include "net/http/partial_data.h" |
| 32 | 33 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 cache_read_callback_(new CancelableCompletionCallback<Transaction>( | 160 cache_read_callback_(new CancelableCompletionCallback<Transaction>( |
| 160 this, &Transaction::OnCacheReadCompleted))) { | 161 this, &Transaction::OnCacheReadCompleted))) { |
| 161 } | 162 } |
| 162 | 163 |
| 163 // Clean up the transaction. | 164 // Clean up the transaction. |
| 164 virtual ~Transaction(); | 165 virtual ~Transaction(); |
| 165 | 166 |
| 166 // HttpTransaction methods: | 167 // HttpTransaction methods: |
| 167 virtual int Start(const HttpRequestInfo*, CompletionCallback*); | 168 virtual int Start(const HttpRequestInfo*, CompletionCallback*); |
| 168 virtual int RestartIgnoringLastError(CompletionCallback*); | 169 virtual int RestartIgnoringLastError(CompletionCallback*); |
| 170 virtual int RestartWithCertificate(X509Certificate* client_cert, |
| 171 CompletionCallback* callback); |
| 169 virtual int RestartWithAuth(const std::wstring& username, | 172 virtual int RestartWithAuth(const std::wstring& username, |
| 170 const std::wstring& password, | 173 const std::wstring& password, |
| 171 CompletionCallback* callback); | 174 CompletionCallback* callback); |
| 172 virtual bool IsReadyToRestartForAuth(); | 175 virtual bool IsReadyToRestartForAuth(); |
| 173 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback*); | 176 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback*); |
| 174 virtual const HttpResponseInfo* GetResponseInfo() const; | 177 virtual const HttpResponseInfo* GetResponseInfo() const; |
| 175 virtual LoadState GetLoadState() const; | 178 virtual LoadState GetLoadState() const; |
| 176 virtual uint64 GetUploadProgress(void) const; | 179 virtual uint64 GetUploadProgress(void) const; |
| 177 | 180 |
| 178 // The transaction has the following modes, which apply to how it may access | 181 // The transaction has the following modes, which apply to how it may access |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // to fetch it. Returns a network error code. | 245 // to fetch it. Returns a network error code. |
| 243 int ContinuePartialCacheValidation(); | 246 int ContinuePartialCacheValidation(); |
| 244 | 247 |
| 245 // Called to begin a network transaction. Returns network error code. | 248 // Called to begin a network transaction. Returns network error code. |
| 246 int BeginNetworkRequest(); | 249 int BeginNetworkRequest(); |
| 247 | 250 |
| 248 // Called to restart a network transaction after an error. Returns network | 251 // Called to restart a network transaction after an error. Returns network |
| 249 // error code. | 252 // error code. |
| 250 int RestartNetworkRequest(); | 253 int RestartNetworkRequest(); |
| 251 | 254 |
| 255 // Called to restart a network transaction with a client certificate. |
| 256 // Returns network error code. |
| 257 int RestartNetworkRequestWithCertificate(X509Certificate* client_cert); |
| 258 |
| 252 // Called to restart a network transaction with authentication credentials. | 259 // Called to restart a network transaction with authentication credentials. |
| 253 // Returns network error code. | 260 // Returns network error code. |
| 254 int RestartNetworkRequestWithAuth(const std::wstring& username, | 261 int RestartNetworkRequestWithAuth(const std::wstring& username, |
| 255 const std::wstring& password); | 262 const std::wstring& password); |
| 256 | 263 |
| 257 // Called to determine if we need to validate the cache entry before using it. | 264 // Called to determine if we need to validate the cache entry before using it. |
| 258 bool RequiresValidation(); | 265 bool RequiresValidation(); |
| 259 | 266 |
| 260 // Called to make the request conditional (to ask the server if the cached | 267 // Called to make the request conditional (to ask the server if the cached |
| 261 // copy is valid). Returns true if able to make the request conditional. | 268 // copy is valid). Returns true if able to make the request conditional. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return ERR_UNEXPECTED; | 414 return ERR_UNEXPECTED; |
| 408 | 415 |
| 409 int rv = RestartNetworkRequest(); | 416 int rv = RestartNetworkRequest(); |
| 410 | 417 |
| 411 if (rv == ERR_IO_PENDING) | 418 if (rv == ERR_IO_PENDING) |
| 412 callback_ = callback; | 419 callback_ = callback; |
| 413 | 420 |
| 414 return rv; | 421 return rv; |
| 415 } | 422 } |
| 416 | 423 |
| 424 int HttpCache::Transaction::RestartWithCertificate( |
| 425 X509Certificate* client_cert, |
| 426 CompletionCallback* callback) { |
| 427 DCHECK(callback); |
| 428 |
| 429 // ensure that we only have one asynchronous call at a time. |
| 430 DCHECK(!callback_); |
| 431 |
| 432 if (revoked()) |
| 433 return ERR_UNEXPECTED; |
| 434 |
| 435 int rv = RestartNetworkRequestWithCertificate(client_cert); |
| 436 |
| 437 if (rv == ERR_IO_PENDING) |
| 438 callback_ = callback; |
| 439 |
| 440 return rv; |
| 441 } |
| 442 |
| 417 int HttpCache::Transaction::RestartWithAuth( | 443 int HttpCache::Transaction::RestartWithAuth( |
| 418 const std::wstring& username, | 444 const std::wstring& username, |
| 419 const std::wstring& password, | 445 const std::wstring& password, |
| 420 CompletionCallback* callback) { | 446 CompletionCallback* callback) { |
| 421 DCHECK(auth_response_.headers); | 447 DCHECK(auth_response_.headers); |
| 422 DCHECK(callback); | 448 DCHECK(callback); |
| 423 | 449 |
| 424 // Ensure that we only have one asynchronous call at a time. | 450 // Ensure that we only have one asynchronous call at a time. |
| 425 DCHECK(!callback_); | 451 DCHECK(!callback_); |
| 426 | 452 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 DCHECK(!callback_); | 518 DCHECK(!callback_); |
| 493 callback_ = callback; | 519 callback_ = callback; |
| 494 } | 520 } |
| 495 return rv; | 521 return rv; |
| 496 } | 522 } |
| 497 | 523 |
| 498 const HttpResponseInfo* HttpCache::Transaction::GetResponseInfo() const { | 524 const HttpResponseInfo* HttpCache::Transaction::GetResponseInfo() const { |
| 499 // Null headers means we encountered an error or haven't a response yet | 525 // Null headers means we encountered an error or haven't a response yet |
| 500 if (auth_response_.headers) | 526 if (auth_response_.headers) |
| 501 return &auth_response_; | 527 return &auth_response_; |
| 502 return (response_.headers || response_.ssl_info.cert) ? &response_ : NULL; | 528 return (response_.headers || response_.ssl_info.cert || |
| 529 response_.cert_request_info) ? &response_ : NULL; |
| 503 } | 530 } |
| 504 | 531 |
| 505 LoadState HttpCache::Transaction::GetLoadState() const { | 532 LoadState HttpCache::Transaction::GetLoadState() const { |
| 506 if (network_trans_.get()) | 533 if (network_trans_.get()) |
| 507 return network_trans_->GetLoadState(); | 534 return network_trans_->GetLoadState(); |
| 508 if (entry_ || !request_) | 535 if (entry_ || !request_) |
| 509 return LOAD_STATE_IDLE; | 536 return LOAD_STATE_IDLE; |
| 510 return LOAD_STATE_WAITING_FOR_CACHE; | 537 return LOAD_STATE_WAITING_FOR_CACHE; |
| 511 } | 538 } |
| 512 | 539 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 int HttpCache::Transaction::RestartNetworkRequest() { | 825 int HttpCache::Transaction::RestartNetworkRequest() { |
| 799 DCHECK(mode_ & WRITE || mode_ == NONE); | 826 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 800 DCHECK(network_trans_.get()); | 827 DCHECK(network_trans_.get()); |
| 801 | 828 |
| 802 int rv = network_trans_->RestartIgnoringLastError(&network_info_callback_); | 829 int rv = network_trans_->RestartIgnoringLastError(&network_info_callback_); |
| 803 if (rv != ERR_IO_PENDING) | 830 if (rv != ERR_IO_PENDING) |
| 804 OnNetworkInfoAvailable(rv); | 831 OnNetworkInfoAvailable(rv); |
| 805 return rv; | 832 return rv; |
| 806 } | 833 } |
| 807 | 834 |
| 835 int HttpCache::Transaction::RestartNetworkRequestWithCertificate( |
| 836 X509Certificate* client_cert) { |
| 837 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 838 DCHECK(network_trans_.get()); |
| 839 |
| 840 int rv = network_trans_->RestartWithCertificate(client_cert, |
| 841 &network_info_callback_); |
| 842 if (rv != ERR_IO_PENDING) |
| 843 OnNetworkInfoAvailable(rv); |
| 844 return rv; |
| 845 } |
| 846 |
| 808 int HttpCache::Transaction::RestartNetworkRequestWithAuth( | 847 int HttpCache::Transaction::RestartNetworkRequestWithAuth( |
| 809 const std::wstring& username, | 848 const std::wstring& username, |
| 810 const std::wstring& password) { | 849 const std::wstring& password) { |
| 811 DCHECK(mode_ & WRITE || mode_ == NONE); | 850 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 812 DCHECK(network_trans_.get()); | 851 DCHECK(network_trans_.get()); |
| 813 | 852 |
| 814 int rv = network_trans_->RestartWithAuth(username, password, | 853 int rv = network_trans_->RestartWithAuth(username, password, |
| 815 &network_info_callback_); | 854 &network_info_callback_); |
| 816 if (rv != ERR_IO_PENDING) | 855 if (rv != ERR_IO_PENDING) |
| 817 OnNetworkInfoAvailable(rv); | 856 OnNetworkInfoAvailable(rv); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 if (result >= 0 || result == net::ERR_IO_PENDING) | 1124 if (result >= 0 || result == net::ERR_IO_PENDING) |
| 1086 return; | 1125 return; |
| 1087 } | 1126 } |
| 1088 } | 1127 } |
| 1089 } else if (IsCertificateError(result)) { | 1128 } else if (IsCertificateError(result)) { |
| 1090 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); | 1129 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); |
| 1091 // If we get a certificate error, then there is a certificate in ssl_info, | 1130 // If we get a certificate error, then there is a certificate in ssl_info, |
| 1092 // so GetResponseInfo() should never returns NULL here. | 1131 // so GetResponseInfo() should never returns NULL here. |
| 1093 DCHECK(response); | 1132 DCHECK(response); |
| 1094 response_.ssl_info = response->ssl_info; | 1133 response_.ssl_info = response->ssl_info; |
| 1134 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 1135 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); |
| 1136 DCHECK(response); |
| 1137 response_.cert_request_info = response->cert_request_info; |
| 1095 } | 1138 } |
| 1096 HandleResult(result); | 1139 HandleResult(result); |
| 1097 } | 1140 } |
| 1098 | 1141 |
| 1099 void HttpCache::Transaction::OnNetworkReadCompleted(int result) { | 1142 void HttpCache::Transaction::OnNetworkReadCompleted(int result) { |
| 1100 DoNetworkReadCompleted(result); | 1143 DoNetworkReadCompleted(result); |
| 1101 } | 1144 } |
| 1102 | 1145 |
| 1103 int HttpCache::Transaction::DoNetworkReadCompleted(int result) { | 1146 int HttpCache::Transaction::DoNetworkReadCompleted(int result) { |
| 1104 DCHECK(mode_ & WRITE || mode_ == NONE); | 1147 DCHECK(mode_ & WRITE || mode_ == NONE); |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 1741 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
| 1699 HttpNetworkSession* session = network->GetSession(); | 1742 HttpNetworkSession* session = network->GetSession(); |
| 1700 if (session) { | 1743 if (session) { |
| 1701 session->connection_pool()->CloseIdleSockets(); | 1744 session->connection_pool()->CloseIdleSockets(); |
| 1702 } | 1745 } |
| 1703 } | 1746 } |
| 1704 | 1747 |
| 1705 //----------------------------------------------------------------------------- | 1748 //----------------------------------------------------------------------------- |
| 1706 | 1749 |
| 1707 } // namespace net | 1750 } // namespace net |
| OLD | NEW |