summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/base/cert_verifier.cc41
-rw-r--r--net/base/cert_verifier.h9
-rw-r--r--net/base/cert_verifier_unittest.cc71
-rw-r--r--net/base/origin_bound_cert_service.cc25
-rw-r--r--net/base/origin_bound_cert_service.h2
-rw-r--r--net/base/origin_bound_cert_service_unittest.cc66
-rw-r--r--net/socket/ssl_client_socket_mac.cc12
-rw-r--r--net/socket/ssl_client_socket_mac.h1
-rw-r--r--net/socket/ssl_client_socket_nss.cc12
-rw-r--r--net/socket/ssl_client_socket_openssl.cc14
-rw-r--r--net/socket/ssl_client_socket_openssl.h1
-rw-r--r--net/socket/ssl_client_socket_win.cc9
-rw-r--r--net/socket/ssl_host_info.cc10
-rw-r--r--net/socket/ssl_host_info.h3
14 files changed, 143 insertions, 133 deletions
diff --git a/net/base/cert_verifier.cc b/net/base/cert_verifier.cc
index ea90ea9..ae474c5 100644
--- a/net/base/cert_verifier.cc
+++ b/net/base/cert_verifier.cc
@@ -4,6 +4,7 @@
#include "net/base/cert_verifier.h"
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
@@ -87,7 +88,7 @@ bool CachedCertVerifyResult::HasExpired(const base::Time current_time) const {
// Represents the output and result callback of a request.
class CertVerifierRequest {
public:
- CertVerifierRequest(OldCompletionCallback* callback,
+ CertVerifierRequest(const CompletionCallback& callback,
CertVerifyResult* verify_result)
: callback_(callback),
verify_result_(verify_result) {
@@ -95,24 +96,24 @@ class CertVerifierRequest {
// Ensures that the result callback will never be made.
void Cancel() {
- callback_ = NULL;
+ callback_.Reset();
verify_result_ = NULL;
}
// Copies the contents of |verify_result| to the caller's
// CertVerifyResult and calls the callback.
void Post(const CachedCertVerifyResult& verify_result) {
- if (callback_) {
+ if (!callback_.is_null()) {
*verify_result_ = verify_result.result;
- callback_->Run(verify_result.error);
+ callback_.Run(verify_result.error);
}
delete this;
}
- bool canceled() const { return !callback_; }
+ bool canceled() const { return callback_.is_null(); }
private:
- OldCompletionCallback* callback_;
+ CompletionCallback callback_;
CertVerifyResult* verify_result_;
};
@@ -309,11 +310,11 @@ int CertVerifier::Verify(X509Certificate* cert,
const std::string& hostname,
int flags,
CertVerifyResult* verify_result,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
RequestHandle* out_req) {
DCHECK(CalledOnValidThread());
- if (!callback || !verify_result || hostname.empty()) {
+ if (callback.is_null() || !verify_result || hostname.empty()) {
*out_req = NULL;
return ERR_INVALID_ARGUMENT;
}
@@ -448,10 +449,7 @@ void CertVerifier::OnCertTrustChanged(const X509Certificate* cert) {
SingleRequestCertVerifier::SingleRequestCertVerifier(
CertVerifier* cert_verifier)
: cert_verifier_(cert_verifier),
- cur_request_(NULL),
- cur_request_callback_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_(this, &SingleRequestCertVerifier::OnVerifyCompletion)) {
+ cur_request_(NULL) {
DCHECK(cert_verifier_ != NULL);
}
@@ -466,12 +464,12 @@ int SingleRequestCertVerifier::Verify(X509Certificate* cert,
const std::string& hostname,
int flags,
CertVerifyResult* verify_result,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
// Should not be already in use.
- DCHECK(!cur_request_ && !cur_request_callback_);
+ DCHECK(!cur_request_ && cur_request_callback_.is_null());
// Do a synchronous verification.
- if (!callback)
+ if (callback.is_null())
return cert->Verify(hostname, flags, verify_result);
CertVerifier::RequestHandle request = NULL;
@@ -479,7 +477,10 @@ int SingleRequestCertVerifier::Verify(X509Certificate* cert,
// We need to be notified of completion before |callback| is called, so that
// we can clear out |cur_request_*|.
int rv = cert_verifier_->Verify(
- cert, hostname, flags, verify_result, &callback_, &request);
+ cert, hostname, flags, verify_result,
+ base::Bind(&SingleRequestCertVerifier::OnVerifyCompletion,
+ base::Unretained(this)),
+ &request);
if (rv == ERR_IO_PENDING) {
// Cleared in OnVerifyCompletion().
@@ -491,16 +492,16 @@ int SingleRequestCertVerifier::Verify(X509Certificate* cert,
}
void SingleRequestCertVerifier::OnVerifyCompletion(int result) {
- DCHECK(cur_request_ && cur_request_callback_);
+ DCHECK(cur_request_ && !cur_request_callback_.is_null());
- OldCompletionCallback* callback = cur_request_callback_;
+ CompletionCallback callback = cur_request_callback_;
// Clear the outstanding request information.
cur_request_ = NULL;
- cur_request_callback_ = NULL;
+ cur_request_callback_.Reset();
// Call the user's original callback.
- callback->Run(result);
+ callback.Run(result);
}
} // namespace net
diff --git a/net/base/cert_verifier.h b/net/base/cert_verifier.h
index 9f97573..f701f77 100644
--- a/net/base/cert_verifier.h
+++ b/net/base/cert_verifier.h
@@ -102,7 +102,7 @@ class NET_EXPORT CertVerifier : NON_EXPORTED_BASE(public base::NonThreadSafe),
const std::string& hostname,
int flags,
CertVerifyResult* verify_result,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
RequestHandle* out_req);
// Cancels the specified request. |req| is the handle returned by Verify().
@@ -201,7 +201,7 @@ class SingleRequestCertVerifier {
const std::string& hostname,
int flags,
CertVerifyResult* verify_result,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
private:
// Callback for when the request to |cert_verifier_| completes, so we
@@ -213,10 +213,7 @@ class SingleRequestCertVerifier {
// The current request (if any).
CertVerifier::RequestHandle cur_request_;
- OldCompletionCallback* cur_request_callback_;
-
- // Completion callback for when request to |cert_verifier_| completes.
- OldCompletionCallbackImpl<SingleRequestCertVerifier> callback_;
+ CompletionCallback cur_request_callback_;
DISALLOW_COPY_AND_ASSIGN(SingleRequestCertVerifier);
};
diff --git a/net/base/cert_verifier_unittest.cc b/net/base/cert_verifier_unittest.cc
index 3787749..15eafa7 100644
--- a/net/base/cert_verifier_unittest.cc
+++ b/net/base/cert_verifier_unittest.cc
@@ -4,7 +4,7 @@
#include "net/base/cert_verifier.h"
-#include "base/callback.h"
+#include "base/bind.h"
#include "base/file_path.h"
#include "base/stringprintf.h"
#include "net/base/cert_test_util.h"
@@ -15,6 +15,8 @@
namespace net {
+namespace {
+
class TestTimeService : public CertVerifier::TimeService {
public:
// CertVerifier::TimeService methods:
@@ -26,18 +28,12 @@ class TestTimeService : public CertVerifier::TimeService {
base::Time current_time_;
};
-class CertVerifierTest : public testing::Test {
-};
-
-class ExplodingCallback : public CallbackRunner<Tuple1<int> > {
- public:
- virtual void RunWithParams(const Tuple1<int>& params) {
- FAIL();
- }
-};
+void FailTest(int /* result */) {
+ FAIL();
+}
// Tests a cache hit, which should results in synchronous completion.
-TEST_F(CertVerifierTest, CacheHit) {
+TEST(CertVerifierTest, CacheHit) {
TestTimeService* time_service = new TestTimeService;
base::Time current_time = base::Time::Now();
time_service->set_current_time(current_time);
@@ -50,11 +46,11 @@ TEST_F(CertVerifierTest, CacheHit) {
int error;
CertVerifyResult verify_result;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CertVerifier::RequestHandle request_handle;
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -64,7 +60,7 @@ TEST_F(CertVerifierTest, CacheHit) {
ASSERT_EQ(0u, verifier.inflight_joins());
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
// Synchronous completion.
ASSERT_NE(ERR_IO_PENDING, error);
ASSERT_TRUE(IsCertificateError(error));
@@ -75,7 +71,7 @@ TEST_F(CertVerifierTest, CacheHit) {
}
// Tests an inflight join.
-TEST_F(CertVerifierTest, InflightJoin) {
+TEST(CertVerifierTest, InflightJoin) {
TestTimeService* time_service = new TestTimeService;
base::Time current_time = base::Time::Now();
time_service->set_current_time(current_time);
@@ -88,18 +84,18 @@ TEST_F(CertVerifierTest, InflightJoin) {
int error;
CertVerifyResult verify_result;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CertVerifier::RequestHandle request_handle;
CertVerifyResult verify_result2;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
CertVerifier::RequestHandle request_handle2;
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result2,
- &callback2, &request_handle2);
+ callback2.callback(), &request_handle2);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle2 != NULL);
error = callback.WaitForResult();
@@ -112,7 +108,7 @@ TEST_F(CertVerifierTest, InflightJoin) {
}
// Tests cache entry expiration.
-TEST_F(CertVerifierTest, ExpiredCacheEntry) {
+TEST(CertVerifierTest, ExpiredCacheEntry) {
TestTimeService* time_service = new TestTimeService;
base::Time current_time = base::Time::Now();
time_service->set_current_time(current_time);
@@ -125,11 +121,11 @@ TEST_F(CertVerifierTest, ExpiredCacheEntry) {
int error;
CertVerifyResult verify_result;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CertVerifier::RequestHandle request_handle;
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -140,7 +136,7 @@ TEST_F(CertVerifierTest, ExpiredCacheEntry) {
// Before expiration, should have a cache hit.
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
// Synchronous completion.
ASSERT_NE(ERR_IO_PENDING, error);
ASSERT_TRUE(IsCertificateError(error));
@@ -154,7 +150,7 @@ TEST_F(CertVerifierTest, ExpiredCacheEntry) {
current_time += base::TimeDelta::FromMinutes(60);
time_service->set_current_time(current_time);
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
ASSERT_EQ(0u, verifier.GetCacheSize());
@@ -166,7 +162,7 @@ TEST_F(CertVerifierTest, ExpiredCacheEntry) {
}
// Tests a full cache.
-TEST_F(CertVerifierTest, FullCache) {
+TEST(CertVerifierTest, FullCache) {
TestTimeService* time_service = new TestTimeService;
base::Time current_time = base::Time::Now();
time_service->set_current_time(current_time);
@@ -184,11 +180,11 @@ TEST_F(CertVerifierTest, FullCache) {
int error;
CertVerifyResult verify_result;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CertVerifier::RequestHandle request_handle;
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -200,7 +196,7 @@ TEST_F(CertVerifierTest, FullCache) {
for (unsigned i = 0; i < kCacheSize; i++) {
std::string hostname = base::StringPrintf("www%d.example.com", i + 1);
error = verifier.Verify(test_cert, hostname, 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -214,7 +210,7 @@ TEST_F(CertVerifierTest, FullCache) {
current_time += base::TimeDelta::FromMinutes(60);
time_service->set_current_time(current_time);
error = verifier.Verify(test_cert, "www999.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
ASSERT_EQ(kCacheSize, verifier.GetCacheSize());
@@ -227,7 +223,7 @@ TEST_F(CertVerifierTest, FullCache) {
}
// Tests that the callback of a canceled request is never made.
-TEST_F(CertVerifierTest, CancelRequest) {
+TEST(CertVerifierTest, CancelRequest) {
CertVerifier verifier;
FilePath certs_dir = GetTestCertsDirectory();
@@ -237,11 +233,10 @@ TEST_F(CertVerifierTest, CancelRequest) {
int error;
CertVerifyResult verify_result;
- ExplodingCallback exploding_callback;
CertVerifier::RequestHandle request_handle;
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &exploding_callback, &request_handle);
+ base::Bind(&FailTest), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
verifier.CancelRequest(request_handle);
@@ -249,10 +244,10 @@ TEST_F(CertVerifierTest, CancelRequest) {
// Issue a few more requests to the worker pool and wait for their
// completion, so that the task of the canceled request (which runs on a
// worker thread) is likely to complete by the end of this test.
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
for (int i = 0; i < 5; ++i) {
error = verifier.Verify(test_cert, "www2.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -261,7 +256,7 @@ TEST_F(CertVerifierTest, CancelRequest) {
}
// Tests that a canceled request is not leaked.
-TEST_F(CertVerifierTest, CancelRequestThenQuit) {
+TEST(CertVerifierTest, CancelRequestThenQuit) {
CertVerifier verifier;
FilePath certs_dir = GetTestCertsDirectory();
@@ -271,15 +266,17 @@ TEST_F(CertVerifierTest, CancelRequestThenQuit) {
int error;
CertVerifyResult verify_result;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CertVerifier::RequestHandle request_handle;
error = verifier.Verify(test_cert, "www.example.com", 0, &verify_result,
- &callback, &request_handle);
+ callback.callback(), &request_handle);
ASSERT_EQ(ERR_IO_PENDING, error);
ASSERT_TRUE(request_handle != NULL);
verifier.CancelRequest(request_handle);
// Destroy |verifier| by going out of scope.
}
+} // namespace
+
} // namespace net
diff --git a/net/base/origin_bound_cert_service.cc b/net/base/origin_bound_cert_service.cc
index cd89519..4b48e61 100644
--- a/net/base/origin_bound_cert_service.cc
+++ b/net/base/origin_bound_cert_service.cc
@@ -36,7 +36,7 @@ const int kValidityPeriodInDays = 365;
// Represents the output and result callback of a request.
class OriginBoundCertServiceRequest {
public:
- OriginBoundCertServiceRequest(OldCompletionCallback* callback,
+ OriginBoundCertServiceRequest(const CompletionCallback& callback,
std::string* private_key,
std::string* cert)
: callback_(callback),
@@ -46,7 +46,7 @@ class OriginBoundCertServiceRequest {
// Ensures that the result callback will never be made.
void Cancel() {
- callback_ = NULL;
+ callback_.Reset();
private_key_ = NULL;
cert_ = NULL;
}
@@ -56,18 +56,18 @@ class OriginBoundCertServiceRequest {
void Post(int error,
const std::string& private_key,
const std::string& cert) {
- if (callback_) {
+ if (!callback_.is_null()) {
*private_key_ = private_key;
*cert_ = cert;
- callback_->Run(error);
+ callback_.Run(error);
}
delete this;
}
- bool canceled() const { return !callback_; }
+ bool canceled() const { return callback_.is_null(); }
private:
- OldCompletionCallback* callback_;
+ CompletionCallback callback_;
std::string* private_key_;
std::string* cert_;
};
@@ -256,14 +256,15 @@ OriginBoundCertService::~OriginBoundCertService() {
STLDeleteValues(&inflight_);
}
-int OriginBoundCertService::GetOriginBoundCert(const std::string& origin,
- std::string* private_key,
- std::string* cert,
- OldCompletionCallback* callback,
- RequestHandle* out_req) {
+int OriginBoundCertService::GetOriginBoundCert(
+ const std::string& origin,
+ std::string* private_key,
+ std::string* cert,
+ const CompletionCallback& callback,
+ RequestHandle* out_req) {
DCHECK(CalledOnValidThread());
- if (!callback || !private_key || !cert || origin.empty()) {
+ if (callback.is_null() || !private_key || !cert || origin.empty()) {
*out_req = NULL;
return ERR_INVALID_ARGUMENT;
}
diff --git a/net/base/origin_bound_cert_service.h b/net/base/origin_bound_cert_service.h
index 0b5e54c..861602f 100644
--- a/net/base/origin_bound_cert_service.h
+++ b/net/base/origin_bound_cert_service.h
@@ -55,7 +55,7 @@ class NET_EXPORT OriginBoundCertService
int GetOriginBoundCert(const std::string& origin,
std::string* private_key,
std::string* cert,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
RequestHandle* out_req);
// Cancels the specified request. |req| is the handle returned by
diff --git a/net/base/origin_bound_cert_service_unittest.cc b/net/base/origin_bound_cert_service_unittest.cc
index edc347f..3fdb443 100644
--- a/net/base/origin_bound_cert_service_unittest.cc
+++ b/net/base/origin_bound_cert_service_unittest.cc
@@ -7,6 +7,7 @@
#include <string>
#include <vector>
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "crypto/rsa_private_key.h"
#include "net/base/default_origin_bound_cert_store.h"
@@ -17,33 +18,30 @@
namespace net {
-class OriginBoundCertServiceTest : public testing::Test {
-};
+namespace {
-class ExplodingCallback : public CallbackRunner<Tuple1<int> > {
- public:
- virtual void RunWithParams(const Tuple1<int>& params) {
- FAIL();
- }
-};
+void FailTest(int /* result */) {
+ FAIL();
+}
// See http://crbug.com/91512 - implement OpenSSL version of CreateSelfSigned.
#if !defined(USE_OPENSSL)
-TEST_F(OriginBoundCertServiceTest, CacheHit) {
+TEST(OriginBoundCertServiceTest, CacheHit) {
scoped_ptr<OriginBoundCertService> service(
new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
std::string origin("https://encrypted.google.com:443");
int error;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
OriginBoundCertService::RequestHandle request_handle;
// Asynchronous completion.
std::string private_key_info1, der_cert1;
EXPECT_EQ(0, service->cert_count());
error = service->GetOriginBoundCert(
- origin, &private_key_info1, &der_cert1, &callback, &request_handle);
+ origin, &private_key_info1, &der_cert1, callback.callback(),
+ &request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -55,7 +53,8 @@ TEST_F(OriginBoundCertServiceTest, CacheHit) {
// Synchronous completion.
std::string private_key_info2, der_cert2;
error = service->GetOriginBoundCert(
- origin, &private_key_info2, &der_cert2, &callback, &request_handle);
+ origin, &private_key_info2, &der_cert2, callback.callback(),
+ &request_handle);
EXPECT_TRUE(request_handle == NULL);
EXPECT_EQ(OK, error);
EXPECT_EQ(1, service->cert_count());
@@ -68,18 +67,19 @@ TEST_F(OriginBoundCertServiceTest, CacheHit) {
EXPECT_EQ(0u, service->inflight_joins());
}
-TEST_F(OriginBoundCertServiceTest, StoreCerts) {
+TEST(OriginBoundCertServiceTest, StoreCerts) {
scoped_ptr<OriginBoundCertService> service(
new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
int error;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
OriginBoundCertService::RequestHandle request_handle;
std::string origin1("https://encrypted.google.com:443");
std::string private_key_info1, der_cert1;
EXPECT_EQ(0, service->cert_count());
error = service->GetOriginBoundCert(
- origin1, &private_key_info1, &der_cert1, &callback, &request_handle);
+ origin1, &private_key_info1, &der_cert1, callback.callback(),
+ &request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -89,7 +89,8 @@ TEST_F(OriginBoundCertServiceTest, StoreCerts) {
std::string origin2("https://www.verisign.com:443");
std::string private_key_info2, der_cert2;
error = service->GetOriginBoundCert(
- origin2, &private_key_info2, &der_cert2, &callback, &request_handle);
+ origin2, &private_key_info2, &der_cert2, callback.callback(),
+ &request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -99,7 +100,8 @@ TEST_F(OriginBoundCertServiceTest, StoreCerts) {
std::string origin3("https://www.twitter.com:443");
std::string private_key_info3, der_cert3;
error = service->GetOriginBoundCert(
- origin3, &private_key_info3, &der_cert3, &callback, &request_handle);
+ origin3, &private_key_info3, &der_cert3, callback.callback(),
+ &request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -115,26 +117,28 @@ TEST_F(OriginBoundCertServiceTest, StoreCerts) {
}
// Tests an inflight join.
-TEST_F(OriginBoundCertServiceTest, InflightJoin) {
+TEST(OriginBoundCertServiceTest, InflightJoin) {
scoped_ptr<OriginBoundCertService> service(
new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
std::string origin("https://encrypted.google.com:443");
int error;
std::string private_key_info1, der_cert1;
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
OriginBoundCertService::RequestHandle request_handle1;
std::string private_key_info2, der_cert2;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
OriginBoundCertService::RequestHandle request_handle2;
error = service->GetOriginBoundCert(
- origin, &private_key_info1, &der_cert1, &callback1, &request_handle1);
+ origin, &private_key_info1, &der_cert1, callback1.callback(),
+ &request_handle1);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle1 != NULL);
error = service->GetOriginBoundCert(
- origin, &private_key_info2, &der_cert2, &callback2, &request_handle2);
+ origin, &private_key_info2, &der_cert2, callback2.callback(),
+ &request_handle2);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle2 != NULL);
@@ -148,17 +152,18 @@ TEST_F(OriginBoundCertServiceTest, InflightJoin) {
EXPECT_EQ(1u, service->inflight_joins());
}
-TEST_F(OriginBoundCertServiceTest, ExtractValuesFromBytes) {
+TEST(OriginBoundCertServiceTest, ExtractValuesFromBytes) {
scoped_ptr<OriginBoundCertService> service(
new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
std::string origin("https://encrypted.google.com:443");
std::string private_key_info, der_cert;
int error;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
OriginBoundCertService::RequestHandle request_handle;
error = service->GetOriginBoundCert(
- origin, &private_key_info, &der_cert, &callback, &request_handle);
+ origin, &private_key_info, &der_cert, callback.callback(),
+ &request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
error = callback.WaitForResult();
@@ -177,19 +182,18 @@ TEST_F(OriginBoundCertServiceTest, ExtractValuesFromBytes) {
}
// Tests that the callback of a canceled request is never made.
-TEST_F(OriginBoundCertServiceTest, CancelRequest) {
+TEST(OriginBoundCertServiceTest, CancelRequest) {
scoped_ptr<OriginBoundCertService> service(
new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL)));
std::string origin("https://encrypted.google.com:443");
std::string private_key_info, der_cert;
int error;
- ExplodingCallback exploding_callback;
OriginBoundCertService::RequestHandle request_handle;
error = service->GetOriginBoundCert(origin,
&private_key_info,
&der_cert,
- &exploding_callback,
+ base::Bind(&FailTest),
&request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
@@ -198,13 +202,13 @@ TEST_F(OriginBoundCertServiceTest, CancelRequest) {
// Issue a few more requests to the worker pool and wait for their
// completion, so that the task of the canceled request (which runs on a
// worker thread) is likely to complete by the end of this test.
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
for (int i = 0; i < 5; ++i) {
error = service->GetOriginBoundCert(
"https://encrypted.google.com:" + std::string(1, (char) ('1' + i)),
&private_key_info,
&der_cert,
- &callback,
+ callback.callback(),
&request_handle);
EXPECT_EQ(ERR_IO_PENDING, error);
EXPECT_TRUE(request_handle != NULL);
@@ -214,4 +218,6 @@ TEST_F(OriginBoundCertServiceTest, CancelRequest) {
#endif // !defined(USE_OPENSSL)
+} // namespace
+
} // namespace net
diff --git a/net/socket/ssl_client_socket_mac.cc b/net/socket/ssl_client_socket_mac.cc
index 97527b8..a3c7854 100644
--- a/net/socket/ssl_client_socket_mac.cc
+++ b/net/socket/ssl_client_socket_mac.cc
@@ -11,6 +11,7 @@
#include <algorithm>
+#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/string_util.h"
@@ -522,8 +523,7 @@ SSLClientSocketMac::SSLClientSocketMac(ClientSocketHandle* transport_socket,
const HostPortPair& host_and_port,
const SSLConfig& ssl_config,
const SSLClientSocketContext& context)
- : handshake_io_callback_(this, &SSLClientSocketMac::OnHandshakeIOComplete),
- transport_read_callback_(this,
+ : transport_read_callback_(this,
&SSLClientSocketMac::OnTransportReadComplete),
transport_write_callback_(this,
&SSLClientSocketMac::OnTransportWriteComplete),
@@ -1156,9 +1156,11 @@ int SSLClientSocketMac::DoVerifyCert() {
if (ssl_config_.verify_ev_cert)
flags |= X509Certificate::VERIFY_EV_CERT;
verifier_.reset(new SingleRequestCertVerifier(cert_verifier_));
- return verifier_->Verify(server_cert_, host_and_port_.host(), flags,
- &server_cert_verify_result_,
- &handshake_io_callback_);
+ return verifier_->Verify(
+ server_cert_, host_and_port_.host(), flags,
+ &server_cert_verify_result_,
+ base::Bind(&SSLClientSocketMac::OnHandshakeIOComplete,
+ base::Unretained(this)));
}
int SSLClientSocketMac::DoVerifyCertComplete(int result) {
diff --git a/net/socket/ssl_client_socket_mac.h b/net/socket/ssl_client_socket_mac.h
index 2f3b1e3..5370b2d 100644
--- a/net/socket/ssl_client_socket_mac.h
+++ b/net/socket/ssl_client_socket_mac.h
@@ -105,7 +105,6 @@ class SSLClientSocketMac : public SSLClientSocket {
const void* data,
size_t* data_length);
- OldCompletionCallbackImpl<SSLClientSocketMac> handshake_io_callback_;
OldCompletionCallbackImpl<SSLClientSocketMac> transport_read_callback_;
OldCompletionCallbackImpl<SSLClientSocketMac> transport_write_callback_;
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index 79fd69a..0616578 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -64,6 +64,7 @@
#include <limits>
#include <map>
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
@@ -1686,9 +1687,11 @@ int SSLClientSocketNSS::DoVerifyCert(int result) {
flags |= X509Certificate::VERIFY_EV_CERT;
verifier_.reset(new SingleRequestCertVerifier(cert_verifier_));
server_cert_verify_result_ = &local_server_cert_verify_result_;
- return verifier_->Verify(server_cert_, host_and_port_.host(), flags,
- &local_server_cert_verify_result_,
- &handshake_io_callback_);
+ return verifier_->Verify(
+ server_cert_, host_and_port_.host(), flags,
+ &local_server_cert_verify_result_,
+ base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete,
+ base::Unretained(this)));
}
// Derived from AuthCertificateCallback() in
@@ -2126,7 +2129,8 @@ SECStatus SSLClientSocketNSS::OriginBoundClientAuthHandler(
origin,
&ob_private_key_,
&ob_cert_,
- &handshake_io_callback_,
+ base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete,
+ base::Unretained(this)),
&ob_cert_request_handle_);
if (error == OK) {
diff --git a/net/socket/ssl_client_socket_openssl.cc b/net/socket/ssl_client_socket_openssl.cc
index db9dc78..d76b377 100644
--- a/net/socket/ssl_client_socket_openssl.cc
+++ b/net/socket/ssl_client_socket_openssl.cc
@@ -10,6 +10,7 @@
#include <openssl/ssl.h>
#include <openssl/err.h>
+#include "base/bind.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram.h"
#include "base/synchronization/lock.h"
@@ -394,8 +395,6 @@ SSLClientSocketOpenSSL::SSLClientSocketOpenSSL(
completed_handshake_(false),
client_auth_cert_needed_(false),
cert_verifier_(context.cert_verifier),
- ALLOW_THIS_IN_INITIALIZER_LIST(handshake_io_callback_(
- this, &SSLClientSocketOpenSSL::OnHandshakeIOComplete)),
ssl_(NULL),
transport_bio_(NULL),
transport_(transport_socket),
@@ -664,8 +663,7 @@ void SSLClientSocketOpenSSL::Disconnect() {
transport_bio_ = NULL;
}
- // Shut down anything that may call us back (through buffer_send_callback_,
- // buffer_recv_callback, or handshake_io_callback_).
+ // Shut down anything that may call us back.
verifier_.reset();
transport_->socket()->Disconnect();
@@ -836,9 +834,11 @@ int SSLClientSocketOpenSSL::DoVerifyCert(int result) {
if (ssl_config_.verify_ev_cert)
flags |= X509Certificate::VERIFY_EV_CERT;
verifier_.reset(new SingleRequestCertVerifier(cert_verifier_));
- return verifier_->Verify(server_cert_, host_and_port_.host(), flags,
- &server_cert_verify_result_,
- &handshake_io_callback_);
+ return verifier_->Verify(
+ server_cert_, host_and_port_.host(), flags,
+ &server_cert_verify_result_,
+ base::Bind(&SSLClientSocketOpenSSL::OnHandshakeIOComplete,
+ base::Unretained(this)));
}
int SSLClientSocketOpenSSL::DoVerifyCertComplete(int result) {
diff --git a/net/socket/ssl_client_socket_openssl.h b/net/socket/ssl_client_socket_openssl.h
index 81ece4c..a09fff4 100644
--- a/net/socket/ssl_client_socket_openssl.h
+++ b/net/socket/ssl_client_socket_openssl.h
@@ -142,7 +142,6 @@ class SSLClientSocketOpenSSL : public SSLClientSocket {
CertVerifier* const cert_verifier_;
scoped_ptr<SingleRequestCertVerifier> verifier_;
- OldCompletionCallbackImpl<SSLClientSocketOpenSSL> handshake_io_callback_;
// OpenSSL stuff
SSL* ssl_;
diff --git a/net/socket/ssl_client_socket_win.cc b/net/socket/ssl_client_socket_win.cc
index 50b24db..10ba66a 100644
--- a/net/socket/ssl_client_socket_win.cc
+++ b/net/socket/ssl_client_socket_win.cc
@@ -7,6 +7,7 @@
#include <schnlsp.h>
#include <map>
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/stl_util.h"
@@ -1172,9 +1173,11 @@ int SSLClientSocketWin::DoVerifyCert() {
if (ssl_config_.verify_ev_cert)
flags |= X509Certificate::VERIFY_EV_CERT;
verifier_.reset(new SingleRequestCertVerifier(cert_verifier_));
- return verifier_->Verify(server_cert_, host_and_port_.host(), flags,
- &server_cert_verify_result_,
- &handshake_io_callback_);
+ return verifier_->Verify(
+ server_cert_, host_and_port_.host(), flags,
+ &server_cert_verify_result_,
+ base::Bind(&SSLClientSocketWin::OnHandshakeIOComplete,
+ base::Unretained(this)));
}
int SSLClientSocketWin::DoVerifyCertComplete(int result) {
diff --git a/net/socket/ssl_host_info.cc b/net/socket/ssl_host_info.cc
index 2f03a1a..ae897b0 100644
--- a/net/socket/ssl_host_info.cc
+++ b/net/socket/ssl_host_info.cc
@@ -4,6 +4,7 @@
#include "net/socket/ssl_host_info.h"
+#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "base/pickle.h"
#include "base/string_piece.h"
@@ -35,9 +36,7 @@ SSLHostInfo::SSLHostInfo(
rev_checking_enabled_(ssl_config.rev_checking_enabled),
verify_ev_cert_(ssl_config.verify_ev_cert),
verifier_(cert_verifier),
- callback_(new CancelableOldCompletionCallback<SSLHostInfo>(
- ALLOW_THIS_IN_INITIALIZER_LIST(this),
- &SSLHostInfo::VerifyCallback)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
dnsrr_resolver_(NULL),
dns_callback_(NULL),
dns_handle_(DnsRRResolver::kInvalidHandle) {
@@ -128,8 +127,9 @@ bool SSLHostInfo::ParseInner(const std::string& data) {
VLOG(1) << "Kicking off verification for " << hostname_;
verification_start_time_ = base::TimeTicks::Now();
verification_end_time_ = base::TimeTicks();
- int rv = verifier_.Verify(cert_.get(), hostname_, flags,
- &cert_verify_result_, callback_);
+ int rv = verifier_.Verify(
+ cert_.get(), hostname_, flags, &cert_verify_result_,
+ base::Bind(&SSLHostInfo::VerifyCallback, weak_factory_.GetWeakPtr()));
if (rv != ERR_IO_PENDING)
VerifyCallback(rv);
} else {
diff --git a/net/socket/ssl_host_info.h b/net/socket/ssl_host_info.h
index b4884a7..c8028d3 100644
--- a/net/socket/ssl_host_info.h
+++ b/net/socket/ssl_host_info.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "net/base/cert_verifier.h"
#include "net/base/cert_verify_result.h"
@@ -128,7 +129,7 @@ class NET_EXPORT_PRIVATE SSLHostInfo {
CertVerifyResult cert_verify_result_;
SingleRequestCertVerifier verifier_;
scoped_refptr<X509Certificate> cert_;
- scoped_refptr<CancelableOldCompletionCallback<SSLHostInfo> > callback_;
+ base::WeakPtrFactory<SSLHostInfo> weak_factory_;
DnsRRResolver* dnsrr_resolver_;
OldCompletionCallback* dns_callback_;