Commit b6693c23 authored by jhawkins@chromium.org's avatar jhawkins@chromium.org

base::Bind: Convert SSLHostInfo::WaitForDataReady.

BUG=none
TEST=none
R=csilv

Review URL: http://codereview.chromium.org/8784003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112899 0039d316-1c4b-4281-b951-d872f2087c98
parent 445e1041
...@@ -48,8 +48,7 @@ DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo( ...@@ -48,8 +48,7 @@ DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo(
hostname_(hostname), hostname_(hostname),
http_cache_(http_cache), http_cache_(http_cache),
backend_(NULL), backend_(NULL),
entry_(NULL), entry_(NULL) {
user_callback_(NULL) {
} }
void DiskCacheBasedSSLHostInfo::Start() { void DiskCacheBasedSSLHostInfo::Start() {
...@@ -58,16 +57,19 @@ void DiskCacheBasedSSLHostInfo::Start() { ...@@ -58,16 +57,19 @@ void DiskCacheBasedSSLHostInfo::Start() {
DoLoop(OK); DoLoop(OK);
} }
int DiskCacheBasedSSLHostInfo::WaitForDataReady(OldCompletionCallback* callback) { int DiskCacheBasedSSLHostInfo::WaitForDataReady(
const CompletionCallback& callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(state_ != GET_BACKEND); DCHECK(state_ != GET_BACKEND);
if (ready_) if (ready_)
return OK; return OK;
if (callback) {
DCHECK(!user_callback_); if (!callback.is_null()) {
DCHECK(user_callback_.is_null());
user_callback_ = callback; user_callback_ = callback;
} }
return ERR_IO_PENDING; return ERR_IO_PENDING;
} }
...@@ -77,7 +79,7 @@ void DiskCacheBasedSSLHostInfo::Persist() { ...@@ -77,7 +79,7 @@ void DiskCacheBasedSSLHostInfo::Persist() {
DCHECK(new_data_.empty()); DCHECK(new_data_.empty());
CHECK(ready_); CHECK(ready_);
DCHECK(user_callback_ == NULL); DCHECK(user_callback_.is_null());
new_data_ = Serialize(); new_data_ = Serialize();
if (!backend_) if (!backend_)
...@@ -88,7 +90,7 @@ void DiskCacheBasedSSLHostInfo::Persist() { ...@@ -88,7 +90,7 @@ void DiskCacheBasedSSLHostInfo::Persist() {
} }
DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() { DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() {
DCHECK(!user_callback_); DCHECK(user_callback_.is_null());
if (entry_) if (entry_)
entry_->Close(); entry_->Close();
if (!IsCallbackPending()) if (!IsCallbackPending())
...@@ -101,11 +103,10 @@ std::string DiskCacheBasedSSLHostInfo::key() const { ...@@ -101,11 +103,10 @@ std::string DiskCacheBasedSSLHostInfo::key() const {
void DiskCacheBasedSSLHostInfo::OnIOComplete(int rv) { void DiskCacheBasedSSLHostInfo::OnIOComplete(int rv) {
rv = DoLoop(rv); rv = DoLoop(rv);
if (rv != ERR_IO_PENDING) { if (rv != ERR_IO_PENDING && !user_callback_.is_null()) {
OldCompletionCallback* callback = user_callback_; CompletionCallback callback = user_callback_;
user_callback_ = NULL; user_callback_.Reset();
if (callback) callback.Run(rv);
callback->Run(rv);
} }
} }
......
...@@ -32,9 +32,9 @@ class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo ...@@ -32,9 +32,9 @@ class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo
CertVerifier* cert_verifier, CertVerifier* cert_verifier,
HttpCache* http_cache); HttpCache* http_cache);
// Implementation of SSLHostInfo // SSLHostInfo implementation.
virtual void Start() OVERRIDE; virtual void Start() OVERRIDE;
virtual int WaitForDataReady(OldCompletionCallback* callback) OVERRIDE; virtual int WaitForDataReady(const CompletionCallback& callback) OVERRIDE;
virtual void Persist() OVERRIDE; virtual void Persist() OVERRIDE;
private: private:
...@@ -115,7 +115,7 @@ class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo ...@@ -115,7 +115,7 @@ class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo
HttpCache* const http_cache_; HttpCache* const http_cache_;
disk_cache::Backend* backend_; disk_cache::Backend* backend_;
disk_cache::Entry* entry_; disk_cache::Entry* entry_;
OldCompletionCallback* user_callback_; CompletionCallback user_callback_;
scoped_refptr<IOBuffer> read_buffer_; scoped_refptr<IOBuffer> read_buffer_;
scoped_refptr<IOBuffer> write_buffer_; scoped_refptr<IOBuffer> write_buffer_;
std::string data_; std::string data_;
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/ssl_config_service.h" #include "net/base/ssl_config_service.h"
#include "net/http/disk_cache_based_ssl_host_info.h" #include "net/http/disk_cache_based_ssl_host_info.h"
...@@ -10,20 +13,6 @@ ...@@ -10,20 +13,6 @@
namespace { namespace {
class DeleteSSLHostInfoOldCompletionCallback : public TestOldCompletionCallback {
public:
explicit DeleteSSLHostInfoOldCompletionCallback(net::SSLHostInfo* ssl_host_info)
: ssl_host_info_(ssl_host_info) {}
virtual void RunWithParams(const Tuple1<int>& params) {
delete ssl_host_info_;
TestOldCompletionCallback::RunWithParams(params);
}
private:
net::SSLHostInfo* ssl_host_info_;
};
// This is an empty transaction, needed to register the URL and the test mode. // This is an empty transaction, needed to register the URL and the test mode.
const MockTransaction kHostInfoTransaction = { const MockTransaction kHostInfoTransaction = {
"sslhostinfo:https://www.google.com", "sslhostinfo:https://www.google.com",
...@@ -40,8 +29,6 @@ const MockTransaction kHostInfoTransaction = { ...@@ -40,8 +29,6 @@ const MockTransaction kHostInfoTransaction = {
0 0
}; };
} // namespace
// Tests that we can delete a DiskCacheBasedSSLHostInfo object in a // Tests that we can delete a DiskCacheBasedSSLHostInfo object in a
// completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady. // completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady.
TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
...@@ -51,12 +38,12 @@ TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { ...@@ -51,12 +38,12 @@ TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
MockHttpCache cache(factory); MockHttpCache cache(factory);
net::SSLConfig ssl_config; net::SSLConfig ssl_config;
net::SSLHostInfo* ssl_host_info = scoped_ptr<net::SSLHostInfo> ssl_host_info(
new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config,
&cert_verifier, cache.http_cache()); &cert_verifier, cache.http_cache()));
ssl_host_info->Start(); ssl_host_info->Start();
DeleteSSLHostInfoOldCompletionCallback callback(ssl_host_info); net::TestCompletionCallback callback;
int rv = ssl_host_info->WaitForDataReady(&callback); int rv = ssl_host_info->WaitForDataReady(callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv); EXPECT_EQ(net::ERR_IO_PENDING, rv);
// Now complete the backend creation and let the callback run. // Now complete the backend creation and let the callback run.
factory->FinishCreation(); factory->FinishCreation();
...@@ -67,7 +54,7 @@ TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { ...@@ -67,7 +54,7 @@ TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
TEST(DiskCacheBasedSSLHostInfo, Update) { TEST(DiskCacheBasedSSLHostInfo, Update) {
MockHttpCache cache; MockHttpCache cache;
AddMockTransaction(&kHostInfoTransaction); AddMockTransaction(&kHostInfoTransaction);
TestOldCompletionCallback callback; net::TestCompletionCallback callback;
// Store a certificate chain. // Store a certificate chain.
net::CertVerifier cert_verifier; net::CertVerifier cert_verifier;
...@@ -76,7 +63,7 @@ TEST(DiskCacheBasedSSLHostInfo, Update) { ...@@ -76,7 +63,7 @@ TEST(DiskCacheBasedSSLHostInfo, Update) {
new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config, new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
&cert_verifier, cache.http_cache())); &cert_verifier, cache.http_cache()));
ssl_host_info->Start(); ssl_host_info->Start();
int rv = ssl_host_info->WaitForDataReady(&callback); int rv = ssl_host_info->WaitForDataReady(callback.callback());
EXPECT_EQ(net::OK, callback.GetResult(rv)); EXPECT_EQ(net::OK, callback.GetResult(rv));
net::SSLHostInfo::State* state = ssl_host_info->mutable_state(); net::SSLHostInfo::State* state = ssl_host_info->mutable_state();
...@@ -92,7 +79,7 @@ TEST(DiskCacheBasedSSLHostInfo, Update) { ...@@ -92,7 +79,7 @@ TEST(DiskCacheBasedSSLHostInfo, Update) {
new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config, new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
&cert_verifier, cache.http_cache())); &cert_verifier, cache.http_cache()));
ssl_host_info->Start(); ssl_host_info->Start();
rv = ssl_host_info->WaitForDataReady(&callback); rv = ssl_host_info->WaitForDataReady(callback.callback());
EXPECT_EQ(net::OK, callback.GetResult(rv)); EXPECT_EQ(net::OK, callback.GetResult(rv));
// And now update the data. // And now update the data.
...@@ -111,7 +98,7 @@ TEST(DiskCacheBasedSSLHostInfo, Update) { ...@@ -111,7 +98,7 @@ TEST(DiskCacheBasedSSLHostInfo, Update) {
new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config, new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
&cert_verifier, cache.http_cache())); &cert_verifier, cache.http_cache()));
ssl_host_info->Start(); ssl_host_info->Start();
rv = ssl_host_info->WaitForDataReady(&callback); rv = ssl_host_info->WaitForDataReady(callback.callback());
EXPECT_EQ(net::OK, callback.GetResult(rv)); EXPECT_EQ(net::OK, callback.GetResult(rv));
state = ssl_host_info->mutable_state(); state = ssl_host_info->mutable_state();
...@@ -121,3 +108,5 @@ TEST(DiskCacheBasedSSLHostInfo, Update) { ...@@ -121,3 +108,5 @@ TEST(DiskCacheBasedSSLHostInfo, Update) {
RemoveMockTransaction(&kHostInfoTransaction); RemoveMockTransaction(&kHostInfoTransaction);
} }
} // namespace
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include <map> #include <map>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
...@@ -439,7 +440,8 @@ SSLClientSocketNSS::SSLClientSocketNSS(ClientSocketHandle* transport_socket, ...@@ -439,7 +440,8 @@ SSLClientSocketNSS::SSLClientSocketNSS(ClientSocketHandle* transport_socket,
transport_recv_busy_(false), transport_recv_busy_(false),
corked_(false), corked_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(handshake_io_callback_( ALLOW_THIS_IN_INITIALIZER_LIST(handshake_io_callback_(
this, &SSLClientSocketNSS::OnHandshakeIOComplete)), base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete,
base::Unretained(this)))),
transport_(transport_socket), transport_(transport_socket),
host_and_port_(host_and_port), host_and_port_(host_and_port),
ssl_config_(ssl_config), ssl_config_(ssl_config),
...@@ -1386,7 +1388,7 @@ bool SSLClientSocketNSS::LoadSSLHostInfo() { ...@@ -1386,7 +1388,7 @@ bool SSLClientSocketNSS::LoadSSLHostInfo() {
int SSLClientSocketNSS::DoLoadSSLHostInfo() { int SSLClientSocketNSS::DoLoadSSLHostInfo() {
EnterFunction(""); EnterFunction("");
int rv = ssl_host_info_->WaitForDataReady(&handshake_io_callback_); int rv = ssl_host_info_->WaitForDataReady(handshake_io_callback_);
GotoState(STATE_HANDSHAKE); GotoState(STATE_HANDSHAKE);
if (rv == OK) { if (rv == OK) {
...@@ -1667,7 +1669,7 @@ int SSLClientSocketNSS::DoVerifyCert(int result) { ...@@ -1667,7 +1669,7 @@ int SSLClientSocketNSS::DoVerifyCert(int result) {
UMA_HISTOGRAM_TIMES("Net.SSLVerificationMergedMsSaved", UMA_HISTOGRAM_TIMES("Net.SSLVerificationMergedMsSaved",
end_time - ssl_host_info_->verification_start_time()); end_time - ssl_host_info_->verification_start_time());
server_cert_verify_result_ = &ssl_host_info_->cert_verify_result(); server_cert_verify_result_ = &ssl_host_info_->cert_verify_result();
return ssl_host_info_->WaitForCertVerification(&handshake_io_callback_); return ssl_host_info_->WaitForCertVerification(handshake_io_callback_);
} else { } else {
UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 0 /* false */, 2); UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 0 /* false */, 2);
} }
...@@ -1875,7 +1877,7 @@ void SSLClientSocketNSS::SaveSSLHostInfo() { ...@@ -1875,7 +1877,7 @@ void SSLClientSocketNSS::SaveSSLHostInfo() {
// If the SSLHostInfo hasn't managed to load from disk yet then we can't save // If the SSLHostInfo hasn't managed to load from disk yet then we can't save
// anything. // anything.
if (ssl_host_info_->WaitForDataReady(NULL) != OK) if (ssl_host_info_->WaitForDataReady(net::CompletionCallback()) != OK)
return; return;
SSLHostInfo::State* state = ssl_host_info_->mutable_state(); SSLHostInfo::State* state = ssl_host_info_->mutable_state();
......
...@@ -217,7 +217,7 @@ class SSLClientSocketNSS : public SSLClientSocket { ...@@ -217,7 +217,7 @@ class SSLClientSocketNSS : public SSLClientSocket {
base::OneShotTimer<SSLClientSocketNSS> uncork_timer_; base::OneShotTimer<SSLClientSocketNSS> uncork_timer_;
scoped_refptr<IOBuffer> recv_buffer_; scoped_refptr<IOBuffer> recv_buffer_;
OldCompletionCallbackImpl<SSLClientSocketNSS> handshake_io_callback_; CompletionCallback handshake_io_callback_;
scoped_ptr<ClientSocketHandle> transport_; scoped_ptr<ClientSocketHandle> transport_;
HostPortPair host_and_port_; HostPortPair host_and_port_;
SSLConfig ssl_config_; SSLConfig ssl_config_;
......
...@@ -32,7 +32,6 @@ SSLHostInfo::SSLHostInfo( ...@@ -32,7 +32,6 @@ SSLHostInfo::SSLHostInfo(
cert_verification_error_(ERR_CERT_INVALID), cert_verification_error_(ERR_CERT_INVALID),
hostname_(hostname), hostname_(hostname),
cert_parsing_failed_(false), cert_parsing_failed_(false),
cert_verification_callback_(NULL),
rev_checking_enabled_(ssl_config.rev_checking_enabled), rev_checking_enabled_(ssl_config.rev_checking_enabled),
verify_ev_cert_(ssl_config.verify_ev_cert), verify_ev_cert_(ssl_config.verify_ev_cert),
verifier_(cert_verifier), verifier_(cert_verifier),
...@@ -136,7 +135,7 @@ bool SSLHostInfo::ParseInner(const std::string& data) { ...@@ -136,7 +135,7 @@ bool SSLHostInfo::ParseInner(const std::string& data) {
VerifyCallback(rv); VerifyCallback(rv);
} else { } else {
cert_parsing_failed_ = true; cert_parsing_failed_ = true;
DCHECK(!cert_verification_callback_); DCHECK(cert_verification_callback_.is_null());
} }
} }
...@@ -181,11 +180,12 @@ const CertVerifyResult& SSLHostInfo::cert_verify_result() const { ...@@ -181,11 +180,12 @@ const CertVerifyResult& SSLHostInfo::cert_verify_result() const {
return cert_verify_result_; return cert_verify_result_;
} }
int SSLHostInfo::WaitForCertVerification(OldCompletionCallback* callback) { int SSLHostInfo::WaitForCertVerification(const CompletionCallback& callback) {
if (cert_verification_complete_) if (cert_verification_complete_)
return cert_verification_error_; return cert_verification_error_;
DCHECK(!cert_parsing_failed_); DCHECK(!cert_parsing_failed_);
DCHECK(!cert_verification_callback_); DCHECK(cert_verification_callback_.is_null());
DCHECK(!state_.certs.empty()); DCHECK(!state_.certs.empty());
cert_verification_callback_ = callback; cert_verification_callback_ = callback;
return ERR_IO_PENDING; return ERR_IO_PENDING;
...@@ -206,10 +206,10 @@ void SSLHostInfo::VerifyCallback(int rv) { ...@@ -206,10 +206,10 @@ void SSLHostInfo::VerifyCallback(int rv) {
verification_end_time_ = now; verification_end_time_ = now;
cert_verification_complete_ = true; cert_verification_complete_ = true;
cert_verification_error_ = rv; cert_verification_error_ = rv;
if (cert_verification_callback_) { if (!cert_verification_callback_.is_null()) {
OldCompletionCallback* callback = cert_verification_callback_; CompletionCallback callback = cert_verification_callback_;
cert_verification_callback_ = NULL; cert_verification_callback_.Reset();
callback->Run(rv); callback.Run(rv);
} }
} }
......
...@@ -51,7 +51,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo { ...@@ -51,7 +51,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo {
// //
// |callback| may be NULL, in which case ERR_IO_PENDING may still be returned // |callback| may be NULL, in which case ERR_IO_PENDING may still be returned
// but, obviously, a callback will never be made. // but, obviously, a callback will never be made.
virtual int WaitForDataReady(OldCompletionCallback* callback) = 0; virtual int WaitForDataReady(const CompletionCallback& callback) = 0;
// Persist allows for the host information to be updated for future users. // Persist allows for the host information to be updated for future users.
// This is a fire and forget operation: the caller may drop its reference // This is a fire and forget operation: the caller may drop its reference
...@@ -91,7 +91,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo { ...@@ -91,7 +91,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo {
// callback to be called when the verification completes. If the verification // callback to be called when the verification completes. If the verification
// has already finished then WaitForCertVerification returns the result of // has already finished then WaitForCertVerification returns the result of
// that verification. // that verification.
int WaitForCertVerification(OldCompletionCallback* callback); int WaitForCertVerification(const CompletionCallback& callback);
base::TimeTicks verification_start_time() const { base::TimeTicks verification_start_time() const {
return verification_start_time_; return verification_start_time_;
...@@ -121,7 +121,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo { ...@@ -121,7 +121,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo {
// This is the hostname that we'll validate the certificates against. // This is the hostname that we'll validate the certificates against.
const std::string hostname_; const std::string hostname_;
bool cert_parsing_failed_; bool cert_parsing_failed_;
OldCompletionCallback* cert_verification_callback_; CompletionCallback cert_verification_callback_;
// These three members are taken from the SSLConfig. // These three members are taken from the SSLConfig.
bool rev_checking_enabled_; bool rev_checking_enabled_;
bool verify_ev_cert_; bool verify_ev_cert_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment