diff options
-rw-r--r-- | net/http/disk_cache_based_ssl_host_info.cc | 26 | ||||
-rw-r--r-- | net/http/disk_cache_based_ssl_host_info.h | 13 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 42 | ||||
-rw-r--r-- | net/socket/ssl_host_info.h | 3 |
4 files changed, 66 insertions, 18 deletions
diff --git a/net/http/disk_cache_based_ssl_host_info.cc b/net/http/disk_cache_based_ssl_host_info.cc index 2b509ca..55f471d5 100644 --- a/net/http/disk_cache_based_ssl_host_info.cc +++ b/net/http/disk_cache_based_ssl_host_info.cc @@ -41,7 +41,7 @@ DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo( : SSLHostInfo(hostname, ssl_config, cert_verifier), weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(), - &DiskCacheBasedSSLHostInfo::DoLoop)), + &DiskCacheBasedSSLHostInfo::OnIOComplete)), state_(GET_BACKEND), ready_(false), hostname_(hostname), @@ -98,7 +98,17 @@ std::string DiskCacheBasedSSLHostInfo::key() const { return "sslhostinfo:" + hostname_; } -void DiskCacheBasedSSLHostInfo::DoLoop(int rv) { +void DiskCacheBasedSSLHostInfo::OnIOComplete(int rv) { + rv = DoLoop(rv); + if (rv != ERR_IO_PENDING) { + CompletionCallback* callback = user_callback_; + user_callback_ = NULL; + if (callback) + callback->Run(rv); + } +} + +int DiskCacheBasedSSLHostInfo::DoLoop(int rv) { do { switch (state_) { case GET_BACKEND: @@ -142,6 +152,8 @@ void DiskCacheBasedSSLHostInfo::DoLoop(int rv) { NOTREACHED(); } } while (rv != ERR_IO_PENDING && state_ != NONE); + + return rv; } int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { @@ -167,7 +179,7 @@ int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) { if (rv > 0) - data_ = std::string(read_buffer_->data(), rv); + data_.assign(read_buffer_->data(), rv); state_ = WAIT_FOR_DATA_READY_DONE; return OK; @@ -227,23 +239,15 @@ int DiskCacheBasedSSLHostInfo::DoCreate() { } int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() { - CompletionCallback* callback; - DCHECK(!ready_); state_ = NONE; ready_ = true; - callback = user_callback_; - user_callback_ = NULL; // We close the entry because, if we shutdown before ::Persist is called, // then we might leak a cache reference, which causes a DCHECK on shutdown. if (entry_) entry_->Close(); entry_ = NULL; Parse(data_); - - if (callback) - callback->Run(OK); - return OK; } diff --git a/net/http/disk_cache_based_ssl_host_info.h b/net/http/disk_cache_based_ssl_host_info.h index c28d403..56a1f5bb 100644 --- a/net/http/disk_cache_based_ssl_host_info.h +++ b/net/http/disk_cache_based_ssl_host_info.h @@ -23,8 +23,9 @@ struct SSLConfig; // DiskCacheBasedSSLHostInfo fetches information about an SSL host from our // standard disk cache. Since the information is defined to be non-sensitive, // it's ok for us to keep it on disk. -class DiskCacheBasedSSLHostInfo : public SSLHostInfo, - public base::NonThreadSafe { +class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo + : public SSLHostInfo, + public NON_EXPORTED_BASE(base::NonThreadSafe) { public: DiskCacheBasedSSLHostInfo(const std::string& hostname, const SSLConfig& ssl_config, @@ -79,7 +80,9 @@ class DiskCacheBasedSSLHostInfo : public SSLHostInfo, std::string key() const; - void DoLoop(int rv); + void OnIOComplete(int rv); + + int DoLoop(int rv); int DoGetBackendComplete(int rv); int DoOpenComplete(int rv); @@ -112,8 +115,8 @@ class DiskCacheBasedSSLHostInfo : public SSLHostInfo, disk_cache::Backend* backend_; disk_cache::Entry* entry_; CompletionCallback* user_callback_; - scoped_refptr<net::IOBuffer> read_buffer_; - scoped_refptr<net::IOBuffer> write_buffer_; + scoped_refptr<IOBuffer> read_buffer_; + scoped_refptr<IOBuffer> write_buffer_; std::string data_; }; diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index dceabf8..6ea1be2 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -16,7 +16,9 @@ #include "net/base/net_errors.h" #include "net/base/net_log_unittest.h" #include "net/base/ssl_cert_request_info.h" +#include "net/base/ssl_config_service.h" #include "net/disk_cache/disk_cache.h" +#include "net/http/disk_cache_based_ssl_host_info.h" #include "net/http/http_byte_range.h" #include "net/http/http_request_headers.h" #include "net/http/http_request_info.h" @@ -1038,7 +1040,7 @@ struct Context { //----------------------------------------------------------------------------- -// tests +// HttpCache tests TEST(HttpCache, CreateThenDestroy) { MockHttpCache cache; @@ -5180,3 +5182,41 @@ TEST(HttpCache, TruncatedByContentLength2) { EXPECT_TRUE(truncated); entry->Close(); } + +//----------------------------------------------------------------------------- +// DiskCacheBasedSSLHostInfo tests + +class DeleteSSLHostInfoCompletionCallback : public TestCompletionCallback { + public: + explicit DeleteSSLHostInfoCompletionCallback(net::SSLHostInfo* ssl_host_info) + : ssl_host_info_(ssl_host_info) {} + + virtual void RunWithParams(const Tuple1<int>& params) { + delete ssl_host_info_; + TestCompletionCallback::RunWithParams(params); + } + + private: + net::SSLHostInfo* ssl_host_info_; +}; + +// Tests that we can delete a DiskCacheBasedSSLHostInfo object in a +// completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady. +TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { + net::CertVerifier cert_verifier; + // Use the blocking mock backend factory to force asynchronous completion + // of ssl_host_info->WaitForDataReady(), so that the callback will run. + MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); + MockHttpCache cache(factory); + net::SSLConfig ssl_config; + net::SSLHostInfo* ssl_host_info = + new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, + &cert_verifier, cache.http_cache()); + ssl_host_info->Start(); + DeleteSSLHostInfoCompletionCallback callback(ssl_host_info); + int rv = ssl_host_info->WaitForDataReady(&callback); + EXPECT_EQ(net::ERR_IO_PENDING, rv); + // Now complete the backend creation and let the callback run. + factory->FinishCreation(); + EXPECT_EQ(net::OK, callback.GetResult(rv)); +} diff --git a/net/socket/ssl_host_info.h b/net/socket/ssl_host_info.h index 1387071..6441e60e 100644 --- a/net/socket/ssl_host_info.h +++ b/net/socket/ssl_host_info.h @@ -15,6 +15,7 @@ #include "net/base/cert_verify_result.h" #include "net/base/completion_callback.h" #include "net/base/dnsrr_resolver.h" +#include "net/base/net_export.h" #include "net/socket/ssl_client_socket.h" namespace net { @@ -26,7 +27,7 @@ struct SSLConfig; // This information may be stored on disk so does not include keys or session // information etc. Primarily it's intended for caching the server's // certificates. -class SSLHostInfo { +class NET_EXPORT_PRIVATE SSLHostInfo { public: SSLHostInfo(const std::string& hostname, const SSLConfig& ssl_config, |