base::Bind: Convert most of net/http.
BUG=none
TEST=none
R=csilv
Review URL: http://codereview.chromium.org/8990001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115220 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc
index cd1e5be..d782f5e 100644
--- a/net/http/http_auth_cache_unittest.cc
+++ b/net/http/http_auth_cache_unittest.cc
@@ -42,7 +42,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials*,
const HttpRequestInfo*,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) {
*auth_token = "mock-credentials";
return OK;
diff --git a/net/http/http_auth_controller.cc b/net/http/http_auth_controller.cc
index d2457ef..8a23969 100644
--- a/net/http/http_auth_controller.cc
+++ b/net/http/http_auth_controller.cc
@@ -4,6 +4,8 @@
#include "net/http/http_auth_controller.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/threading/platform_thread.h"
@@ -161,20 +163,16 @@
embedded_identity_used_(false),
default_credentials_used_(false),
http_auth_cache_(http_auth_cache),
- http_auth_handler_factory_(http_auth_handler_factory),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &HttpAuthController::OnIOComplete)),
- user_callback_(NULL) {
+ http_auth_handler_factory_(http_auth_handler_factory) {
}
HttpAuthController::~HttpAuthController() {
DCHECK(CalledOnValidThread());
- user_callback_ = NULL;
}
-int HttpAuthController::MaybeGenerateAuthToken(const HttpRequestInfo* request,
- OldCompletionCallback* callback,
- const BoundNetLog& net_log) {
+int HttpAuthController::MaybeGenerateAuthToken(
+ const HttpRequestInfo* request, const CompletionCallback& callback,
+ const BoundNetLog& net_log) {
DCHECK(CalledOnValidThread());
bool needs_auth = HaveAuth() || SelectPreemptiveAuth(net_log);
if (!needs_auth)
@@ -183,15 +181,15 @@
if (identity_.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS)
credentials = &identity_.credentials;
DCHECK(auth_token_.empty());
- DCHECK(NULL == user_callback_);
- int rv = handler_->GenerateAuthToken(credentials,
- request,
- &io_callback_,
- &auth_token_);
+ DCHECK(callback_.is_null());
+ int rv = handler_->GenerateAuthToken(
+ credentials, request,
+ base::Bind(&HttpAuthController::OnIOComplete, base::Unretained(this)),
+ &auth_token_);
if (DisableOnAuthHandlerResult(rv))
rv = OK;
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
else
OnIOComplete(rv);
return rv;
@@ -543,10 +541,10 @@
DCHECK(CalledOnValidThread());
if (DisableOnAuthHandlerResult(result))
result = OK;
- if (user_callback_) {
- OldCompletionCallback* c = user_callback_;
- user_callback_ = NULL;
- c->Run(result);
+ if (!callback_.is_null()) {
+ CompletionCallback c = callback_;
+ callback_.Reset();
+ c.Run(result);
}
}
diff --git a/net/http/http_auth_controller.h b/net/http/http_auth_controller.h
index 2712d00..2995bb7 100644
--- a/net/http/http_auth_controller.h
+++ b/net/http/http_auth_controller.h
@@ -45,7 +45,7 @@
// a token is correctly generated synchronously, as well as when no tokens
// were necessary.
virtual int MaybeGenerateAuthToken(const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log);
// Adds either the proxy auth header, or the origin server auth header,
@@ -163,8 +163,7 @@
std::set<HttpAuth::Scheme> disabled_schemes_;
- OldCompletionCallbackImpl<HttpAuthController> io_callback_;
- OldCompletionCallback* user_callback_;
+ CompletionCallback callback_;
};
} // namespace net
diff --git a/net/http/http_auth_controller_unittest.cc b/net/http/http_auth_controller_unittest.cc
index 392d9ab..a50d767f 100644
--- a/net/http/http_auth_controller_unittest.cc
+++ b/net/http/http_auth_controller_unittest.cc
@@ -77,10 +77,10 @@
controller->ResetAuth(AuthCredentials());
EXPECT_TRUE(controller->HaveAuth());
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
EXPECT_EQ((run_mode == RUN_HANDLER_ASYNC)? ERR_IO_PENDING:
expected_controller_rv,
- controller->MaybeGenerateAuthToken(&request, &callback,
+ controller->MaybeGenerateAuthToken(&request, callback.callback(),
dummy_log));
if (run_mode == RUN_HANDLER_ASYNC)
EXPECT_EQ(expected_controller_rv, callback.WaitForResult());
@@ -144,7 +144,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE {
int result =
HttpAuthHandlerMock::GenerateAuthTokenImpl(credentials,
@@ -215,7 +215,8 @@
EXPECT_TRUE(controller->HaveAuth());
// Should only succeed if we are using the AUTH_SCHEME_MOCK MockHandler.
- EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log));
+ EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(
+ &request, CompletionCallback(), dummy_log));
controller->AddAuthorizationHeader(&request_headers);
// Once a token is generated, simulate the receipt of a server response
@@ -229,7 +230,8 @@
EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC));
// Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler.
- EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log));
+ EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(
+ &request, CompletionCallback(), dummy_log));
}
} // namespace net
diff --git a/net/http/http_auth_handler.cc b/net/http/http_auth_handler.cc
index c196b85..0aad829 100644
--- a/net/http/http_auth_handler.cc
+++ b/net/http/http_auth_handler.cc
@@ -4,6 +4,8 @@
#include "net/http/http_auth_handler.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "net/base/net_errors.h"
@@ -13,11 +15,7 @@
: auth_scheme_(HttpAuth::AUTH_SCHEME_MAX),
score_(-1),
target_(HttpAuth::AUTH_NONE),
- properties_(-1),
- original_callback_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- wrapper_callback_(
- this, &HttpAuthHandler::OnGenerateAuthTokenComplete)) {
+ properties_(-1) {
}
HttpAuthHandler::~HttpAuthHandler() {
@@ -62,19 +60,21 @@
} // namespace
-int HttpAuthHandler::GenerateAuthToken(const AuthCredentials* credentials,
- const HttpRequestInfo* request,
- OldCompletionCallback* callback,
- std::string* auth_token) {
+int HttpAuthHandler::GenerateAuthToken(
+ const AuthCredentials* credentials, const HttpRequestInfo* request,
+ const CompletionCallback& callback, std::string* auth_token) {
// TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream.
DCHECK(request);
DCHECK(credentials != NULL || AllowsDefaultCredentials());
DCHECK(auth_token != NULL);
- DCHECK(original_callback_ == NULL);
- original_callback_ = callback;
+ DCHECK(callback_.is_null());
+ callback_ = callback;
net_log_.BeginEvent(EventTypeFromAuthTarget(target_), NULL);
- int rv = GenerateAuthTokenImpl(credentials, request,
- &wrapper_callback_, auth_token);
+ int rv = GenerateAuthTokenImpl(
+ credentials, request,
+ base::Bind(&HttpAuthHandler::OnGenerateAuthTokenComplete,
+ base::Unretained(this)),
+ auth_token);
if (rv != ERR_IO_PENDING)
FinishGenerateAuthToken();
return rv;
@@ -93,16 +93,16 @@
}
void HttpAuthHandler::OnGenerateAuthTokenComplete(int rv) {
- OldCompletionCallback* callback = original_callback_;
+ CompletionCallback callback = callback_;
FinishGenerateAuthToken();
- if (callback)
- callback->Run(rv);
+ if (!callback.is_null())
+ callback.Run(rv);
}
void HttpAuthHandler::FinishGenerateAuthToken() {
// TOOD(cbentzel): Should this be done in OK case only?
net_log_.EndEvent(EventTypeFromAuthTarget(target_), NULL);
- original_callback_ = NULL;
+ callback_.Reset();
}
} // namespace net
diff --git a/net/http/http_auth_handler.h b/net/http/http_auth_handler.h
index cdda944..864a512 100644
--- a/net/http/http_auth_handler.h
+++ b/net/http/http_auth_handler.h
@@ -27,7 +27,7 @@
// Initializes the handler using a challenge issued by a server.
// |challenge| must be non-NULL and have already tokenized the
- // authentication scheme, but none of the tokens occuring after the
+ // authentication scheme, but none of the tokens occurring after the
// authentication scheme. |target| and |origin| are both stored
// for later use, and are not part of the initial challenge.
bool InitFromChallenge(HttpAuth::ChallengeTokenizer* challenge,
@@ -46,7 +46,7 @@
// be made with a different nonce provided in the challenge.
//
// |challenge| must be non-NULL and have already tokenized the
- // authentication scheme, but none of the tokens occuring after the
+ // authentication scheme, but none of the tokens occurring after the
// authentication scheme.
virtual HttpAuth::AuthorizationResult HandleAnotherChallenge(
HttpAuth::ChallengeTokenizer* challenge) = 0;
@@ -73,7 +73,7 @@
// token, and the value of |*auth_token| is unspecified.
int GenerateAuthToken(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token);
// The authentication scheme as an enumerated value.
@@ -148,18 +148,18 @@
// Initializes the handler using a challenge issued by a server.
// |challenge| must be non-NULL and have already tokenized the
- // authentication scheme, but none of the tokens occuring after the
+ // authentication scheme, but none of the tokens occurring after the
// authentication scheme.
- // Implementations are expcted to initialize the following members:
+ // Implementations are expected to initialize the following members:
// scheme_, realm_, score_, properties_
virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) = 0;
// |GenerateAuthTokenImpl()} is the auth-scheme specific implementation
- // of generating the next auth token. Callers sohuld use |GenerateAuthToken()|
+ // of generating the next auth token. Callers should use |GenerateAuthToken()|
// which will in turn call |GenerateAuthTokenImpl()|
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) = 0;
// The auth-scheme as an enumerated value.
@@ -191,8 +191,7 @@
void OnGenerateAuthTokenComplete(int rv);
void FinishGenerateAuthToken();
- OldCompletionCallback* original_callback_;
- OldCompletionCallbackImpl<HttpAuthHandler> wrapper_callback_;
+ CompletionCallback callback_;
};
} // namespace net
diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc
index df24d0e..52396cc 100644
--- a/net/http/http_auth_handler_basic.cc
+++ b/net/http/http_auth_handler_basic.cc
@@ -86,10 +86,8 @@
}
int HttpAuthHandlerBasic::GenerateAuthTokenImpl(
- const AuthCredentials* credentials,
- const HttpRequestInfo*,
- OldCompletionCallback*,
- std::string* auth_token) {
+ const AuthCredentials* credentials, const HttpRequestInfo*,
+ const CompletionCallback&, std::string* auth_token) {
DCHECK(credentials);
// TODO(eroman): is this the right encoding of username/password?
std::string base64_username_password;
diff --git a/net/http/http_auth_handler_basic.h b/net/http/http_auth_handler_basic.h
index 7cb79c5..62d153e6 100644
--- a/net/http/http_auth_handler_basic.h
+++ b/net/http/http_auth_handler_basic.h
@@ -40,7 +40,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc
index b1e1a84..e8bf1d3 100644
--- a/net/http/http_auth_handler_basic_unittest.cc
+++ b/net/http/http_auth_handler_basic_unittest.cc
@@ -41,7 +41,7 @@
HttpRequestInfo request_info;
std::string auth_token;
int rv = basic->GenerateAuthToken(&credentials, &request_info,
- NULL, &auth_token);
+ CompletionCallback(), &auth_token);
EXPECT_EQ(OK, rv);
EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str());
}
diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc
index 2b5c026d..7ac8b1c 100644
--- a/net/http/http_auth_handler_digest.cc
+++ b/net/http/http_auth_handler_digest.cc
@@ -137,10 +137,8 @@
}
int HttpAuthHandlerDigest::GenerateAuthTokenImpl(
- const AuthCredentials* credentials,
- const HttpRequestInfo* request,
- OldCompletionCallback* callback,
- std::string* auth_token) {
+ const AuthCredentials* credentials, const HttpRequestInfo* request,
+ const CompletionCallback& callback, std::string* auth_token) {
// Generate a random client nonce.
std::string cnonce = nonce_generator_->GenerateNonce();
diff --git a/net/http/http_auth_handler_digest.h b/net/http/http_auth_handler_digest.h
index 03406a2d..e9607799 100644
--- a/net/http/http_auth_handler_digest.h
+++ b/net/http/http_auth_handler_digest.h
@@ -86,7 +86,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
diff --git a/net/http/http_auth_handler_digest_unittest.cc b/net/http/http_auth_handler_digest_unittest.cc
index 0bce2a4a3..c5549e71 100644
--- a/net/http/http_auth_handler_digest_unittest.cc
+++ b/net/http/http_auth_handler_digest_unittest.cc
@@ -63,13 +63,13 @@
// Create a token in response to the challenge.
// NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always
// completes synchronously. That's why this test can get away with a
- // TestOldCompletionCallback without an IO thread.
- TestOldCompletionCallback callback;
+ // TestCompletionCallback without an IO thread.
+ TestCompletionCallback callback;
scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo());
request->url = GURL(request_url);
AuthCredentials credentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
int rv_generate = handler->GenerateAuthToken(
- &credentials, request.get(), &callback, token);
+ &credentials, request.get(), callback.callback(), token);
if (rv_generate != OK) {
ADD_FAILURE() << "Problems generating auth token";
return false;
diff --git a/net/http/http_auth_handler_mock.cc b/net/http/http_auth_handler_mock.cc
index d90d823..8ed8f314 100644
--- a/net/http/http_auth_handler_mock.cc
+++ b/net/http/http_auth_handler_mock.cc
@@ -14,9 +14,10 @@
namespace net {
HttpAuthHandlerMock::HttpAuthHandlerMock()
- : resolve_(RESOLVE_INIT), user_callback_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)),
- generate_async_(false), generate_rv_(OK),
+ : resolve_(RESOLVE_INIT),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ generate_async_(false),
+ generate_rv_(OK),
auth_token_(NULL),
first_round_(true),
connection_based_(false),
@@ -46,8 +47,8 @@
}
}
-int HttpAuthHandlerMock::ResolveCanonicalName(HostResolver* host_resolver,
- OldCompletionCallback* callback) {
+int HttpAuthHandlerMock::ResolveCanonicalName(
+ HostResolver* host_resolver, const CompletionCallback& callback) {
EXPECT_NE(RESOLVE_TESTED, resolve_);
int rv = OK;
switch (resolve_) {
@@ -55,13 +56,13 @@
resolve_ = RESOLVE_TESTED;
break;
case RESOLVE_ASYNC:
- EXPECT_TRUE(user_callback_ == NULL);
+ EXPECT_TRUE(callback_.is_null());
rv = ERR_IO_PENDING;
- user_callback_ = callback;
+ callback_ = callback;
MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(
&HttpAuthHandlerMock::OnResolveCanonicalName,
- ptr_factory_.GetWeakPtr()));
+ weak_factory_.GetWeakPtr()));
break;
default:
NOTREACHED();
@@ -108,19 +109,19 @@
int HttpAuthHandlerMock::GenerateAuthTokenImpl(
const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) {
first_round_ = false;
request_url_ = request->url;
if (generate_async_) {
- EXPECT_TRUE(user_callback_ == NULL);
+ EXPECT_TRUE(callback_.is_null());
EXPECT_TRUE(auth_token_ == NULL);
- user_callback_ = callback;
+ callback_ = callback;
auth_token_ = auth_token;
MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(
&HttpAuthHandlerMock::OnGenerateAuthToken,
- ptr_factory_.GetWeakPtr()));
+ weak_factory_.GetWeakPtr()));
return ERR_IO_PENDING;
} else {
if (generate_rv_ == OK)
@@ -131,22 +132,22 @@
void HttpAuthHandlerMock::OnResolveCanonicalName() {
EXPECT_EQ(RESOLVE_ASYNC, resolve_);
- EXPECT_TRUE(user_callback_ != NULL);
+ EXPECT_TRUE(!callback_.is_null());
resolve_ = RESOLVE_TESTED;
- OldCompletionCallback* callback = user_callback_;
- user_callback_ = NULL;
- callback->Run(OK);
+ CompletionCallback callback = callback_;
+ callback_.Reset();
+ callback.Run(OK);
}
void HttpAuthHandlerMock::OnGenerateAuthToken() {
EXPECT_TRUE(generate_async_);
- EXPECT_TRUE(user_callback_ != NULL);
+ EXPECT_TRUE(!callback_.is_null());
if (generate_rv_ == OK)
*auth_token_ = "auth_token";
auth_token_ = NULL;
- OldCompletionCallback* callback = user_callback_;
- user_callback_ = NULL;
- callback->Run(generate_rv_);
+ CompletionCallback callback = callback_;
+ callback_.Reset();
+ callback.Run(generate_rv_);
}
HttpAuthHandlerMock::Factory::Factory()
diff --git a/net/http/http_auth_handler_mock.h b/net/http/http_auth_handler_mock.h
index 922a5cd..8992d2e 100644
--- a/net/http/http_auth_handler_mock.h
+++ b/net/http/http_auth_handler_mock.h
@@ -66,7 +66,7 @@
virtual bool NeedsCanonicalName();
virtual int ResolveCanonicalName(HostResolver* host_resolver,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
void SetGenerateExpectation(bool async, int rv);
@@ -99,7 +99,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
@@ -108,8 +108,8 @@
void OnGenerateAuthToken();
Resolve resolve_;
- OldCompletionCallback* user_callback_;
- base::WeakPtrFactory<HttpAuthHandlerMock> ptr_factory_;
+ CompletionCallback callback_;
+ base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_;
bool generate_async_;
int generate_rv_;
std::string* auth_token_;
diff --git a/net/http/http_auth_handler_negotiate.cc b/net/http/http_auth_handler_negotiate.cc
index 814cecd..cfab741 100644
--- a/net/http/http_auth_handler_negotiate.cc
+++ b/net/http/http_auth_handler_negotiate.cc
@@ -106,7 +106,6 @@
resolver_(resolver),
already_called_(false),
has_credentials_(false),
- user_callback_(NULL),
auth_token_(NULL),
next_state_(STATE_NONE),
url_security_manager_(url_security_manager) {
@@ -212,11 +211,9 @@
}
int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl(
- const AuthCredentials* credentials,
- const HttpRequestInfo* request,
- OldCompletionCallback* callback,
- std::string* auth_token) {
- DCHECK(user_callback_ == NULL);
+ const AuthCredentials* credentials, const HttpRequestInfo* request,
+ const CompletionCallback& callback, std::string* auth_token) {
+ DCHECK(callback_.is_null());
DCHECK(auth_token_ == NULL);
auth_token_ = auth_token;
if (already_called_) {
@@ -233,7 +230,7 @@
}
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
@@ -245,10 +242,10 @@
void HttpAuthHandlerNegotiate::DoCallback(int rv) {
DCHECK(rv != ERR_IO_PENDING);
- DCHECK(user_callback_);
- OldCompletionCallback* callback = user_callback_;
- user_callback_ = NULL;
- callback->Run(rv);
+ DCHECK(!callback_.is_null());
+ CompletionCallback callback = callback_;
+ callback_.Reset();
+ callback.Run(rv);
}
int HttpAuthHandlerNegotiate::DoLoop(int result) {
diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h
index 868d88aa6..9e00c3b 100644
--- a/net/http/http_auth_handler_negotiate.h
+++ b/net/http/http_auth_handler_negotiate.h
@@ -118,7 +118,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
@@ -156,7 +156,7 @@
std::wstring spn_;
// Things which vary each round.
- OldCompletionCallback* user_callback_;
+ CompletionCallback callback_;
std::string* auth_token_;
State next_state_;
diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc
index 4c013d21..f43e39a 100644
--- a/net/http/http_auth_handler_negotiate_unittest.cc
+++ b/net/http/http_auth_handler_negotiate_unittest.cc
@@ -220,11 +220,11 @@
true, false, true, "http://alias:500", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
- &callback, &token));
+ callback.callback(), &token));
#if defined(OS_WIN)
EXPECT_EQ(L"HTTP/alias", auth_handler->spn());
#elif defined(OS_POSIX)
@@ -238,11 +238,11 @@
EXPECT_EQ(OK, CreateHandler(
true, true, true, "http://alias:80", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
- &callback, &token));
+ callback.callback(), &token));
#if defined(OS_WIN)
EXPECT_EQ(L"HTTP/alias", auth_handler->spn());
#elif defined(OS_POSIX)
@@ -256,11 +256,11 @@
EXPECT_EQ(OK, CreateHandler(
true, true, true, "http://alias:500", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
- &callback, &token));
+ callback.callback(), &token));
#if defined(OS_WIN)
EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn());
#elif defined(OS_POSIX)
@@ -274,11 +274,11 @@
EXPECT_EQ(OK, CreateHandler(
false, false, true, "http://alias:500", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
- &callback, &token));
+ callback.callback(), &token));
#if defined(OS_WIN)
EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn());
#elif defined(OS_POSIX)
@@ -292,11 +292,11 @@
EXPECT_EQ(OK, CreateHandler(
false, false, false, "http://alias:500", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken(
- NULL, &request_info, &callback, &token));
+ NULL, &request_info, callback.callback(), &token));
EXPECT_EQ(OK, callback.WaitForResult());
#if defined(OS_WIN)
EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn());
@@ -315,11 +315,11 @@
EXPECT_EQ(OK, CreateHandler(
false, false, false, "http://alias:500", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken(
- NULL, &request_info, &callback, &token));
+ NULL, &request_info, callback.callback(), &token));
EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult());
}
@@ -331,11 +331,11 @@
EXPECT_EQ(OK, CreateHandler(
false, false, false, "http://alias:500", &auth_handler));
ASSERT_TRUE(auth_handler.get() != NULL);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
std::string token;
EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken(
- NULL, &request_info, &callback, &token));
+ NULL, &request_info, callback.callback(), &token));
EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult());
}
diff --git a/net/http/http_auth_handler_ntlm.cc b/net/http/http_auth_handler_ntlm.cc
index 3bbc045..964ae27 100644
--- a/net/http/http_auth_handler_ntlm.cc
+++ b/net/http/http_auth_handler_ntlm.cc
@@ -29,10 +29,8 @@
}
int HttpAuthHandlerNTLM::GenerateAuthTokenImpl(
- const AuthCredentials* credentials,
- const HttpRequestInfo* request,
- OldCompletionCallback* callback,
- std::string* auth_token) {
+ const AuthCredentials* credentials, const HttpRequestInfo* request,
+ const CompletionCallback& callback, std::string* auth_token) {
#if defined(NTLM_SSPI)
return auth_sspi_.GenerateAuthToken(
credentials,
diff --git a/net/http/http_auth_handler_ntlm.h b/net/http/http_auth_handler_ntlm.h
index 542fd822..eb87795 100644
--- a/net/http/http_auth_handler_ntlm.h
+++ b/net/http/http_auth_handler_ntlm.h
@@ -121,7 +121,7 @@
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
diff --git a/net/http/http_auth_handler_unittest.cc b/net/http/http_auth_handler_unittest.cc
index 011c6893..84809e1 100644
--- a/net/http/http_auth_handler_unittest.cc
+++ b/net/http/http_auth_handler_unittest.cc
@@ -29,7 +29,7 @@
for (int j = 0; j < 2; ++j) {
int rv = (j == 0) ? OK : ERR_UNEXPECTED;
for (int k = 0; k < 2; ++k) {
- TestOldCompletionCallback test_callback;
+ TestCompletionCallback test_callback;
HttpAuth::Target target =
(k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER;
NetLog::EventType event_type =
@@ -44,7 +44,7 @@
origin, bound_net_log);
mock_handler.SetGenerateExpectation(async, rv);
mock_handler.GenerateAuthToken(&credentials, &request,
- &test_callback, &auth_token);
+ test_callback.callback(), &auth_token);
if (async)
test_callback.WaitForResult();
diff --git a/net/http/http_basic_stream.cc b/net/http/http_basic_stream.cc
index 43b141a..621fdd5 100644
--- a/net/http/http_basic_stream.cc
+++ b/net/http/http_basic_stream.cc
@@ -33,9 +33,9 @@
HttpBasicStream::~HttpBasicStream() {}
-int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info,
- const BoundNetLog& net_log,
- OldCompletionCallback* callback) {
+int HttpBasicStream::InitializeStream(
+ const HttpRequestInfo* request_info, const BoundNetLog& net_log,
+ const CompletionCallback& callback) {
DCHECK(!parser_.get());
request_info_ = request_info;
parser_.reset(new HttpStreamParser(connection_.get(), request_info,
@@ -48,7 +48,7 @@
int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(parser_.get());
DCHECK(request_info_);
const std::string path = using_proxy_ ?
@@ -66,7 +66,7 @@
return parser_->GetUploadProgress();
}
-int HttpBasicStream::ReadResponseHeaders(OldCompletionCallback* callback) {
+int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) {
return parser_->ReadResponseHeaders(callback);
}
@@ -75,7 +75,7 @@
}
int HttpBasicStream::ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
return parser_->ReadResponseBody(buf, buf_len, callback);
}
diff --git a/net/http/http_basic_stream.h b/net/http/http_basic_stream.h
index 8024576..42693c87 100644
--- a/net/http/http_basic_stream.h
+++ b/net/http/http_basic_stream.h
@@ -42,21 +42,21 @@
// HttpStream methods:
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual uint64 GetUploadProgress() const OVERRIDE;
- virtual int ReadResponseHeaders(OldCompletionCallback* callback) OVERRIDE;
+ virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE;
virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual void Close(bool not_reusable) OVERRIDE;
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 1dcb368..a638326 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -163,7 +163,7 @@
if (entry_)
*entry_ = entry;
if (trans_)
- trans_->io_callback()->Run(result);
+ trans_->io_callback().Run(result);
}
// Notifies the caller about the operation completion. Returns true if the
@@ -231,12 +231,12 @@
class HttpCache::MetadataWriter {
public:
explicit MetadataWriter(HttpCache::Transaction* trans)
- : transaction_(trans),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_(this, &MetadataWriter::OnIOComplete)) {}
+ : transaction_(trans) {
+ }
+
~MetadataWriter() {}
- // Implementes the bulk of HttpCache::WriteMetadata.
+ // Implements the bulk of HttpCache::WriteMetadata.
void Write(const GURL& url, base::Time expected_response_time, IOBuffer* buf,
int buf_len);
@@ -250,7 +250,6 @@
scoped_refptr<IOBuffer> buf_;
int buf_len_;
base::Time expected_response_time_;
- OldCompletionCallbackImpl<MetadataWriter> callback_;
HttpRequestInfo request_info_;
DISALLOW_COPY_AND_ASSIGN(MetadataWriter);
};
@@ -270,7 +269,10 @@
buf_len_ = buf_len;
verified_ = false;
- int rv = transaction_->Start(&request_info_, &callback_, BoundNetLog());
+ int rv = transaction_->Start(
+ &request_info_,
+ base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)),
+ BoundNetLog());
if (rv != ERR_IO_PENDING)
VerifyResponse(rv);
}
@@ -907,7 +909,7 @@
// be added to a new entry.
while (!pending_queue.empty()) {
// ERR_CACHE_RACE causes the transaction to restart the whole process.
- pending_queue.front()->io_callback()->Run(ERR_CACHE_RACE);
+ pending_queue.front()->io_callback().Run(ERR_CACHE_RACE);
pending_queue.pop_front();
}
}
@@ -1051,7 +1053,7 @@
int rv = AddTransactionToEntry(entry, next);
if (rv != ERR_IO_PENDING) {
- next->io_callback()->Run(rv);
+ next->io_callback().Run(rv);
}
}
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 13ce79c..58ad27e5c 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -107,7 +107,6 @@
entry_(NULL),
new_entry_(NULL),
network_trans_(NULL),
- callback_(NULL),
new_response_(NULL),
mode_(NONE),
target_state_(STATE_NONE),
@@ -123,8 +122,8 @@
effective_load_flags_(0),
write_len_(0),
final_upload_progress_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &Transaction::OnIOComplete)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(
+ base::Bind(&Transaction::OnIOComplete, base::Unretained(this)))),
ALLOW_THIS_IN_INITIALIZER_LIST(
cache_callback_(new CancelableOldCompletionCallback<Transaction>(
this, &Transaction::OnIOComplete))),
@@ -139,7 +138,7 @@
HttpCache::Transaction::~Transaction() {
// We may have to issue another IO, but we should never invoke the callback_
// after this point.
- callback_ = NULL;
+ callback_.Reset();
if (cache_) {
if (entry_) {
@@ -218,13 +217,13 @@
}
int HttpCache::Transaction::Start(const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) {
DCHECK(request);
- DCHECK(callback);
+ DCHECK(!callback.is_null());
// Ensure that we only have one asynchronous call at a time.
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
DCHECK(!reading_);
DCHECK(!network_trans_.get());
DCHECK(!entry_);
@@ -247,11 +246,11 @@
}
int HttpCache::Transaction::RestartIgnoringLastError(
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
// Ensure that we only have one asynchronous call at a time.
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
if (!cache_)
return ERR_UNEXPECTED;
@@ -266,11 +265,11 @@
int HttpCache::Transaction::RestartWithCertificate(
X509Certificate* client_cert,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
// Ensure that we only have one asynchronous call at a time.
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
if (!cache_)
return ERR_UNEXPECTED;
@@ -285,12 +284,12 @@
int HttpCache::Transaction::RestartWithAuth(
const AuthCredentials& credentials,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(auth_response_.headers);
- DCHECK(callback);
+ DCHECK(!callback.is_null());
// Ensure that we only have one asynchronous call at a time.
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
if (!cache_)
return ERR_UNEXPECTED;
@@ -313,12 +312,12 @@
}
int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(buf);
DCHECK_GT(buf_len, 0);
- DCHECK(callback);
+ DCHECK(!callback.is_null());
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
if (!cache_)
return ERR_UNEXPECTED;
@@ -357,7 +356,7 @@
}
if (rv == ERR_IO_PENDING) {
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
callback_ = callback;
}
return rv;
@@ -415,18 +414,19 @@
void HttpCache::Transaction::DoCallback(int rv) {
DCHECK(rv != ERR_IO_PENDING);
- DCHECK(callback_);
+ DCHECK(!callback_.is_null());
// Since Run may result in Read being called, clear callback_ up front.
- OldCompletionCallback* c = callback_;
- callback_ = NULL;
- c->Run(rv);
+ CompletionCallback c = callback_;
+ callback_.Reset();
+ c.Run(rv);
}
int HttpCache::Transaction::HandleResult(int rv) {
DCHECK(rv != ERR_IO_PENDING);
- if (callback_)
+ if (!callback_.is_null())
DoCallback(rv);
+
return rv;
}
@@ -722,7 +722,7 @@
return rv;
next_state_ = STATE_SEND_REQUEST_COMPLETE;
- rv = network_trans_->Start(request_, &io_callback_, net_log_);
+ rv = network_trans_->Start(request_, io_callback_, net_log_);
return rv;
}
@@ -798,7 +798,7 @@
int HttpCache::Transaction::DoNetworkRead() {
next_state_ = STATE_NETWORK_READ_COMPLETE;
- return network_trans_->Read(read_buf_, io_buf_len_, &io_callback_);
+ return network_trans_->Read(read_buf_, io_buf_len_, io_callback_);
}
int HttpCache::Transaction::DoNetworkReadComplete(int result) {
@@ -990,7 +990,7 @@
return OK;
next_state_ = STATE_COMPLETE_PARTIAL_CACHE_VALIDATION;
- return partial_->ShouldValidateCache(entry_->disk_entry, &io_callback_);
+ return partial_->ShouldValidateCache(entry_->disk_entry, io_callback_);
}
int HttpCache::Transaction::DoCompletePartialCacheValidation(int result) {
@@ -1682,7 +1682,7 @@
DCHECK_EQ(STATE_NONE, next_state_);
next_state_ = STATE_SEND_REQUEST_COMPLETE;
- int rv = network_trans_->RestartIgnoringLastError(&io_callback_);
+ int rv = network_trans_->RestartIgnoringLastError(io_callback_);
if (rv != ERR_IO_PENDING)
return DoLoop(rv);
return rv;
@@ -1695,7 +1695,7 @@
DCHECK_EQ(STATE_NONE, next_state_);
next_state_ = STATE_SEND_REQUEST_COMPLETE;
- int rv = network_trans_->RestartWithCertificate(client_cert, &io_callback_);
+ int rv = network_trans_->RestartWithCertificate(client_cert, io_callback_);
if (rv != ERR_IO_PENDING)
return DoLoop(rv);
return rv;
@@ -1708,7 +1708,7 @@
DCHECK_EQ(STATE_NONE, next_state_);
next_state_ = STATE_SEND_REQUEST_COMPLETE;
- int rv = network_trans_->RestartWithAuth(credentials, &io_callback_);
+ int rv = network_trans_->RestartWithAuth(credentials, io_callback_);
if (rv != ERR_IO_PENDING)
return DoLoop(rv);
return rv;
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index f60a445..7629c0b7 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -93,23 +93,24 @@
// to the cache entry.
LoadState GetWriterLoadState() const;
- OldCompletionCallback* io_callback() { return &io_callback_; }
+ const CompletionCallback& io_callback() { return io_callback_; }
const BoundNetLog& net_log() const;
// HttpTransaction methods:
- virtual int Start(const HttpRequestInfo*, OldCompletionCallback*,
+ virtual int Start(const HttpRequestInfo*, const CompletionCallback&,
const BoundNetLog&) OVERRIDE;
virtual int RestartIgnoringLastError(
- OldCompletionCallback* callback) OVERRIDE;
- virtual int RestartWithCertificate(X509Certificate* client_cert,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
+ virtual int RestartWithCertificate(
+ X509Certificate* client_cert,
+ const CompletionCallback& callback) OVERRIDE;
virtual int RestartWithAuth(const AuthCredentials& credentials,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual bool IsReadyToRestartForAuth() OVERRIDE;
virtual int Read(IOBuffer* buf,
int buf_len,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual void StopCaching() OVERRIDE;
virtual void DoneReading() OVERRIDE;
virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
@@ -338,7 +339,7 @@
base::TimeTicks entry_lock_waiting_since_;
HttpCache::ActiveEntry* new_entry_;
scoped_ptr<HttpTransaction> network_trans_;
- OldCompletionCallback* callback_; // Consumer's callback.
+ CompletionCallback callback_; // Consumer's callback.
HttpResponseInfo response_;
HttpResponseInfo auth_response_;
const HttpResponseInfo* new_response_;
@@ -360,7 +361,7 @@
int write_len_;
scoped_ptr<PartialData> partial_; // We are dealing with range requests.
uint64 final_upload_progress_;
- OldCompletionCallbackImpl<Transaction> io_callback_;
+ CompletionCallback io_callback_;
scoped_refptr<CancelableOldCompletionCallback<Transaction> > cache_callback_;
scoped_refptr<CancelableOldCompletionCallback<Transaction> >
write_headers_callback_;
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 2ffa866..1c8363e 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -74,7 +74,7 @@
const MockHttpRequest& request,
net::HttpResponseInfo* response_info,
const net::BoundNetLog& net_log) {
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
// write to the cache
@@ -83,7 +83,7 @@
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net_log);
+ rv = trans->Start(&request, callback.callback(), net_log);
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::OK, rv);
@@ -382,7 +382,7 @@
Context() : result(net::ERR_IO_PENDING) {}
int result;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
};
@@ -503,7 +503,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
rv = c->callback.WaitForResult();
@@ -549,7 +549,7 @@
EXPECT_EQ(net::OK, rv);
MockHttpRequest request(kSimpleGET_Transaction);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::ERR_CACHE_READ_FAILURE, c->callback.GetResult(rv));
}
@@ -629,14 +629,14 @@
transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
MockHttpRequest request(transaction);
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::ERR_CACHE_MISS, rv);
@@ -862,7 +862,8 @@
EXPECT_EQ(net::OK, c->result);
EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState());
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
}
// All requests are waiting for the active entry.
@@ -932,7 +933,8 @@
if (i == 1 || i == 2)
this_request = &reader_request;
- c->result = c->trans->Start(this_request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ this_request, c->callback.callback(), net::BoundNetLog());
}
// Allow all requests to move from the Create queue to the active entry.
@@ -1016,7 +1018,8 @@
if (i == 3)
this_request = &writer_request;
- c->result = c->trans->Start(this_request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ this_request, c->callback.callback(), net::BoundNetLog());
}
// The first request should be a writer at this point, and the two subsequent
@@ -1059,7 +1062,8 @@
c->result = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
}
// Allow all requests to move from the Create queue to the active entry.
@@ -1105,7 +1109,8 @@
c->result = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
}
// Allow all requests to move from the Create queue to the active entry.
@@ -1164,7 +1169,8 @@
c->result = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
}
// The first request should be creating the disk cache entry and the others
@@ -1214,11 +1220,12 @@
c->result = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::ERR_IO_PENDING, c->result);
// Release the reference that the mock disk cache keeps for this entry, so
- // that we test that the http cache handles the cancelation correctly.
+ // that we test that the http cache handles the cancellation correctly.
cache.disk_cache()->ReleaseAll();
delete c;
@@ -1243,7 +1250,8 @@
c->result = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
}
// The first request should be deleting the disk cache entry and the others
@@ -1278,18 +1286,18 @@
RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
MockHttpRequest request(kSimpleGET_Transaction);
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::OK, rv);
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
// Test that destroying the transaction while it is reading from the cache
@@ -1319,7 +1327,8 @@
c->result = cache->http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->result = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
}
// The first request should be creating the disk cache entry and the others
@@ -1359,11 +1368,11 @@
}
context_list[0]->result = context_list[0]->trans->Start(
- &request0, &context_list[0]->callback, net::BoundNetLog());
+ &request0, context_list[0]->callback.callback(), net::BoundNetLog());
context_list[1]->result = context_list[1]->trans->Start(
- &request1, &context_list[1]->callback, net::BoundNetLog());
+ &request1, context_list[1]->callback.callback(), net::BoundNetLog());
context_list[2]->result = context_list[2]->trans->Start(
- &request2, &context_list[2]->callback, net::BoundNetLog());
+ &request2, context_list[2]->callback.callback(), net::BoundNetLog());
// Just to make sure that everything is still pending.
MessageLoop::current()->RunAllPending();
@@ -1405,11 +1414,11 @@
}
context_list[0]->result = context_list[0]->trans->Start(
- &request0, &context_list[0]->callback, net::BoundNetLog());
+ &request0, context_list[0]->callback.callback(), net::BoundNetLog());
context_list[1]->result = context_list[1]->trans->Start(
- &request1, &context_list[1]->callback, net::BoundNetLog());
+ &request1, context_list[1]->callback.callback(), net::BoundNetLog());
context_list[2]->result = context_list[2]->trans->Start(
- &request2, &context_list[2]->callback, net::BoundNetLog());
+ &request2, context_list[2]->callback.callback(), net::BoundNetLog());
// Just to make sure that everything is still pending.
MessageLoop::current()->RunAllPending();
@@ -1449,7 +1458,7 @@
c->result = cache->http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
// Just to make sure that everything is still pending.
MessageLoop::current()->RunAllPending();
@@ -1487,7 +1496,7 @@
c->result = cache->http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, c->result);
- c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
// And another direct backend request.
net::TestCompletionCallback cb2;
@@ -2172,14 +2181,14 @@
transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
MockHttpRequest request(transaction);
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::ERR_CACHE_MISS, rv);
@@ -3084,7 +3093,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
@@ -3094,7 +3103,7 @@
// Make sure that the entry has some data stored.
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
EXPECT_EQ(buf->size(), rv);
@@ -3123,7 +3132,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
@@ -3134,9 +3143,9 @@
// Make sure that we revalidate the entry and read from the cache (a single
// read will return while waiting for the network).
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
EXPECT_EQ(5, c->callback.GetResult(rv));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
// Destroy the transaction before completing the read.
@@ -3168,7 +3177,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
rv = c->callback.WaitForResult();
@@ -3179,9 +3188,9 @@
// Make sure that we revalidate the entry and read from the cache (a single
// read will return while waiting for the network).
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
EXPECT_EQ(5, c->callback.GetResult(rv));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
// Destroy the transaction before completing the read.
@@ -3195,7 +3204,7 @@
rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
MockDiskEntry::IgnoreCallbacks(true);
@@ -3470,14 +3479,14 @@
transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
MockHttpRequest request(transaction);
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::ERR_CACHE_MISS, rv);
@@ -3554,7 +3563,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
c->result = c->callback.WaitForResult();
@@ -3584,7 +3593,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
@@ -3594,7 +3603,7 @@
// Make sure that the entry has some data stored.
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
EXPECT_EQ(buf->size(), rv);
@@ -3627,7 +3636,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
@@ -3637,7 +3646,7 @@
// Make sure that the entry has some data stored.
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
EXPECT_EQ(buf->size(), rv);
@@ -3670,7 +3679,7 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
@@ -3680,13 +3689,13 @@
// Make sure that the entry has some data stored.
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(10));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = c->callback.WaitForResult();
EXPECT_EQ(buf->size(), rv);
// We want to cancel the request when the transaction is busy.
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
EXPECT_FALSE(c->callback.have_result());
@@ -3730,12 +3739,12 @@
int rv = cache.http_cache()->CreateTransaction(&c->trans);
EXPECT_EQ(net::OK, rv);
- rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, c->callback.GetResult(rv));
// Read everything.
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(22));
- rv = c->trans->Read(buf, buf->size(), &c->callback);
+ rv = c->trans->Read(buf, buf->size(), c->callback.callback());
EXPECT_EQ(buf->size(), c->callback.GetResult(rv));
// Destroy the transaction.
@@ -3861,7 +3870,8 @@
EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
MockHttpRequest request(transaction);
- int rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ int rv = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, c->callback.GetResult(rv));
// We should have checked with the server before finishing Start().
@@ -3931,14 +3941,15 @@
Context* c = new Context();
EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
- int rv = c->trans->Start(&request, &c->callback, net::BoundNetLog());
+ int rv = c->trans->Start(
+ &request, c->callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, c->callback.GetResult(rv));
// Read 20 bytes from the cache, and 10 from the net.
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100));
- rv = c->trans->Read(buf, 20, &c->callback);
+ rv = c->trans->Read(buf, 20, c->callback.callback());
EXPECT_EQ(20, c->callback.GetResult(rv));
- rv = c->trans->Read(buf, 10, &c->callback);
+ rv = c->trans->Read(buf, 10, c->callback.callback());
EXPECT_EQ(10, c->callback.GetResult(rv));
// At this point, we are already reading so canceling the request should leave
@@ -4051,7 +4062,7 @@
kTestTransaction.response_headers = "Location: http://www.bar.com/\n";
MockHttpRequest request(kTestTransaction);
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
// write to the cache
{
@@ -4060,7 +4071,7 @@
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::OK, rv);
@@ -4088,7 +4099,7 @@
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::OK, rv);
@@ -4206,14 +4217,14 @@
transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
MockHttpRequest request(transaction);
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
ASSERT_TRUE(trans.get());
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(net::ERR_CACHE_MISS, rv);
@@ -4458,7 +4469,7 @@
// of the stream.
TEST(HttpCache, FilterCompletion) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
{
scoped_ptr<net::HttpTransaction> trans;
@@ -4466,11 +4477,11 @@
EXPECT_EQ(net::OK, rv);
MockHttpRequest request(kSimpleGET_Transaction);
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, callback.GetResult(rv));
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
// Now make sure that the entry is preserved.
@@ -4491,7 +4502,7 @@
// Tests that we stop cachining when told.
TEST(HttpCache, StopCachingDeletesEntry) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
MockHttpRequest request(kSimpleGET_Transaction);
{
@@ -4499,19 +4510,19 @@
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, callback.GetResult(rv));
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
- rv = trans->Read(buf, 10, &callback);
+ rv = trans->Read(buf, 10, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 10);
trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 0);
}
@@ -4529,7 +4540,7 @@
// Tests that when we are told to stop caching we don't throw away valid data.
TEST(HttpCache, StopCachingSavesEntry) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
MockHttpRequest request(kSimpleGET_Transaction);
{
@@ -4544,19 +4555,19 @@
"Content-Length: 42\n"
"Etag: foo\n";
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, callback.GetResult(rv));
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
- rv = trans->Read(buf, 10, &callback);
+ rv = trans->Read(buf, 10, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 10);
trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 0);
RemoveMockTransaction(&mock_transaction);
@@ -4575,7 +4586,7 @@
// Tests that we handle truncated enries when StopCaching is called.
TEST(HttpCache, StopCachingTruncatedEntry) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
MockHttpRequest request(kRangeGET_TransactionOK);
request.extra_headers.Clear();
request.extra_headers.AddHeaderFromString(EXTRA_HEADER);
@@ -4594,22 +4605,22 @@
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
- rv = trans->Start(&request, &callback, net::BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
EXPECT_EQ(net::OK, callback.GetResult(rv));
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
- rv = trans->Read(buf, 10, &callback);
+ rv = trans->Read(buf, 10, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 10);
// This is actually going to do nothing.
trans->StopCaching();
// We should be able to keep reading.
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_GT(callback.GetResult(rv), 0);
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
EXPECT_EQ(callback.GetResult(rv), 0);
}
@@ -4630,7 +4641,7 @@
// a Content-Length header.
TEST(HttpCache, TruncatedByContentLength) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
MockTransaction transaction(kSimpleGET_Transaction);
AddMockTransaction(&transaction);
@@ -4651,7 +4662,7 @@
// from the net.
TEST(HttpCache, TruncatedByContentLength2) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
MockTransaction transaction(kSimpleGET_Transaction);
AddMockTransaction(&transaction);
diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc
index b598e8e..99c9bc3 100644
--- a/net/http/http_network_layer_unittest.cc
+++ b/net/http/http_network_layer_unittest.cc
@@ -89,7 +89,7 @@
data_writes, arraysize(data_writes));
mock_socket_factory_.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request_info;
request_info.url = GURL("http://www.google.com/");
@@ -102,7 +102,7 @@
int rv = factory_->CreateTransaction(&trans);
EXPECT_EQ(OK, rv);
- rv = trans->Start(&request_info, &callback, BoundNetLog());
+ rv = trans->Start(&request_info, callback.callback(), BoundNetLog());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(OK, rv);
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index a557c87..631434df 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -7,6 +7,8 @@
#include <set>
#include <vector>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/format_macros.h"
#include "base/memory/scoped_ptr.h"
@@ -96,9 +98,9 @@
HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session)
: pending_auth_target_(HttpAuth::AUTH_NONE),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &HttpNetworkTransaction::OnIOComplete)),
- user_callback_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(
+ base::Bind(&HttpNetworkTransaction::OnIOComplete,
+ base::Unretained(this)))),
session_(session),
request_(NULL),
headers_valid_(false),
@@ -144,7 +146,7 @@
}
int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) {
SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count");
@@ -160,12 +162,12 @@
next_state_ = STATE_CREATE_STREAM;
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
int HttpNetworkTransaction::RestartIgnoringLastError(
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(!stream_.get());
DCHECK(!stream_request_.get());
DCHECK_EQ(STATE_NONE, next_state_);
@@ -174,13 +176,12 @@
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
int HttpNetworkTransaction::RestartWithCertificate(
- X509Certificate* client_cert,
- OldCompletionCallback* callback) {
+ X509Certificate* client_cert, const CompletionCallback& callback) {
// In HandleCertificateRequest(), we always tear down existing stream
// requests to force a new connection. So we shouldn't have one here.
DCHECK(!stream_request_.get());
@@ -199,12 +200,12 @@
next_state_ = STATE_CREATE_STREAM;
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
-int HttpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials,
- OldCompletionCallback* callback) {
+int HttpNetworkTransaction::RestartWithAuth(
+ const AuthCredentials& credentials, const CompletionCallback& callback) {
HttpAuth::Target target = pending_auth_target_;
if (target == HttpAuth::AUTH_NONE) {
NOTREACHED();
@@ -214,7 +215,7 @@
auth_controllers_[target]->ResetAuth(credentials);
- DCHECK(user_callback_ == NULL);
+ DCHECK(callback_.is_null());
int rv = OK;
if (target == HttpAuth::AUTH_PROXY && establishing_tunnel_) {
@@ -234,7 +235,7 @@
}
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
@@ -297,7 +298,7 @@
}
int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(buf);
DCHECK_LT(0, buf_len);
@@ -331,7 +332,7 @@
next_state_ = next_state;
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
@@ -469,12 +470,12 @@
void HttpNetworkTransaction::DoCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
- DCHECK(user_callback_);
+ DCHECK(!callback_.is_null());
// Since Run may result in Read being called, clear user_callback_ up front.
- OldCompletionCallback* c = user_callback_;
- user_callback_ = NULL;
- c->Run(rv);
+ CompletionCallback c = callback_;
+ callback_.Reset();
+ c.Run(rv);
}
void HttpNetworkTransaction::OnIOComplete(int result) {
@@ -615,7 +616,7 @@
int HttpNetworkTransaction::DoInitStream() {
DCHECK(stream_.get());
next_state_ = STATE_INIT_STREAM_COMPLETE;
- return stream_->InitializeStream(request_, net_log_, &io_callback_);
+ return stream_->InitializeStream(request_, net_log_, io_callback_);
}
int HttpNetworkTransaction::DoInitStreamComplete(int result) {
@@ -644,7 +645,7 @@
session_->http_auth_cache(),
session_->http_auth_handler_factory());
return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
- &io_callback_,
+ io_callback_,
net_log_);
}
@@ -667,7 +668,7 @@
if (!ShouldApplyServerAuth())
return OK;
return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
- &io_callback_,
+ io_callback_,
net_log_);
}
@@ -761,7 +762,7 @@
next_state_ = STATE_SEND_REQUEST_COMPLETE;
return stream_->SendRequest(
- request_headers_, request_body_.release(), &response_, &io_callback_);
+ request_headers_, request_body_.release(), &response_, io_callback_);
}
int HttpNetworkTransaction::DoSendRequestComplete(int result) {
@@ -773,7 +774,7 @@
int HttpNetworkTransaction::DoReadHeaders() {
next_state_ = STATE_READ_HEADERS_COMPLETE;
- return stream_->ReadResponseHeaders(&io_callback_);
+ return stream_->ReadResponseHeaders(io_callback_);
}
int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() {
@@ -878,7 +879,7 @@
DCHECK(stream_ != NULL);
next_state_ = STATE_READ_BODY_COMPLETE;
- return stream_->ReadResponseBody(read_buf_, read_buf_len_, &io_callback_);
+ return stream_->ReadResponseBody(read_buf_, read_buf_len_, io_callback_);
}
int HttpNetworkTransaction::DoReadBodyComplete(int result) {
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 21bf421..7ad9f7e3 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -43,19 +43,20 @@
// HttpTransaction methods:
virtual int Start(const HttpRequestInfo* request_info,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
virtual int RestartIgnoringLastError(
- OldCompletionCallback* callback) OVERRIDE;
- virtual int RestartWithCertificate(X509Certificate* client_cert,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
+ virtual int RestartWithCertificate(
+ X509Certificate* client_cert,
+ const CompletionCallback& callback) OVERRIDE;
virtual int RestartWithAuth(const AuthCredentials& credentials,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual bool IsReadyToRestartForAuth() OVERRIDE;
virtual int Read(IOBuffer* buf,
int buf_len,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual void StopCaching() OVERRIDE {}
virtual void DoneReading() OVERRIDE {}
virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
@@ -227,8 +228,8 @@
// cleared by RestartWithAuth().
HttpAuth::Target pending_auth_target_;
- OldCompletionCallbackImpl<HttpNetworkTransaction> io_callback_;
- OldCompletionCallback* user_callback_;
+ CompletionCallback io_callback_;
+ CompletionCallback callback_;
scoped_ptr<UploadDataStream> request_body_;
scoped_refptr<HttpNetworkSession> session_;
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index c86033a..cca2f8e 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -198,11 +198,11 @@
session_deps.socket_factory.AddSocketDataProvider(data[i]);
}
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
EXPECT_TRUE(log.bound().IsLoggingAllEvents());
- int rv = trans->Start(&request, &callback, log.bound());
+ int rv = trans->Start(&request, callback.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
out.rv = callback.WaitForResult();
@@ -316,7 +316,7 @@
const void* socket_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) {
last_group_name_ = group_name;
return ERR_IO_PENDING;
@@ -720,9 +720,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -794,9 +794,9 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -851,9 +851,9 @@
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -893,9 +893,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -935,9 +935,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -972,9 +972,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1002,9 +1002,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1064,11 +1064,11 @@
};
for (int i = 0; i < 2; ++i) {
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1121,9 +1121,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1198,11 +1198,11 @@
std::string response_lines[kNumUnreadBodies];
for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) {
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1233,9 +1233,9 @@
for (int i = 0; i < kNumUnreadBodies; ++i)
EXPECT_EQ(kStatusLines[i], response_lines[i]);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -1304,9 +1304,9 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1316,9 +1316,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1358,9 +1359,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads),
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1422,10 +1423,10 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1435,9 +1436,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1497,10 +1499,10 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1510,9 +1512,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1580,10 +1583,10 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1593,9 +1596,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1665,10 +1669,10 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1678,9 +1682,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1747,11 +1752,11 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1773,9 +1778,10 @@
EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1849,9 +1855,9 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -1875,10 +1881,11 @@
EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
// Wrong password (should be "bar").
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBaz), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -1932,9 +1939,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1987,9 +1994,9 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -2039,11 +2046,11 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2092,11 +2099,11 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2155,11 +2162,11 @@
ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2;
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2242,11 +2249,11 @@
ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2;
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2260,9 +2267,10 @@
EXPECT_TRUE(response->was_fetched_via_spdy);
EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -2340,9 +2348,9 @@
ssl2.protocol_negotiated = SSLClientSocket::kProtoUnknown;
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2417,9 +2425,9 @@
ssl2.protocol_negotiated = SSLClientSocket::kProtoSPDY2;
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2486,9 +2494,9 @@
ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2;
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2549,11 +2557,11 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2566,9 +2574,10 @@
EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -2616,11 +2625,11 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -2880,9 +2889,9 @@
session_deps.socket_factory.AddSocketDataProvider(&data2);
session_deps.socket_factory.AddSocketDataProvider(&data3);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -2892,9 +2901,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -2904,9 +2914,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback3;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), &callback3);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo2, kBar2), callback3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback3.WaitForResult();
@@ -3009,11 +3020,11 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -3025,10 +3036,10 @@
ASSERT_FALSE(response == NULL);
EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
- &callback2);
+ callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -3040,9 +3051,9 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(response->auth_challenge.get() == NULL);
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback3;
- rv = trans->RestartWithAuth(AuthCredentials(), &callback3);
+ rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback3.WaitForResult();
@@ -3189,11 +3200,11 @@
session_deps.socket_factory.AddSocketDataProvider(&data2);
session_deps.socket_factory.AddSocketDataProvider(&data3);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -3205,19 +3216,19 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
// Enter the wrong password.
rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword),
- &callback2);
+ callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
EXPECT_EQ(OK, rv);
EXPECT_TRUE(trans->IsReadyToRestartForAuth());
- TestOldCompletionCallback callback3;
- rv = trans->RestartWithAuth(AuthCredentials(), &callback3);
+ TestCompletionCallback callback3;
+ rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback3.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3227,11 +3238,11 @@
ASSERT_FALSE(response == NULL);
EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback4;
+ TestCompletionCallback callback4;
// Now enter the right password.
rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
- &callback4);
+ callback4.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback4.WaitForResult();
@@ -3239,10 +3250,10 @@
EXPECT_TRUE(trans->IsReadyToRestartForAuth());
- TestOldCompletionCallback callback5;
+ TestCompletionCallback callback5;
// One more roundtrip
- rv = trans->RestartWithAuth(AuthCredentials(), &callback5);
+ rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback5.WaitForResult();
@@ -3280,9 +3291,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -3328,9 +3339,9 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -3377,9 +3388,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -3436,12 +3447,12 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -3504,12 +3515,12 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -3537,7 +3548,7 @@
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request, &callback, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -3588,9 +3599,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -3684,9 +3695,9 @@
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request[i], &callback, BoundNetLog());
+ int rv = trans->Start(&request[i], callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -3759,17 +3770,17 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
EXPECT_EQ(OK, rv);
EXPECT_TRUE(trans->IsReadyToRestartForAuth());
- TestOldCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(), &callback2);
+ TestCompletionCallback callback2;
+ rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3857,17 +3868,17 @@
session_deps.socket_factory.AddSocketDataProvider(&data2);
session_deps.socket_factory.AddSocketDataProvider(&data3);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
EXPECT_EQ(OK, rv);
EXPECT_TRUE(trans->IsReadyToRestartForAuth());
- TestOldCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(), &callback2);
+ TestCompletionCallback callback2;
+ rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3877,8 +3888,9 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback3;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback3);
+ TestCompletionCallback callback3;
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback3.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3945,9 +3957,9 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -3957,9 +3969,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -4023,9 +4036,9 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -4040,9 +4053,10 @@
EXPECT_EQ("MyRealm2", response->auth_challenge->realm);
EXPECT_EQ("basic", response->auth_challenge->scheme);
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo2, kBar2), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -4086,9 +4100,9 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -4148,17 +4162,17 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
EXPECT_EQ(OK, rv);
EXPECT_TRUE(trans->IsReadyToRestartForAuth());
- TestOldCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(), &callback2);
+ TestCompletionCallback callback2;
+ rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -4237,17 +4251,17 @@
session_deps.socket_factory.AddSocketDataProvider(&data2);
session_deps.socket_factory.AddSocketDataProvider(&data3);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
EXPECT_EQ(OK, rv);
EXPECT_TRUE(trans->IsReadyToRestartForAuth());
- TestOldCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(), &callback2);
+ TestCompletionCallback callback2;
+ rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -4257,9 +4271,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback3;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo3, kBar3), &callback3);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo3, kBar3), callback3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback3.WaitForResult();
@@ -4330,9 +4345,9 @@
session_deps.socket_factory.AddSocketDataProvider(&data1);
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -4342,9 +4357,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -4391,9 +4407,9 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -4483,15 +4499,15 @@
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_bad);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
- rv = trans->RestartIgnoringLastError(&callback);
+ rv = trans->RestartIgnoringLastError(callback.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4554,7 +4570,7 @@
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_bad);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
for (int i = 0; i < 2; i++) {
session_deps.socket_factory.ResetNextMockIndexes();
@@ -4562,13 +4578,13 @@
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
- rv = trans->RestartIgnoringLastError(&callback);
+ rv = trans->RestartIgnoringLastError(callback.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4618,12 +4634,12 @@
session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl);
session_deps.socket_factory.AddSSLSocketDataProvider(&tunnel_ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4668,12 +4684,12 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4730,12 +4746,12 @@
session_deps.socket_factory.AddSocketDataProvider(data.get());
session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4780,12 +4796,12 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4850,12 +4866,12 @@
session_deps.socket_factory.AddSocketDataProvider(data.get());
session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4931,18 +4947,18 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
- rv = trans->RestartIgnoringLastError(&callback);
+ rv = trans->RestartIgnoringLastError(callback.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4984,9 +5000,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5022,9 +5038,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5062,9 +5078,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5099,9 +5115,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5136,9 +5152,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5173,9 +5189,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5212,9 +5228,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5251,9 +5267,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5289,9 +5305,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5331,9 +5347,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5374,9 +5390,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5430,9 +5446,9 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5495,9 +5511,9 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5565,9 +5581,9 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5614,10 +5630,10 @@
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
// We do not complete this request, the dtor will clean the transaction up.
- return trans->Start(&request, &callback, BoundNetLog());
+ return trans->Start(&request, callback.callback(), BoundNetLog());
}
TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) {
@@ -5837,9 +5853,9 @@
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5866,7 +5882,6 @@
// Warm up the host cache so it has an entry for "www.google.com".
AddressList addrlist;
TestCompletionCallback callback;
- TestOldCompletionCallback old_callback;
int rv = session_deps.host_resolver->Resolve(
HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), &addrlist,
callback.callback(), NULL, BoundNetLog());
@@ -5893,9 +5908,9 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
// Run the request.
- rv = trans->Start(&request, &old_callback, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
ASSERT_EQ(ERR_IO_PENDING, rv);
- rv = old_callback.WaitForResult();
+ rv = callback.WaitForResult();
// If we bypassed the cache, we would have gotten a failure while resolving
// "www.google.com".
@@ -5933,12 +5948,12 @@
write_failure, arraysize(write_failure));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5963,12 +5978,12 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -6037,11 +6052,11 @@
data_writes2, arraysize(data_writes2));
session_deps.socket_factory.AddSocketDataProvider(&data2);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -6051,9 +6066,10 @@
ASSERT_TRUE(response != NULL);
EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -6085,14 +6101,14 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
session_deps.socket_factory.ResetNextMockIndexes();
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -6117,9 +6133,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6166,9 +6182,9 @@
StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -6229,9 +6245,9 @@
arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -6297,9 +6313,9 @@
arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -6314,9 +6330,10 @@
// Now make the file unreadable and try again.
ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file));
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback2);
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
@@ -6414,7 +6431,7 @@
session_deps.socket_factory.AddSocketDataProvider(&data3);
session_deps.socket_factory.AddSocketDataProvider(&data4);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));
@@ -6422,7 +6439,7 @@
// Issue the first request with Authorize headers. There should be a
// password prompt for first_realm waiting to be filled in after the
// transaction completes.
- int rv = trans->Start(&request, &callback1, BoundNetLog());
+ int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -6438,8 +6455,9 @@
// Issue the second request with an incorrect password. There should be a
// password prompt for second_realm waiting to be filled in after the
// transaction completes.
- TestOldCompletionCallback callback2;
- rv = trans->RestartWithAuth(AuthCredentials(kFirst, kBaz), &callback2);
+ TestCompletionCallback callback2;
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFirst, kBaz), callback2.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback2.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -6456,8 +6474,9 @@
// a password prompt for first_realm waiting to be filled in. If the password
// prompt is not present, it indicates that the HttpAuthCacheEntry for
// first_realm was not correctly removed.
- TestOldCompletionCallback callback3;
- rv = trans->RestartWithAuth(AuthCredentials(kSecond, kFou), &callback3);
+ TestCompletionCallback callback3;
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kSecond, kFou), callback3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback3.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -6471,8 +6490,9 @@
EXPECT_EQ("basic", challenge->scheme);
// Issue the fourth request with the correct password and username.
- TestOldCompletionCallback callback4;
- rv = trans->RestartWithAuth(AuthCredentials(kFirst, kBar), &callback4);
+ TestCompletionCallback callback4;
+ rv = trans->RestartWithAuth(
+ AuthCredentials(kFirst, kBar), callback4.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback4.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -6503,12 +6523,12 @@
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
HostPortPair http_host_port_pair("www.google.com", 80);
@@ -6577,9 +6597,9 @@
NPN_SPDY_2);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6639,9 +6659,10 @@
NPN_SPDY_2);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&restricted_port_request, &callback, BoundNetLog());
+ int rv = trans->Start(
+ &restricted_port_request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Invalid change to unrestricted port should fail.
EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
@@ -6687,9 +6708,10 @@
NPN_SPDY_2);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&restricted_port_request, &callback, BoundNetLog());
+ int rv = trans->Start(
+ &restricted_port_request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Valid change to restricted port should pass.
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6735,9 +6757,10 @@
NPN_SPDY_2);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&unrestricted_port_request, &callback, BoundNetLog());
+ int rv = trans->Start(
+ &unrestricted_port_request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Valid change to restricted port should pass.
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6783,9 +6806,10 @@
NPN_SPDY_2);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&unrestricted_port_request, &callback, BoundNetLog());
+ int rv = trans->Start(
+ &unrestricted_port_request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Valid change to an unrestricted port should pass.
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6847,12 +6871,12 @@
session_deps.socket_factory.AddSocketDataProvider(
&hanging_non_alternate_protocol_socket);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6867,7 +6891,7 @@
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request, &callback, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -6953,10 +6977,10 @@
session_deps.socket_factory.AddSocketDataProvider(&hanging_socket);
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
HttpNetworkTransaction trans1(session);
- int rv = trans1.Start(&request, &callback1, BoundNetLog());
+ int rv = trans1.Start(&request, callback1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback1.WaitForResult());
@@ -6969,14 +6993,14 @@
ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
EXPECT_EQ("hello world", response_data);
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
HttpNetworkTransaction trans2(session);
- rv = trans2.Start(&request, &callback2, BoundNetLog());
+ rv = trans2.Start(&request, callback2.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback3;
HttpNetworkTransaction trans3(session);
- rv = trans3.Start(&request, &callback3, BoundNetLog());
+ rv = trans3.Start(&request, callback3.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback2.WaitForResult());
@@ -7043,12 +7067,12 @@
// 2nd request is just a copy of the first one, over HTTP again.
session_deps.socket_factory.AddSocketDataProvider(&first_transaction);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -7063,7 +7087,7 @@
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request, &callback, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -7200,12 +7224,12 @@
session_deps.socket_factory.AddSocketDataProvider(
&hanging_non_alternate_protocol_socket);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -7222,7 +7246,7 @@
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request, &callback, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -7294,16 +7318,15 @@
spdy_writes, arraysize(spdy_writes)));
session_deps.socket_factory.AddSocketDataProvider(spdy_data);
- TestOldCompletionCallback callback_old;
TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback_old, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, callback_old.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
const HttpResponseInfo* response = trans->GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -7349,9 +7372,9 @@
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request, &callback_old, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, callback_old.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
response = trans->GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -7751,12 +7774,13 @@
&ssl_socket_data_provider);
// Start or restart the transaction.
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
int rv;
if (round == 0) {
- rv = trans.Start(&request, &callback, BoundNetLog());
+ rv = trans.Start(&request, callback.callback(), BoundNetLog());
} else {
- rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), &callback);
+ rv = trans.RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback.callback());
}
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
@@ -7827,7 +7851,7 @@
session_peer.SetClientSocketPoolManager(mock_pool_manager);
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
const MockWrite kGet(
"GET / HTTP/1.1\r\n"
@@ -7883,7 +7907,7 @@
// First round of authentication.
auth_handler->SetGenerateExpectation(false, OK);
- rv = trans->Start(&request, &callback, BoundNetLog());
+ rv = trans->Start(&request, callback.callback(), BoundNetLog());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -7897,8 +7921,9 @@
// claimed.
scoped_ptr<HttpTransaction> trans_compete(
new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback_compete;
- rv = trans_compete->Start(&request, &callback_compete, BoundNetLog());
+ TestCompletionCallback callback_compete;
+ rv = trans_compete->Start(
+ &request, callback_compete.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// callback_compete.WaitForResult at this point would stall forever,
// since the HttpNetworkTransaction does not release the request back to
@@ -7906,7 +7931,7 @@
// Second round of authentication.
auth_handler->SetGenerateExpectation(false, OK);
- rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback);
+ rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -7917,7 +7942,7 @@
// Third round of authentication.
auth_handler->SetGenerateExpectation(false, OK);
- rv = trans->RestartWithAuth(AuthCredentials(), &callback);
+ rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -7928,7 +7953,7 @@
// Fourth round of authentication, which completes successfully.
auth_handler->SetGenerateExpectation(false, OK);
- rv = trans->RestartWithAuth(AuthCredentials(), &callback);
+ rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -7940,11 +7965,11 @@
// Read the body since the fourth round was successful. This will also
// release the socket back to the pool.
scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50));
- rv = trans->Read(io_buf, io_buf->size(), &callback);
+ rv = trans->Read(io_buf, io_buf->size(), callback.callback());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
EXPECT_EQ(3, rv);
- rv = trans->Read(io_buf, io_buf->size(), &callback);
+ rv = trans->Read(io_buf, io_buf->size(), callback.callback());
EXPECT_EQ(0, rv);
// There are still 0 idle sockets, since the trans_compete transaction
// will be handed it immediately after trans releases it to the group.
@@ -7954,11 +7979,11 @@
// read the body.
rv = callback_compete.WaitForResult();
EXPECT_EQ(OK, rv);
- rv = trans_compete->Read(io_buf, io_buf->size(), &callback);
+ rv = trans_compete->Read(io_buf, io_buf->size(), callback.callback());
if (rv == ERR_IO_PENDING)
rv = callback.WaitForResult();
EXPECT_EQ(3, rv);
- rv = trans_compete->Read(io_buf, io_buf->size(), &callback);
+ rv = trans_compete->Read(io_buf, io_buf->size(), callback.callback());
EXPECT_EQ(0, rv);
// Finally, the socket is released to the group.
@@ -8020,9 +8045,9 @@
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -8062,9 +8087,9 @@
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -8114,12 +8139,12 @@
data_writes, arraysize(data_writes));
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -8174,12 +8199,12 @@
spdy_writes, arraysize(spdy_writes)));
session_deps.socket_factory.AddSocketDataProvider(spdy_data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
@@ -8307,16 +8332,16 @@
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
// First round should work and provide the Alternate-Protocol state.
- TestOldCompletionCallback callback_1;
+ TestCompletionCallback callback_1;
scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session));
- int rv = trans_1->Start(&request, &callback_1, BoundNetLog());
+ int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback_1.WaitForResult());
// Second round should attempt a tunnel connect and get an auth challenge.
- TestOldCompletionCallback callback_2;
+ TestCompletionCallback callback_2;
scoped_ptr<HttpTransaction> trans_2(new HttpNetworkTransaction(session));
- rv = trans_2->Start(&request, &callback_2, BoundNetLog());
+ rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback_2.WaitForResult());
const HttpResponseInfo* response = trans_2->GetResponseInfo();
@@ -8324,8 +8349,9 @@
ASSERT_FALSE(response->auth_challenge.get() == NULL);
// Restart with auth. Tunnel should work and response received.
- TestOldCompletionCallback callback_3;
- rv = trans_2->RestartWithAuth(AuthCredentials(kFoo, kBar), &callback_3);
+ TestCompletionCallback callback_3;
+ rv = trans_2->RestartWithAuth(
+ AuthCredentials(kFoo, kBar), callback_3.callback());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback_3.WaitForResult());
@@ -8368,10 +8394,10 @@
data.set_connect_data(mock_connect);
session_deps.socket_factory.AddSocketDataProvider(&data);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
- int rv = trans->Start(&request, &callback, log.bound());
+ int rv = trans->Start(&request, callback.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
trans.reset(); // Cancel the transaction here.
@@ -8406,11 +8432,11 @@
data_writes1, arraysize(data_writes1));
session_deps.socket_factory.AddSocketDataProvider(&data1);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -8463,11 +8489,11 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -8527,11 +8553,11 @@
SSLSocketDataProvider ssl(true, OK);
session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &callback1, log.bound());
+ int rv = trans->Start(&request, callback1.callback(), log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback1.WaitForResult();
@@ -8586,7 +8612,6 @@
session->spdy_session_pool()->Get(pair, BoundNetLog());
scoped_refptr<TransportSocketParams> transport_params(
new TransportSocketParams(host_port_pair, MEDIUM, false, false));
- TestOldCompletionCallback old_callback;
TestCompletionCallback callback;
scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
@@ -8607,9 +8632,9 @@
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request, &old_callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, old_callback.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
}
// Given a net error, cause that error to be returned from the first Write()
@@ -8634,8 +8659,8 @@
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- TestOldCompletionCallback callback;
- int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
ASSERT_EQ(error, rv);
@@ -8712,8 +8737,8 @@
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
// Begin the SSL handshake with the peer. This consumes ssl_data1.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
// Complete the SSL handshake, which should abort due to requiring a
@@ -8725,7 +8750,7 @@
// of SSLClientCertCache, NULL is just as meaningful as a real
// certificate, so this is the same as supply a
// legitimate-but-unacceptable certificate.
- rv = trans->RestartWithCertificate(NULL, &callback);
+ rv = trans->RestartWithCertificate(NULL, callback.callback());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
// Ensure the certificate was added to the client auth cache before
@@ -8817,8 +8842,8 @@
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
// Begin the initial SSL handshake.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&request_info, &callback, net::BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
// Complete the SSL handshake, which should abort due to requiring a
@@ -8830,7 +8855,7 @@
// of SSLClientCertCache, NULL is just as meaningful as a real
// certificate, so this is the same as supply a
// legitimate-but-unacceptable certificate.
- rv = trans->RestartWithCertificate(NULL, &callback);
+ rv = trans->RestartWithCertificate(NULL, callback.callback());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
// Ensure the certificate was added to the client auth cache before
@@ -8911,8 +8936,9 @@
new HttpNetworkTransaction(session));
// Begin the SSL handshake with the proxy.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&requests[i], &callback, net::BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &requests[i], callback.callback(), net::BoundNetLog());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
// Complete the SSL handshake, which should abort due to requiring a
@@ -8924,7 +8950,7 @@
// of SSLClientCertCache, NULL is just as meaningful as a real
// certificate, so this is the same as supply a
// legitimate-but-unacceptable certificate.
- rv = trans->RestartWithCertificate(NULL, &callback);
+ rv = trans->RestartWithCertificate(NULL, callback.callback());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
// Ensure the certificate was added to the client auth cache before
@@ -9041,16 +9067,15 @@
session_deps.socket_factory.AddSocketDataProvider(spdy_data);
TestCompletionCallback callback;
- TestOldCompletionCallback old_callback;
HttpRequestInfo request1;
request1.method = "GET";
request1.url = GURL("https://www.google.com/");
request1.load_flags = 0;
HttpNetworkTransaction trans1(session);
- int rv = trans1.Start(&request1, &old_callback, BoundNetLog());
+ int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, old_callback.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
const HttpResponseInfo* response = trans1.GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -9083,9 +9108,9 @@
request2.load_flags = 0;
HttpNetworkTransaction trans2(session);
- rv = trans2.Start(&request2, &old_callback, BoundNetLog());
+ rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, old_callback.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
response = trans2.GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -9202,10 +9227,9 @@
request1.load_flags = 0;
HttpNetworkTransaction trans1(session);
- TestOldCompletionCallback old_callback;
- int rv = trans1.Start(&request1, &old_callback, BoundNetLog());
+ int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, old_callback.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
const HttpResponseInfo* response = trans1.GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -9237,9 +9261,9 @@
IPPoolingAddAlias(host_resolver.GetMockHostResolver(), &pool_peer,
"www.google.com", 443, "127.0.0.1");
- rv = trans2.Start(&request2, &old_callback, BoundNetLog());
+ rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, old_callback.WaitForResult());
+ EXPECT_EQ(OK, callback.WaitForResult());
response = trans2.GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -9393,14 +9417,14 @@
EXPECT_FALSE(
session->spdy_session_pool()->HasSession(host_port_proxy_pair_a));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpRequestInfo request1;
request1.method = "GET";
request1.url = GURL("https://www.a.com/");
request1.load_flags = 0;
scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
- int rv = trans->Start(&request1, &callback, BoundNetLog());
+ int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -9429,7 +9453,7 @@
request2.load_flags = 0;
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request2, &callback, BoundNetLog());
+ rv = trans->Start(&request2, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -9457,7 +9481,7 @@
request3.load_flags = 0;
trans.reset(new HttpNetworkTransaction(session));
- rv = trans->Start(&request3, &callback, BoundNetLog());
+ rv = trans->Start(&request3, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
diff --git a/net/http/http_pipelined_connection_impl.cc b/net/http/http_pipelined_connection_impl.cc
index e8a3e780..ab7ee40 100644
--- a/net/http/http_pipelined_connection_impl.cc
+++ b/net/http/http_pipelined_connection_impl.cc
@@ -4,6 +4,8 @@
#include "net/http/http_pipelined_connection_impl.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
#include "base/values.h"
@@ -82,16 +84,12 @@
active_(false),
usable_(true),
completed_one_request_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
send_next_state_(SEND_STATE_NONE),
send_still_on_call_stack_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(send_io_callback_(
- this, &HttpPipelinedConnectionImpl::OnSendIOCallback)),
read_next_state_(READ_STATE_NONE),
active_read_id_(0),
- read_still_on_call_stack_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_io_callback_(
- this, &HttpPipelinedConnectionImpl::OnReadIOCallback)) {
+ read_still_on_call_stack_(false) {
CHECK(connection_.get());
net_log_.BeginEvent(
NetLog::TYPE_HTTP_PIPELINED_CONNECTION,
@@ -139,8 +137,8 @@
if (pipeline_id == 1) {
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &HttpPipelinedConnectionImpl::ActivatePipeline));
+ base::Bind(&HttpPipelinedConnectionImpl::ActivatePipeline,
+ weak_factory_.GetWeakPtr()));
}
}
@@ -167,12 +165,10 @@
delegate_->OnPipelineHasCapacity(this);
}
-int HttpPipelinedConnectionImpl::SendRequest(int pipeline_id,
- const std::string& request_line,
- const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
- HttpResponseInfo* response,
- OldCompletionCallback* callback) {
+int HttpPipelinedConnectionImpl::SendRequest(
+ int pipeline_id, const std::string& request_line,
+ const HttpRequestHeaders& headers, UploadDataStream* request_body,
+ HttpResponseInfo* response, const CompletionCallback& callback) {
CHECK(ContainsKey(stream_info_map_, pipeline_id));
CHECK_EQ(stream_info_map_[pipeline_id].state, STREAM_BOUND);
if (!usable_) {
@@ -275,7 +271,8 @@
active_send_request_->headers,
active_send_request_->request_body,
active_send_request_->response,
- &send_io_callback_);
+ base::Bind(&HttpPipelinedConnectionImpl::OnSendIOCallback,
+ base::Unretained(this)));
stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENDING;
send_next_state_ = SEND_STATE_COMPLETE;
return rv;
@@ -327,24 +324,21 @@
scoped_ptr<PendingSendRequest> evicted_send(
pending_send_request_queue_.front());
pending_send_request_queue_.pop();
- if (stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED) {
- evicted_send->callback->Run(ERR_PIPELINE_EVICTION);
- }
+ if (stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED)
+ evicted_send->callback.Run(ERR_PIPELINE_EVICTION);
}
send_next_state_ = SEND_STATE_NONE;
return result;
}
int HttpPipelinedConnectionImpl::ReadResponseHeaders(
- int pipeline_id,
- OldCompletionCallback* callback) {
+ int pipeline_id, const CompletionCallback& callback) {
CHECK(ContainsKey(stream_info_map_, pipeline_id));
CHECK_EQ(STREAM_SENT, stream_info_map_[pipeline_id].state);
- CHECK(!stream_info_map_[pipeline_id].read_headers_callback);
+ CHECK(stream_info_map_[pipeline_id].read_headers_callback.is_null());
- if (!usable_) {
+ if (!usable_)
return ERR_PIPELINE_EVICTION;
- }
stream_info_map_[pipeline_id].state = STREAM_READ_PENDING;
stream_info_map_[pipeline_id].read_headers_callback = callback;
@@ -466,7 +460,8 @@
CHECK_EQ(STREAM_READ_PENDING, stream_info_map_[active_read_id_].state);
stream_info_map_[active_read_id_].state = STREAM_ACTIVE;
int rv = stream_info_map_[active_read_id_].parser->ReadResponseHeaders(
- &read_io_callback_);
+ base::Bind(&HttpPipelinedConnectionImpl::OnReadIOCallback,
+ base::Unretained(this)));
read_next_state_ = READ_STATE_READ_HEADERS_COMPLETE;
return rv;
}
@@ -513,8 +508,8 @@
completed_one_request_ = true;
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &HttpPipelinedConnectionImpl::StartNextDeferredRead));
+ base::Bind(&HttpPipelinedConnectionImpl::StartNextDeferredRead,
+ weak_factory_.GetWeakPtr()));
read_next_state_ = READ_STATE_NONE;
return OK;
}
@@ -599,10 +594,8 @@
}
int HttpPipelinedConnectionImpl::ReadResponseBody(
- int pipeline_id,
- IOBuffer* buf,
- int buf_len,
- OldCompletionCallback* callback) {
+ int pipeline_id, IOBuffer* buf, int buf_len,
+ const CompletionCallback& callback) {
CHECK(ContainsKey(stream_info_map_, pipeline_id));
CHECK_EQ(active_read_id_, pipeline_id);
CHECK(stream_info_map_[pipeline_id].parser.get());
@@ -662,7 +655,7 @@
SSLInfo* ssl_info) {
CHECK(ContainsKey(stream_info_map_, pipeline_id));
CHECK(stream_info_map_[pipeline_id].parser.get());
- return stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info);
+ stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info);
}
void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo(
@@ -670,7 +663,7 @@
SSLCertRequestInfo* cert_request_info) {
CHECK(ContainsKey(stream_info_map_, pipeline_id));
CHECK(stream_info_map_[pipeline_id].parser.get());
- return stream_info_map_[pipeline_id].parser->GetSSLCertRequestInfo(
+ stream_info_map_[pipeline_id].parser->GetSSLCertRequestInfo(
cert_request_info);
}
@@ -755,28 +748,24 @@
}
void HttpPipelinedConnectionImpl::QueueUserCallback(
- int pipeline_id,
- OldCompletionCallback* callback,
- int rv,
+ int pipeline_id, const CompletionCallback& callback, int rv,
const tracked_objects::Location& from_here) {
- CHECK(!stream_info_map_[pipeline_id].pending_user_callback);
+ CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null());
stream_info_map_[pipeline_id].pending_user_callback = callback;
MessageLoop::current()->PostTask(
from_here,
- method_factory_.NewRunnableMethod(
- &HttpPipelinedConnectionImpl::FireUserCallback,
- pipeline_id,
- rv));
+ base::Bind(&HttpPipelinedConnectionImpl::FireUserCallback,
+ weak_factory_.GetWeakPtr(), pipeline_id, rv));
}
void HttpPipelinedConnectionImpl::FireUserCallback(int pipeline_id,
int result) {
if (ContainsKey(stream_info_map_, pipeline_id)) {
- CHECK(stream_info_map_[pipeline_id].pending_user_callback);
- OldCompletionCallback* callback =
+ CHECK(!stream_info_map_[pipeline_id].pending_user_callback.is_null());
+ CompletionCallback callback =
stream_info_map_[pipeline_id].pending_user_callback;
- stream_info_map_[pipeline_id].pending_user_callback = NULL;
- callback->Run(result);
+ stream_info_map_[pipeline_id].pending_user_callback.Reset();
+ callback.Run(result);
}
}
@@ -820,9 +809,7 @@
}
HttpPipelinedConnectionImpl::StreamInfo::StreamInfo()
- : read_headers_callback(NULL),
- pending_user_callback(NULL),
- state(STREAM_CREATED) {
+ : state(STREAM_CREATED) {
}
HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() {
diff --git a/net/http/http_pipelined_connection_impl.h b/net/http/http_pipelined_connection_impl.h
index d0d62d05..6fa963c 100644
--- a/net/http/http_pipelined_connection_impl.h
+++ b/net/http/http_pipelined_connection_impl.h
@@ -13,6 +13,7 @@
#include "base/basictypes.h"
#include "base/location.h"
#include "base/memory/linked_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
@@ -90,14 +91,14 @@
const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
int ReadResponseHeaders(int pipeline_id,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
int ReadResponseBody(int pipeline_id,
IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
void Close(int pipeline_id,
bool not_reusable);
@@ -166,7 +167,7 @@
HttpRequestHeaders headers;
UploadDataStream* request_body;
HttpResponseInfo* response;
- OldCompletionCallback* callback;
+ CompletionCallback callback;
};
struct StreamInfo {
@@ -174,8 +175,8 @@
~StreamInfo();
linked_ptr<HttpStreamParser> parser;
- OldCompletionCallback* read_headers_callback;
- OldCompletionCallback* pending_user_callback;
+ CompletionCallback read_headers_callback;
+ CompletionCallback pending_user_callback;
StreamState state;
NetLog::Source source;
};
@@ -275,7 +276,7 @@
// synchronously, but we've already returned ERR_IO_PENDING to the user's
// SendRequest() or ReadResponseHeaders() call into us.
void QueueUserCallback(int pipeline_id,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
int rv,
const tracked_objects::Location& from_here);
@@ -295,7 +296,7 @@
bool active_;
bool usable_;
bool completed_one_request_;
- ScopedRunnableMethodFactory<HttpPipelinedConnectionImpl> method_factory_;
+ base::WeakPtrFactory<HttpPipelinedConnectionImpl> weak_factory_;
StreamInfoMap stream_info_map_;
@@ -305,12 +306,10 @@
scoped_ptr<PendingSendRequest> active_send_request_;
SendRequestState send_next_state_;
bool send_still_on_call_stack_;
- OldCompletionCallbackImpl<HttpPipelinedConnectionImpl> send_io_callback_;
ReadHeadersState read_next_state_;
int active_read_id_;
bool read_still_on_call_stack_;
- OldCompletionCallbackImpl<HttpPipelinedConnectionImpl> read_io_callback_;
DISALLOW_COPY_AND_ASSIGN(HttpPipelinedConnectionImpl);
};
diff --git a/net/http/http_pipelined_connection_impl_unittest.cc b/net/http/http_pipelined_connection_impl_unittest.cc
index 81d1391..e4dfe70 100644
--- a/net/http/http_pipelined_connection_impl_unittest.cc
+++ b/net/http/http_pipelined_connection_impl_unittest.cc
@@ -105,7 +105,8 @@
HttpStream* NewTestStream(const std::string& filename) {
HttpStream* stream = pipeline_->CreateNewStream();
HttpRequestInfo* request_info = GetRequestInfo(filename);
- int rv = stream->InitializeStream(request_info, BoundNetLog(), NULL);
+ int rv = stream->InitializeStream(
+ request_info, BoundNetLog(), CompletionCallback());
DCHECK_EQ(OK, rv);
return stream;
}
@@ -117,13 +118,13 @@
if (async) {
EXPECT_EQ(ERR_IO_PENDING,
stream->ReadResponseBody(buffer.get(), expected.size(),
- &callback_));
+ callback_.callback()));
data_->RunFor(1);
EXPECT_EQ(static_cast<int>(expected.size()), callback_.WaitForResult());
} else {
EXPECT_EQ(static_cast<int>(expected.size()),
stream->ReadResponseBody(buffer.get(), expected.size(),
- &callback_));
+ callback_.callback()));
}
std::string actual(buffer->data(), expected.size());
EXPECT_THAT(actual, StrEq(expected));
@@ -133,8 +134,9 @@
const std::string& filename) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_));
- EXPECT_EQ(OK, stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream->SendRequest(
+ headers, NULL, &response, callback_.callback()));
+ EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse(filename, stream, false);
stream->Close(false);
@@ -149,7 +151,7 @@
SSLConfig ssl_config_;
ProxyInfo proxy_info_;
NiceMock<MockPipelineDelegate> delegate_;
- TestOldCompletionCallback callback_;
+ TestCompletionCallback callback_;
scoped_ptr<HttpPipelinedConnectionImpl> pipeline_;
ScopedVector<HttpRequestInfo> request_info_vector_;
};
@@ -204,12 +206,12 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(ERR_IO_PENDING,
- stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
data_->RunFor(1);
EXPECT_LE(OK, callback_.WaitForResult());
- EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback()));
data_->RunFor(2);
EXPECT_LE(OK, callback_.WaitForResult());
@@ -238,21 +240,21 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(ERR_IO_PENDING,
- stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(ERR_IO_PENDING,
- stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
data_->RunFor(1);
EXPECT_LE(OK, callback_.WaitForResult());
data_->RunFor(1);
EXPECT_LE(OK, callback_.WaitForResult());
- EXPECT_EQ(ERR_IO_PENDING, stream1->ReadResponseHeaders(&callback_));
- EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream1->ReadResponseHeaders(callback_.callback()));
+ EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback()));
data_->RunFor(2);
EXPECT_LE(OK, callback_.WaitForResult());
@@ -290,16 +292,18 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", stream1, false);
stream1->Close(false);
- EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ko.html", stream2, false);
stream2->Close(false);
}
@@ -346,15 +350,17 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
- EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback()));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", stream1, false);
stream1->Close(false);
@@ -385,17 +391,19 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
ExpectResponse("ok.html", stream1, false);
stream1->Close(false);
- EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ko.html", stream2, false);
stream2->Close(false);
}
@@ -420,24 +428,26 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
- TestOldCompletionCallback callback1;
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
+ TestCompletionCallback callback1;
std::string expected = "ok.html";
scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size()));
EXPECT_EQ(ERR_IO_PENDING,
stream1->ReadResponseBody(buffer.get(), expected.size(),
- &callback1));
+ callback1.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
EXPECT_EQ(ERR_IO_PENDING,
- stream2->SendRequest(headers2, NULL, &response2, &callback2));
+ stream2->SendRequest(headers2, NULL, &response2,
+ callback2.callback()));
data_->RunFor(1);
EXPECT_LE(OK, callback2.WaitForResult());
- EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(&callback2));
+ EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback2.callback()));
data_->RunFor(1);
EXPECT_EQ(static_cast<int>(expected.size()), callback1.WaitForResult());
@@ -488,21 +498,21 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(ERR_IO_PENDING,
- stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
scoped_ptr<HttpStream> unsent_stream(NewTestStream("unsent.html"));
HttpRequestHeaders unsent_headers;
HttpResponseInfo unsent_response;
EXPECT_EQ(ERR_IO_PENDING,
unsent_stream->SendRequest(unsent_headers, NULL, &unsent_response,
- &callback_));
+ callback_.callback()));
unsent_stream->Close(false);
data_->RunFor(1);
EXPECT_LE(OK, callback_.WaitForResult());
- EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback()));
data_->RunFor(2);
EXPECT_LE(OK, callback_.WaitForResult());
@@ -528,17 +538,17 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- TestOldCompletionCallback failed_callback;
+ TestCompletionCallback failed_callback;
EXPECT_EQ(ERR_IO_PENDING,
failed_stream->SendRequest(headers, NULL, &response,
- &failed_callback));
- TestOldCompletionCallback evicted_callback;
+ failed_callback.callback()));
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
evicted_stream->SendRequest(headers, NULL, &response,
- &evicted_callback));
+ evicted_callback.callback()));
EXPECT_EQ(ERR_IO_PENDING,
closed_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
closed_stream->Close(false);
data_->RunFor(1);
@@ -546,7 +556,7 @@
EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
EXPECT_EQ(ERR_PIPELINE_EVICTION,
rejected_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
failed_stream->Close(true);
evicted_stream->Close(true);
@@ -581,25 +591,26 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
EXPECT_EQ(OK, closed_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
EXPECT_EQ(OK, read_evicted_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
EXPECT_EQ(OK, read_rejected_stream->SendRequest(headers, NULL, &response,
- &callback_));
- TestOldCompletionCallback send_closed_callback;
+ callback_.callback()));
+ TestCompletionCallback send_closed_callback;
EXPECT_EQ(ERR_IO_PENDING,
send_closed_stream->SendRequest(headers, NULL, &response,
- &send_closed_callback));
- TestOldCompletionCallback send_evicted_callback;
+ send_closed_callback.callback()));
+ TestCompletionCallback send_evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
send_evicted_stream->SendRequest(headers, NULL, &response,
- &send_evicted_callback));
+ send_evicted_callback.callback()));
- TestOldCompletionCallback read_evicted_callback;
+ TestCompletionCallback read_evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- read_evicted_stream->ReadResponseHeaders(&read_evicted_callback));
+ read_evicted_stream->ReadResponseHeaders(
+ read_evicted_callback.callback()));
- EXPECT_EQ(OK, closed_stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, closed_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", closed_stream, false);
closed_stream->Close(true);
@@ -607,7 +618,7 @@
read_evicted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- read_rejected_stream->ReadResponseHeaders(&callback_));
+ read_rejected_stream->ReadResponseHeaders(callback_.callback()));
read_rejected_stream->Close(true);
data_->RunFor(1);
@@ -619,7 +630,7 @@
EXPECT_EQ(ERR_PIPELINE_EVICTION,
send_rejected_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
send_rejected_stream->Close(true);
}
@@ -634,14 +645,14 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- TestOldCompletionCallback aborted_callback;
+ TestCompletionCallback aborted_callback;
EXPECT_EQ(ERR_IO_PENDING,
aborted_stream->SendRequest(headers, NULL, &response,
- &aborted_callback));
- TestOldCompletionCallback evicted_callback;
+ aborted_callback.callback()));
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
evicted_stream->SendRequest(headers, NULL, &response,
- &evicted_callback));
+ evicted_callback.callback()));
aborted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
@@ -662,18 +673,18 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- TestOldCompletionCallback ok_callback;
+ TestCompletionCallback ok_callback;
EXPECT_EQ(ERR_IO_PENDING,
ok_stream->SendRequest(headers, NULL, &response,
- &ok_callback));
- TestOldCompletionCallback aborted_callback;
+ ok_callback.callback()));
+ TestCompletionCallback aborted_callback;
EXPECT_EQ(ERR_IO_PENDING,
aborted_stream->SendRequest(headers, NULL, &response,
- &aborted_callback));
- TestOldCompletionCallback evicted_callback;
+ aborted_callback.callback()));
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
evicted_stream->SendRequest(headers, NULL, &response,
- &evicted_callback));
+ evicted_callback.callback()));
data_->RunFor(1);
EXPECT_LE(OK, ok_callback.WaitForResult());
@@ -702,21 +713,23 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
EXPECT_EQ(OK, aborted_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
- EXPECT_EQ(ERR_IO_PENDING, aborted_stream->ReadResponseHeaders(&callback_));
- TestOldCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ aborted_stream->ReadResponseHeaders(callback_.callback()));
+ TestCompletionCallback evicted_callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
aborted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
evicted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- rejected_stream->SendRequest(headers, NULL, &response, &callback_));
+ rejected_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
rejected_stream->Close(true);
}
@@ -739,19 +752,20 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_EQ(OK, abandoned_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
- EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_));
- TestOldCompletionCallback abandoned_callback;
+ EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
+ TestCompletionCallback abandoned_callback;
+ EXPECT_EQ(ERR_IO_PENDING, abandoned_stream->ReadResponseHeaders(
+ abandoned_callback.callback()));
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- abandoned_stream->ReadResponseHeaders(&abandoned_callback));
- TestOldCompletionCallback evicted_callback;
- EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
abandoned_stream->Close(false);
@@ -785,26 +799,27 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_EQ(OK, rejected_read_stream->SendRequest(
- headers, NULL, &response, &callback_));
+ headers, NULL, &response, callback_.callback()));
- EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
ok_stream->Close(false);
- TestOldCompletionCallback read_callback;
+ TestCompletionCallback read_callback;
EXPECT_EQ(ERR_IO_PENDING,
evicted_send_stream->SendRequest(headers, NULL, &response,
- &read_callback));
+ read_callback.callback()));
data_->RunFor(1);
EXPECT_EQ(ERR_PIPELINE_EVICTION, read_callback.WaitForResult());
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- rejected_read_stream->ReadResponseHeaders(&callback_));
+ rejected_read_stream->ReadResponseHeaders(callback_.callback()));
EXPECT_EQ(ERR_PIPELINE_EVICTION,
rejected_send_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
rejected_read_stream->Close(true);
rejected_send_stream->Close(true);
@@ -828,16 +843,17 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_EQ(OK, evicted_stream->SendRequest(
- headers, NULL, &response, &callback_));
+ headers, NULL, &response, callback_.callback()));
- EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
- TestOldCompletionCallback evicted_callback;
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
ok_stream->Close(false);
@@ -863,16 +879,17 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_EQ(OK, evicted_stream->SendRequest(
- headers, NULL, &response, &callback_));
+ headers, NULL, &response, callback_.callback()));
- EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
- TestOldCompletionCallback evicted_callback;
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
ok_stream->Close(false);
evicted_stream->Close(false);
@@ -896,16 +913,17 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_EQ(OK, evicted_stream->SendRequest(
- headers, NULL, &response, &callback_));
+ headers, NULL, &response, callback_.callback()));
- EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
- TestOldCompletionCallback evicted_callback;
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
ok_stream->Close(false);
@@ -922,11 +940,11 @@
public:
StreamDeleter(HttpStream* stream) :
stream_(stream),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_(this, &StreamDeleter::OnIOComplete)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&StreamDeleter::OnIOComplete, base::Unretained(this)))) {
}
- OldCompletionCallbackImpl<StreamDeleter>* callback() { return &callback_; }
+ const CompletionCallback& callback() { return callback_; }
private:
void OnIOComplete(int result) {
@@ -934,7 +952,7 @@
}
HttpStream* stream_;
- OldCompletionCallbackImpl<StreamDeleter> callback_;
+ CompletionCallback callback_;
};
TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) {
@@ -967,7 +985,8 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
StreamDeleter deleter(stream);
EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback()));
@@ -991,10 +1010,10 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK,
- failed_stream->SendRequest(headers, NULL, &response, &callback_));
- EXPECT_EQ(OK,
- evicted_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, failed_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
+ EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
StreamDeleter failed_deleter(failed_stream);
EXPECT_EQ(ERR_IO_PENDING,
@@ -1021,15 +1040,16 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK,
- deleter_stream->SendRequest(headers, NULL, &response, &callback_));
- EXPECT_EQ(OK,
- deleted_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, deleter_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
+ EXPECT_EQ(OK, deleted_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
StreamDeleter deleter(deleted_stream);
EXPECT_EQ(ERR_IO_PENDING,
deleter_stream->ReadResponseHeaders(deleter.callback()));
- EXPECT_EQ(ERR_IO_PENDING, deleted_stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_IO_PENDING,
+ deleted_stream->ReadResponseHeaders(callback_.callback()));
data_->RunFor(1);
}
@@ -1043,12 +1063,12 @@
scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
- scoped_ptr<TestOldCompletionCallback> close_callback(
- new TestOldCompletionCallback);
+ scoped_ptr<TestCompletionCallback> close_callback(
+ new TestCompletionCallback);
HttpRequestHeaders headers;
HttpResponseInfo response;
EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest(
- headers, NULL, &response, close_callback.get()));
+ headers, NULL, &response, close_callback->callback()));
data_->RunFor(1);
EXPECT_FALSE(close_callback->have_result());
@@ -1076,13 +1096,13 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK,
- close_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
- scoped_ptr<TestOldCompletionCallback> close_callback(
- new TestOldCompletionCallback);
+ scoped_ptr<TestCompletionCallback> close_callback(
+ new TestCompletionCallback);
EXPECT_EQ(ERR_IO_PENDING,
- close_stream->ReadResponseHeaders(close_callback.get()));
+ close_stream->ReadResponseHeaders(close_callback->callback()));
data_->RunFor(1);
EXPECT_FALSE(close_callback->have_result());
@@ -1116,15 +1136,17 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
- EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", stream2, false);
stream2->Close(false);
}
@@ -1146,15 +1168,18 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
- EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_PIPELINE_EVICTION,
+ stream2->ReadResponseHeaders(callback_.callback()));
stream2->Close(false);
}
@@ -1176,15 +1201,18 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
- EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_PIPELINE_EVICTION,
+ stream2->ReadResponseHeaders(callback_.callback()));
stream2->Close(false);
}
@@ -1207,15 +1235,18 @@
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
+ callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
+ callback_.callback()));
- EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
- EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(ERR_PIPELINE_EVICTION,
+ stream2->ReadResponseHeaders(callback_.callback()));
stream2->Close(false);
}
@@ -1238,18 +1269,20 @@
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
- TestOldCompletionCallback ok_callback;
- EXPECT_EQ(ERR_IO_PENDING, ok_stream->ReadResponseHeaders(&ok_callback));
-
- TestOldCompletionCallback evicted_callback;
+ TestCompletionCallback ok_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ ok_stream->ReadResponseHeaders(ok_callback.callback()));
+
+ TestCompletionCallback evicted_callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
data_->RunFor(1);
EXPECT_LE(OK, ok_callback.WaitForResult());
@@ -1259,7 +1292,7 @@
ok_stream->Close(false);
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- rejected_stream->ReadResponseHeaders(&callback_));
+ rejected_stream->ReadResponseHeaders(callback_.callback()));
rejected_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
evicted_stream->Close(true);
@@ -1283,8 +1316,9 @@
scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_));
- EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(&callback_));
+ EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
+ EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback()));
}
TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) {
@@ -1362,7 +1396,8 @@
EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_));
+ EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
+ callback_.callback()));
EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
MessageLoop::current()->RunAllPending();
diff --git a/net/http/http_pipelined_network_transaction_unittest.cc b/net/http/http_pipelined_network_transaction_unittest.cc
index 33225d8..714aa3b 100644
--- a/net/http/http_pipelined_network_transaction_unittest.cc
+++ b/net/http/http_pipelined_network_transaction_unittest.cc
@@ -91,31 +91,34 @@
HttpNetworkTransaction& transaction) {
scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size()));
EXPECT_EQ(static_cast<int>(expected.size()),
- transaction.Read(buffer.get(), expected.size(), &callback_));
+ transaction.Read(buffer.get(), expected.size(),
+ callback_.callback()));
std::string actual(buffer->data(), expected.size());
EXPECT_THAT(actual, StrEq(expected));
- EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), &callback_));
+ EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(),
+ callback_.callback()));
}
void CompleteTwoRequests(int data_index, int stop_at_step) {
scoped_ptr<HttpNetworkTransaction> one_transaction(
new HttpNetworkTransaction(session_.get()));
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
- one_transaction->Start(GetRequestInfo("one.html"), &one_callback,
- BoundNetLog()));
+ one_transaction->Start(GetRequestInfo("one.html"),
+ one_callback.callback(), BoundNetLog()));
EXPECT_EQ(OK, one_callback.WaitForResult());
HttpNetworkTransaction two_transaction(session_.get());
- TestOldCompletionCallback two_callback;
+ TestCompletionCallback two_callback;
EXPECT_EQ(ERR_IO_PENDING,
- two_transaction.Start(GetRequestInfo("two.html"), &two_callback,
- BoundNetLog()));
+ two_transaction.Start(GetRequestInfo("two.html"),
+ two_callback.callback(), BoundNetLog()));
- TestOldCompletionCallback one_read_callback;
+ TestCompletionCallback one_read_callback;
scoped_refptr<IOBuffer> buffer(new IOBuffer(8));
EXPECT_EQ(ERR_IO_PENDING,
- one_transaction->Read(buffer.get(), 8, &one_read_callback));
+ one_transaction->Read(buffer.get(), 8,
+ one_read_callback.callback()));
data_vector_[data_index]->SetStop(stop_at_step);
data_vector_[data_index]->Run();
@@ -123,7 +126,8 @@
data_vector_[data_index]->SetStop(10);
std::string actual(buffer->data(), 8);
EXPECT_THAT(actual, StrEq("one.html"));
- EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, &one_read_callback));
+ EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8,
+ one_read_callback.callback()));
EXPECT_EQ(OK, two_callback.WaitForResult());
ExpectResponse("two.html", two_transaction);
@@ -132,29 +136,30 @@
void CompleteFourRequests() {
scoped_ptr<HttpNetworkTransaction> one_transaction(
new HttpNetworkTransaction(session_.get()));
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
- one_transaction->Start(GetRequestInfo("one.html"), &one_callback,
- BoundNetLog()));
+ one_transaction->Start(GetRequestInfo("one.html"),
+ one_callback.callback(), BoundNetLog()));
EXPECT_EQ(OK, one_callback.WaitForResult());
HttpNetworkTransaction two_transaction(session_.get());
- TestOldCompletionCallback two_callback;
+ TestCompletionCallback two_callback;
EXPECT_EQ(ERR_IO_PENDING,
- two_transaction.Start(GetRequestInfo("two.html"), &two_callback,
- BoundNetLog()));
+ two_transaction.Start(GetRequestInfo("two.html"),
+ two_callback.callback(), BoundNetLog()));
HttpNetworkTransaction three_transaction(session_.get());
- TestOldCompletionCallback three_callback;
+ TestCompletionCallback three_callback;
EXPECT_EQ(ERR_IO_PENDING,
three_transaction.Start(GetRequestInfo("three.html"),
- &three_callback, BoundNetLog()));
+ three_callback.callback(),
+ BoundNetLog()));
HttpNetworkTransaction four_transaction(session_.get());
- TestOldCompletionCallback four_callback;
+ TestCompletionCallback four_callback;
EXPECT_EQ(ERR_IO_PENDING,
four_transaction.Start(GetRequestInfo("four.html"),
- &four_callback, BoundNetLog()));
+ four_callback.callback(), BoundNetLog()));
ExpectResponse("one.html", *one_transaction.get());
EXPECT_EQ(OK, two_callback.WaitForResult());
@@ -171,7 +176,7 @@
ClientSocketPoolHistograms histograms_;
MockTransportClientSocketPool pool_;
std::vector<scoped_refptr<DeterministicSocketData> > data_vector_;
- TestOldCompletionCallback callback_;
+ TestCompletionCallback callback_;
ScopedVector<HttpRequestInfo> request_info_vector_;
bool default_pipelining_enabled_;
@@ -200,7 +205,7 @@
HttpNetworkTransaction transaction(session_.get());
EXPECT_EQ(ERR_IO_PENDING,
- transaction.Start(GetRequestInfo("test.html"), &callback_,
+ transaction.Start(GetRequestInfo("test.html"), callback_.callback(),
BoundNetLog()));
EXPECT_EQ(OK, callback_.WaitForResult());
ExpectResponse("test.html", transaction);
@@ -364,20 +369,21 @@
AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2));
HttpNetworkTransaction one_transaction(session_.get());
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
- one_transaction.Start(GetRequestInfo("one.html"), &one_callback,
- BoundNetLog()));
+ one_transaction.Start(GetRequestInfo("one.html"),
+ one_callback.callback(), BoundNetLog()));
EXPECT_EQ(OK, one_callback.WaitForResult());
HttpNetworkTransaction two_transaction(session_.get());
- TestOldCompletionCallback two_callback;
+ TestCompletionCallback two_callback;
EXPECT_EQ(ERR_IO_PENDING,
- two_transaction.Start(GetRequestInfo("two.html"), &two_callback,
- BoundNetLog()));
+ two_transaction.Start(GetRequestInfo("two.html"),
+ two_callback.callback(), BoundNetLog()));
scoped_refptr<IOBuffer> buffer(new IOBuffer(1));
- EXPECT_EQ(ERR_FAILED, one_transaction.Read(buffer.get(), 1, &callback_));
+ EXPECT_EQ(ERR_FAILED,
+ one_transaction.Read(buffer.get(), 1, callback_.callback()));
EXPECT_EQ(OK, two_callback.WaitForResult());
ExpectResponse("two.html", two_transaction);
}
@@ -403,16 +409,16 @@
AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2));
HttpNetworkTransaction one_transaction(session_.get());
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
- one_transaction.Start(GetRequestInfo("one.html"), &one_callback,
- BoundNetLog()));
+ one_transaction.Start(GetRequestInfo("one.html"),
+ one_callback.callback(), BoundNetLog()));
HttpNetworkTransaction two_transaction(session_.get());
- TestOldCompletionCallback two_callback;
+ TestCompletionCallback two_callback;
EXPECT_EQ(ERR_IO_PENDING,
- two_transaction.Start(GetRequestInfo("two.html"), &two_callback,
- BoundNetLog()));
+ two_transaction.Start(GetRequestInfo("two.html"),
+ two_callback.callback(), BoundNetLog()));
data_vector_[0]->RunFor(1);
EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult());
@@ -444,17 +450,17 @@
scoped_ptr<HttpNetworkTransaction> one_transaction(
new HttpNetworkTransaction(session_.get()));
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
one_transaction->Start(GetRequestInfo("redirect.html"),
- &one_callback, BoundNetLog()));
+ one_callback.callback(), BoundNetLog()));
EXPECT_EQ(OK, one_callback.WaitForResult());
HttpNetworkTransaction two_transaction(session_.get());
- TestOldCompletionCallback two_callback;
+ TestCompletionCallback two_callback;
EXPECT_EQ(ERR_IO_PENDING,
- two_transaction.Start(GetRequestInfo("two.html"), &two_callback,
- BoundNetLog()));
+ two_transaction.Start(GetRequestInfo("two.html"),
+ two_callback.callback(), BoundNetLog()));
one_transaction.reset();
data_vector_[0]->RunFor(2);
@@ -499,13 +505,13 @@
auth_handler_factory_->AddMockHandler(mock_auth, HttpAuth::AUTH_SERVER);
HttpNetworkTransaction transaction(session_.get());
- EXPECT_EQ(
- ERR_IO_PENDING,
- transaction.Start(GetRequestInfo("one.html"), &callback_, BoundNetLog()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ transaction.Start(GetRequestInfo("one.html"), callback_.callback(),
+ BoundNetLog()));
EXPECT_EQ(OK, callback_.WaitForResult());
AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass"));
- EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, &callback_));
+ EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, callback_.callback()));
ExpectResponse("one.html", transaction);
}
@@ -552,10 +558,10 @@
AddExpectedConnection(reads3, arraysize(reads3), writes3, arraysize(writes3));
HttpNetworkTransaction one_transaction(session_.get());
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
one_transaction.Start(GetRequestInfo("pipelined.html"),
- &one_callback, BoundNetLog()));
+ one_callback.callback(), BoundNetLog()));
EXPECT_EQ(OK, one_callback.WaitForResult());
ExpectResponse("pipelined.html", one_transaction);
@@ -616,19 +622,19 @@
CompleteFourRequests();
HttpNetworkTransaction second_one_transaction(session_.get());
- TestOldCompletionCallback second_one_callback;
+ TestCompletionCallback second_one_callback;
EXPECT_EQ(ERR_IO_PENDING,
second_one_transaction.Start(
GetRequestInfo("second-pipeline-one.html"),
- &second_one_callback, BoundNetLog()));
+ second_one_callback.callback(), BoundNetLog()));
MessageLoop::current()->RunAllPending();
HttpNetworkTransaction second_two_transaction(session_.get());
- TestOldCompletionCallback second_two_callback;
+ TestCompletionCallback second_two_callback;
EXPECT_EQ(ERR_IO_PENDING,
second_two_transaction.Start(
GetRequestInfo("second-pipeline-two.html"),
- &second_two_callback, BoundNetLog()));
+ second_two_callback.callback(), BoundNetLog()));
data_vector_[0]->RunFor(3);
EXPECT_EQ(OK, second_one_callback.WaitForResult());
@@ -700,19 +706,19 @@
AddExpectedConnection(NULL, 0, NULL, 0);
HttpNetworkTransaction one_transaction(session_.get());
- TestOldCompletionCallback one_callback;
+ TestCompletionCallback one_callback;
EXPECT_EQ(ERR_IO_PENDING,
- one_transaction.Start(GetRequestInfo("one.html"), &one_callback,
- BoundNetLog()));
+ one_transaction.Start(GetRequestInfo("one.html"),
+ one_callback.callback(), BoundNetLog()));
data_vector_[0]->SetStop(2);
data_vector_[0]->Run();
HttpNetworkTransaction two_transaction(session_.get());
- TestOldCompletionCallback two_callback;
+ TestCompletionCallback two_callback;
EXPECT_EQ(ERR_IO_PENDING,
- two_transaction.Start(GetRequestInfo("two.html"), &two_callback,
- BoundNetLog()));
+ two_transaction.Start(GetRequestInfo("two.html"),
+ two_callback.callback(), BoundNetLog()));
// Posted tasks should be:
// 1. MockHostResolverBase::ResolveNow
// 2. HttpStreamFactoryImpl::Job::OnStreamReadyCallback for job 1
diff --git a/net/http/http_pipelined_stream.cc b/net/http/http_pipelined_stream.cc
index 983b5f1..ba14981 100644
--- a/net/http/http_pipelined_stream.cc
+++ b/net/http/http_pipelined_stream.cc
@@ -25,19 +25,18 @@
pipeline_->OnStreamDeleted(pipeline_id_);
}
-int HttpPipelinedStream::InitializeStream(const HttpRequestInfo* request_info,
- const BoundNetLog& net_log,
- OldCompletionCallback* callback) {
+int HttpPipelinedStream::InitializeStream(
+ const HttpRequestInfo* request_info, const BoundNetLog& net_log,
+ const CompletionCallback& callback) {
request_info_ = request_info;
pipeline_->InitializeParser(pipeline_id_, request_info, net_log);
return OK;
}
-int HttpPipelinedStream::SendRequest(const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
- HttpResponseInfo* response,
- OldCompletionCallback* callback) {
+int HttpPipelinedStream::SendRequest(
+ const HttpRequestHeaders& headers, UploadDataStream* request_body,
+ HttpResponseInfo* response, const CompletionCallback& callback) {
CHECK(pipeline_id_);
CHECK(request_info_);
// TODO(simonjam): Proxy support will be needed here.
@@ -53,7 +52,8 @@
return pipeline_->GetUploadProgress(pipeline_id_);
}
-int HttpPipelinedStream::ReadResponseHeaders(OldCompletionCallback* callback) {
+int HttpPipelinedStream::ReadResponseHeaders(
+ const CompletionCallback& callback) {
return pipeline_->ReadResponseHeaders(pipeline_id_, callback);
}
@@ -62,7 +62,7 @@
}
int HttpPipelinedStream::ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
return pipeline_->ReadResponseBody(pipeline_id_, buf, buf_len, callback);
}
diff --git a/net/http/http_pipelined_stream.h b/net/http/http_pipelined_stream.h
index 6618841..6930c08 100644
--- a/net/http/http_pipelined_stream.h
+++ b/net/http/http_pipelined_stream.h
@@ -42,21 +42,21 @@
// HttpStream methods:
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual uint64 GetUploadProgress() const OVERRIDE;
- virtual int ReadResponseHeaders(OldCompletionCallback* callback) OVERRIDE;
+ virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE;
virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual void Close(bool not_reusable) OVERRIDE;
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index e4d4182d..8e6631a 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -4,6 +4,8 @@
#include "net/http/http_proxy_client_socket.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "googleurl/src/gurl.h"
@@ -35,8 +37,9 @@
bool using_spdy,
SSLClientSocket::NextProto protocol_negotiated,
bool is_https_proxy)
- : ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &HttpProxyClientSocket::OnIOComplete)),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(
+ base::Bind(&HttpProxyClientSocket::OnIOComplete,
+ base::Unretained(this)))),
next_state_(STATE_NONE),
transport_(transport_socket),
endpoint_(endpoint),
@@ -64,7 +67,7 @@
Disconnect();
}
-int HttpProxyClientSocket::RestartWithAuth(OldCompletionCallback* callback) {
+int HttpProxyClientSocket::RestartWithAuth(const CompletionCallback& callback) {
DCHECK_EQ(STATE_NONE, next_state_);
DCHECK(user_callback_.is_null());
@@ -73,10 +76,11 @@
return rv;
rv = DoLoop(OK);
- if (rv == ERR_IO_PENDING)
- if (callback) {
- user_callback_ = base::Bind(&OldCompletionCallbackAdapter, callback);
- }
+ if (rv == ERR_IO_PENDING) {
+ if (!callback.is_null())
+ user_callback_ = callback;
+ }
+
return rv;
}
@@ -371,7 +375,7 @@
int HttpProxyClientSocket::DoGenerateAuthToken() {
next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE;
- return auth_->MaybeGenerateAuthToken(&request_, &io_callback_, net_log_);
+ return auth_->MaybeGenerateAuthToken(&request_, io_callback_, net_log_);
}
int HttpProxyClientSocket::DoGenerateAuthTokenComplete(int result) {
@@ -405,7 +409,7 @@
http_stream_parser_.reset(
new HttpStreamParser(transport_.get(), &request_, parser_buf_, net_log_));
return http_stream_parser_->SendRequest(request_line_, request_headers_, NULL,
- &response_, &io_callback_);
+ &response_, io_callback_);
}
int HttpProxyClientSocket::DoSendRequestComplete(int result) {
@@ -418,7 +422,7 @@
int HttpProxyClientSocket::DoReadHeaders() {
next_state_ = STATE_READ_HEADERS_COMPLETE;
- return http_stream_parser_->ReadResponseHeaders(&io_callback_);
+ return http_stream_parser_->ReadResponseHeaders(io_callback_);
}
int HttpProxyClientSocket::DoReadHeadersComplete(int result) {
@@ -476,7 +480,7 @@
DCHECK(transport_->is_initialized());
next_state_ = STATE_DRAIN_BODY_COMPLETE;
return http_stream_parser_->ReadResponseBody(drain_buf_, kDrainBodyBufferSize,
- &io_callback_);
+ io_callback_);
}
int HttpProxyClientSocket::DoDrainBodyComplete(int result) {
diff --git a/net/http/http_proxy_client_socket.h b/net/http/http_proxy_client_socket.h
index 786eb3f..e4b1844 100644
--- a/net/http/http_proxy_client_socket.h
+++ b/net/http/http_proxy_client_socket.h
@@ -55,7 +55,7 @@
// If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then
// credentials should be added to the HttpAuthController before calling
// RestartWithAuth.
- int RestartWithAuth(OldCompletionCallback* callback);
+ int RestartWithAuth(const CompletionCallback& callback);
const scoped_refptr<HttpAuthController>& auth_controller() {
return auth_;
@@ -141,7 +141,7 @@
int DoTCPRestart();
int DoTCPRestartComplete(int result);
- OldCompletionCallbackImpl<HttpProxyClientSocket> io_callback_;
+ CompletionCallback io_callback_;
State next_state_;
// Stores the callback to the layer above, called on completing Connect().
diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc
index a353b2ca..c9831c3 100644
--- a/net/http/http_proxy_client_socket_pool.cc
+++ b/net/http/http_proxy_client_socket_pool.cc
@@ -86,8 +86,6 @@
ALLOW_THIS_IN_INITIALIZER_LIST(
callback_(base::Bind(&HttpProxyConnectJob::OnIOComplete,
base::Unretained(this)))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_old_(this, &HttpProxyConnectJob::OnIOComplete)),
using_spdy_(false),
protocol_negotiated_(SSLClientSocket::kProtoUnknown) {
}
@@ -312,10 +310,9 @@
}
next_state_ = STATE_SPDY_PROXY_CREATE_STREAM_COMPLETE;
- return spdy_session->CreateStream(params_->request_url(),
- params_->destination().priority(),
- &spdy_stream_, spdy_session->net_log(),
- &callback_old_);
+ return spdy_session->CreateStream(
+ params_->request_url(), params_->destination().priority(),
+ &spdy_stream_, spdy_session->net_log(), callback_);
}
int HttpProxyConnectJob::DoSpdyProxyCreateStreamComplete(int result) {
@@ -410,12 +407,10 @@
transport_pool_->RemoveLayeredPool(this);
}
-int HttpProxyClientSocketPool::RequestSocket(const std::string& group_name,
- const void* socket_params,
- RequestPriority priority,
- ClientSocketHandle* handle,
- OldCompletionCallback* callback,
- const BoundNetLog& net_log) {
+int HttpProxyClientSocketPool::RequestSocket(
+ const std::string& group_name, const void* socket_params,
+ RequestPriority priority, ClientSocketHandle* handle,
+ const CompletionCallback& callback, const BoundNetLog& net_log) {
const scoped_refptr<HttpProxySocketParams>* casted_socket_params =
static_cast<const scoped_refptr<HttpProxySocketParams>*>(socket_params);
diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h
index 7f505c2..6b982dc5 100644
--- a/net/http/http_proxy_client_socket_pool.h
+++ b/net/http/http_proxy_client_socket_pool.h
@@ -157,7 +157,6 @@
State next_state_;
CompletionCallback callback_;
- OldCompletionCallbackImpl<HttpProxyConnectJob> callback_old_;
scoped_ptr<ClientSocketHandle> transport_socket_handle_;
scoped_ptr<ProxyClientSocket> transport_socket_;
bool using_spdy_;
@@ -172,7 +171,8 @@
};
class NET_EXPORT_PRIVATE HttpProxyClientSocketPool
- : public ClientSocketPool, public LayeredPool {
+ : public ClientSocketPool,
+ public LayeredPool {
public:
HttpProxyClientSocketPool(
int max_sockets,
@@ -185,12 +185,12 @@
virtual ~HttpProxyClientSocketPool();
- // ClientSocketPool methods:
+ // ClientSocketPool implementation.
virtual int RequestSocket(const std::string& group_name,
const void* connect_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
virtual void RequestSockets(const std::string& group_name,
@@ -233,7 +233,7 @@
virtual ClientSocketPoolHistograms* histograms() const OVERRIDE;
- // LayeredPool methods:
+ // LayeredPool implementation.
virtual bool CloseOneIdleConnection() OVERRIDE;
private:
diff --git a/net/http/http_response_body_drainer.cc b/net/http/http_response_body_drainer.cc
index b98b3e9..34d946f 100644
--- a/net/http/http_response_body_drainer.cc
+++ b/net/http/http_response_body_drainer.cc
@@ -17,9 +17,6 @@
: stream_(stream),
next_state_(STATE_NONE),
total_read_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &HttpResponseBodyDrainer::OnIOComplete)),
- user_callback_(NULL),
session_(NULL) {}
HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {}
@@ -90,7 +87,8 @@
return stream_->ReadResponseBody(
read_buf_, read_size_ - total_read_,
- &io_callback_);
+ base::Bind(&HttpResponseBodyDrainer::OnIOComplete,
+ base::Unretained(this)));
}
int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) {
diff --git a/net/http/http_response_body_drainer.h b/net/http/http_response_body_drainer.h
index 859fd174..ff4d61a 100644
--- a/net/http/http_response_body_drainer.h
+++ b/net/http/http_response_body_drainer.h
@@ -60,8 +60,7 @@
const scoped_ptr<HttpStream> stream_;
State next_state_;
int total_read_;
- OldCompletionCallbackImpl<HttpResponseBodyDrainer> io_callback_;
- OldCompletionCallback* user_callback_;
+ CompletionCallback user_callback_;
base::OneShotTimer<HttpResponseBodyDrainer> timer_;
HttpNetworkSession* session_;
diff --git a/net/http/http_response_body_drainer_unittest.cc b/net/http/http_response_body_drainer_unittest.cc
index 7568944c..79d9f6fd25 100644
--- a/net/http/http_response_body_drainer_unittest.cc
+++ b/net/http/http_response_body_drainer_unittest.cc
@@ -65,28 +65,27 @@
public:
MockHttpStream(CloseResultWaiter* result_waiter)
: result_waiter_(result_waiter),
- user_callback_(NULL),
closed_(false),
stall_reads_forever_(false),
num_chunks_(0),
is_complete_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {}
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
virtual ~MockHttpStream() {}
- // HttpStream implementation:
+ // HttpStream implementation.
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- OldCompletionCallback* callback) OVERRIDE {
+ const CompletionCallback& callback) OVERRIDE {
return ERR_UNEXPECTED;
}
virtual int SendRequest(const HttpRequestHeaders& request_headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) OVERRIDE {
+ const CompletionCallback& callback) OVERRIDE {
return ERR_UNEXPECTED;
}
virtual uint64 GetUploadProgress() const OVERRIDE { return 0; }
- virtual int ReadResponseHeaders(OldCompletionCallback* callback) OVERRIDE {
+ virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE {
return ERR_UNEXPECTED;
}
virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE {
@@ -104,7 +103,7 @@
// Mocked API
virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual void Close(bool not_reusable) OVERRIDE {
DCHECK(!closed_);
closed_ = true;
@@ -135,18 +134,18 @@
CloseResultWaiter* const result_waiter_;
scoped_refptr<IOBuffer> user_buf_;
- OldCompletionCallback* user_callback_;
+ CompletionCallback callback_;
bool closed_;
bool stall_reads_forever_;
int num_chunks_;
bool is_complete_;
- base::WeakPtrFactory<MockHttpStream> ptr_factory_;
+ base::WeakPtrFactory<MockHttpStream> weak_factory_;
};
int MockHttpStream::ReadResponseBody(
- IOBuffer* buf, int buf_len, OldCompletionCallback* callback) {
- DCHECK(callback);
- DCHECK(!user_callback_);
+ IOBuffer* buf, int buf_len, const CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(callback_.is_null());
DCHECK(buf);
if (stall_reads_forever_)
@@ -157,10 +156,10 @@
if (buf_len > kMagicChunkSize && num_chunks_ > 1) {
user_buf_ = buf;
- user_callback_ = callback;
+ callback_ = callback;
MessageLoop::current()->PostTask(
FROM_HERE,
- base::Bind(&MockHttpStream::CompleteRead, ptr_factory_.GetWeakPtr()));
+ base::Bind(&MockHttpStream::CompleteRead, weak_factory_.GetWeakPtr()));
return ERR_IO_PENDING;
}
@@ -172,14 +171,14 @@
}
void MockHttpStream::CompleteRead() {
- OldCompletionCallback* callback = user_callback_;
+ CompletionCallback callback = callback_;
std::memset(user_buf_->data(), 1, kMagicChunkSize);
user_buf_ = NULL;
- user_callback_ = NULL;
+ callback_.Reset();
num_chunks_--;
if (!num_chunks_)
is_complete_ = true;
- callback->Run(kMagicChunkSize);
+ callback.Run(kMagicChunkSize);
}
class HttpResponseBodyDrainerTest : public testing::Test {
@@ -245,7 +244,6 @@
}
TEST_F(HttpResponseBodyDrainerTest, DrainBodyTooLarge) {
- TestOldCompletionCallback callback;
int too_many_chunks =
HttpResponseBodyDrainer::kDrainBodyBufferSize / kMagicChunkSize;
too_many_chunks += 1; // Now it's too large.
@@ -256,7 +254,6 @@
}
TEST_F(HttpResponseBodyDrainerTest, StartBodyTooLarge) {
- TestOldCompletionCallback callback;
int too_many_chunks =
HttpResponseBodyDrainer::kDrainBodyBufferSize / kMagicChunkSize;
too_many_chunks += 1; // Now it's too large.
@@ -267,7 +264,6 @@
}
TEST_F(HttpResponseBodyDrainerTest, StartWithNothingToDo) {
- TestOldCompletionCallback callback;
mock_stream_->set_num_chunks(0);
drainer_->StartWithSize(session_, 0);
EXPECT_FALSE(result_waiter_.WaitForResult());
diff --git a/net/http/http_stream.h b/net/http/http_stream.h
index 2d6402f..e52b9575 100644
--- a/net/http/http_stream.h
+++ b/net/http/http_stream.h
@@ -41,7 +41,7 @@
// Returns a net error code, possibly ERR_IO_PENDING.
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
// Writes the headers and uploads body data to the underlying socket.
// ERR_IO_PENDING is returned if the operation could not be completed
@@ -51,7 +51,7 @@
virtual int SendRequest(const HttpRequestHeaders& request_headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
// Queries the UploadDataStream for its progress (bytes sent).
virtual uint64 GetUploadProgress() const = 0;
@@ -61,7 +61,7 @@
// not be completed synchronously, in which case the result will be passed
// to the callback when available. Returns OK on success. The response
// headers are available in the HttpResponseInfo returned by GetResponseInfo
- virtual int ReadResponseHeaders(OldCompletionCallback* callback) = 0;
+ virtual int ReadResponseHeaders(const CompletionCallback& callback) = 0;
// Provides access to HttpResponseInfo (owned by HttpStream).
virtual const HttpResponseInfo* GetResponseInfo() const = 0;
@@ -77,7 +77,7 @@
// the socket acquires a reference to the provided buffer until the callback
// is invoked or the socket is destroyed.
virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
// Closes the stream.
// |not_reusable| indicates if the stream can be used for further requests.
diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc
index b29e9f1d..f401db6 100644
--- a/net/http/http_stream_factory_impl_job.cc
+++ b/net/http/http_stream_factory_impl_job.cc
@@ -115,8 +115,6 @@
proxy_ssl_config_(proxy_ssl_config),
net_log_(BoundNetLog::Make(net_log.net_log(),
NetLog::SOURCE_HTTP_STREAM_JOB)),
- ALLOW_THIS_IN_INITIALIZER_LIST(old_io_callback_(
- this, &Job::OnIOComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(
base::Bind(&Job::OnIOComplete, base::Unretained(this)))),
connection_(new ClientSocketHandle),
@@ -963,7 +961,7 @@
next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE;
HttpProxyClientSocket* http_proxy_socket =
static_cast<HttpProxyClientSocket*>(connection_->socket());
- return http_proxy_socket->RestartWithAuth(&old_io_callback_);
+ return http_proxy_socket->RestartWithAuth(io_callback_);
}
int HttpStreamFactoryImpl::Job::DoRestartTunnelAuthComplete(int result) {
diff --git a/net/http/http_stream_factory_impl_job.h b/net/http/http_stream_factory_impl_job.h
index e8ee876..e93b1113 100644
--- a/net/http/http_stream_factory_impl_job.h
+++ b/net/http/http_stream_factory_impl_job.h
@@ -209,7 +209,6 @@
SSLConfig proxy_ssl_config_;
const BoundNetLog net_log_;
- OldCompletionCallbackImpl<Job> old_io_callback_;
CompletionCallback io_callback_;
scoped_ptr<ClientSocketHandle> connection_;
HttpNetworkSession* const session_;
diff --git a/net/http/http_stream_factory_impl_unittest.cc b/net/http/http_stream_factory_impl_unittest.cc
index 8c463af..ca9ae91 100644
--- a/net/http/http_stream_factory_impl_unittest.cc
+++ b/net/http/http_stream_factory_impl_unittest.cc
@@ -202,7 +202,7 @@
const void* socket_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE {
ADD_FAILURE();
return ERR_UNEXPECTED;
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index 8969d73..64248ff 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -77,7 +77,6 @@
chunked_decoder_(NULL),
user_read_buf_(NULL),
user_read_buf_len_(0),
- user_callback_(NULL),
connection_(connection),
net_log_(net_log),
ALLOW_THIS_IN_INITIALIZER_LIST(
@@ -98,10 +97,10 @@
const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK_EQ(STATE_NONE, io_state_);
- DCHECK(!user_callback_);
- DCHECK(callback);
+ DCHECK(callback_.is_null());
+ DCHECK(!callback.is_null());
DCHECK(response);
if (net_log_.IsLoggingAllEvents()) {
@@ -137,15 +136,15 @@
io_state_ = STATE_SENDING_HEADERS;
result = DoLoop(OK);
if (result == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return result > 0 ? OK : result;
}
-int HttpStreamParser::ReadResponseHeaders(OldCompletionCallback* callback) {
+int HttpStreamParser::ReadResponseHeaders(const CompletionCallback& callback) {
DCHECK(io_state_ == STATE_REQUEST_SENT || io_state_ == STATE_DONE);
- DCHECK(!user_callback_);
- DCHECK(callback);
+ DCHECK(callback_.is_null());
+ DCHECK(!callback.is_null());
// This function can be called with io_state_ == STATE_DONE if the
// connection is closed after seeing just a 1xx response code.
@@ -165,7 +164,7 @@
result = DoLoop(result);
if (result == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return result > 0 ? OK : result;
}
@@ -177,10 +176,10 @@
}
int HttpStreamParser::ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(io_state_ == STATE_BODY_PENDING || io_state_ == STATE_DONE);
- DCHECK(!user_callback_);
- DCHECK(callback);
+ DCHECK(callback_.is_null());
+ DCHECK(!callback.is_null());
DCHECK_LE(buf_len, kMaxBufSize);
if (io_state_ == STATE_DONE)
@@ -192,7 +191,7 @@
int result = DoLoop(OK);
if (result == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return result;
}
@@ -202,10 +201,10 @@
// The client callback can do anything, including destroying this class,
// so any pending callback must be issued after everything else is done.
- if (result != ERR_IO_PENDING && user_callback_) {
- OldCompletionCallback* c = user_callback_;
- user_callback_ = NULL;
- c->Run(result);
+ if (result != ERR_IO_PENDING && !callback_.is_null()) {
+ CompletionCallback c = callback_;
+ callback_.Reset();
+ c.Run(result);
}
}
diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h
index b80145f..ae9fc3e 100644
--- a/net/http/http_stream_parser.h
+++ b/net/http/http_stream_parser.h
@@ -44,12 +44,13 @@
int SendRequest(const std::string& request_line,
const HttpRequestHeaders& headers,
UploadDataStream* request_body,
- HttpResponseInfo* response, OldCompletionCallback* callback);
+ HttpResponseInfo* response,
+ const CompletionCallback& callback);
- int ReadResponseHeaders(OldCompletionCallback* callback);
+ int ReadResponseHeaders(const CompletionCallback& callback);
int ReadResponseBody(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
void Close(bool not_reusable);
@@ -175,13 +176,13 @@
// The callback to notify a user that their request or response is
// complete or there was an error
- OldCompletionCallback* user_callback_;
+ CompletionCallback callback_;
// In the client callback, the client can do anything, including
// destroying this class, so any pending callback must be issued
// after everything else is done. When it is time to issue the client
- // callback, move it from |user_callback_| to |scheduled_callback_|.
- OldCompletionCallback* scheduled_callback_;
+ // callback, move it from |callback_| to |scheduled_callback_|.
+ CompletionCallback scheduled_callback_;
// The underlying socket.
ClientSocketHandle* const connection_;
diff --git a/net/http/http_transaction.h b/net/http/http_transaction.h
index 40be470..c3bc517 100644
--- a/net/http/http_transaction.h
+++ b/net/http/http_transaction.h
@@ -32,9 +32,9 @@
//
// Returns OK if the transaction could be started synchronously, which means
// that the request was served from the cache. ERR_IO_PENDING is returned to
- // indicate that the OldCompletionCallback will be notified once response info
- // is available or if an IO error occurs. Any other return value indicates
- // that the transaction could not be started.
+ // indicate that the CompletionCallback will be notified once response info is
+ // available or if an IO error occurs. Any other return value indicates that
+ // the transaction could not be started.
//
// Regardless of the return value, the caller is expected to keep the
// request_info object alive until Destroy is called on the transaction.
@@ -43,7 +43,7 @@
//
// Profiling information for the request is saved to |net_log| if non-NULL.
virtual int Start(const HttpRequestInfo* request_info,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) = 0;
// Restarts the HTTP transaction, ignoring the last error. This call can
@@ -56,15 +56,15 @@
//
// NOTE: The transaction is not responsible for deleting the callback object.
//
- virtual int RestartIgnoringLastError(OldCompletionCallback* callback) = 0;
+ virtual int RestartIgnoringLastError(const CompletionCallback& callback) = 0;
// Restarts the HTTP transaction with a client certificate.
virtual int RestartWithCertificate(X509Certificate* client_cert,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
// Restarts the HTTP transaction with authentication credentials.
virtual int RestartWithAuth(const AuthCredentials& credentials,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
// Returns true if auth is ready to be continued. Callers should check
// this value anytime Start() completes: if it is true, the transaction
@@ -79,9 +79,9 @@
//
// Response data is copied into the given buffer and the number of bytes
// copied is returned. ERR_IO_PENDING is returned if response data is not
- // yet available. The OldCompletionCallback is notified when the data copy
+ // yet available. The CompletionCallback is notified when the data copy
// completes, and it is passed the number of bytes that were successfully
- // copied. Or, if a read error occurs, the OldCompletionCallback is notified of
+ // copied. Or, if a read error occurs, the CompletionCallback is notified of
// the error. Any other negative return value indicates that the transaction
// could not be read.
//
@@ -90,7 +90,7 @@
// a reference to the provided buffer.
//
virtual int Read(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
// Stops further caching of this request by the HTTP cache, if there is any.
virtual void StopCaching() = 0;
diff --git a/net/http/http_transaction_unittest.cc b/net/http/http_transaction_unittest.cc
index ff86bc1..5e14521 100644
--- a/net/http/http_transaction_unittest.cc
+++ b/net/http/http_transaction_unittest.cc
@@ -161,7 +161,8 @@
void TestTransactionConsumer::Start(const net::HttpRequestInfo* request,
const net::BoundNetLog& net_log) {
state_ = STARTING;
- int result = trans_->Start(request, this, net_log);
+ int result = trans_->Start(
+ request, base::Bind(&net::OldCompletionCallbackAdapter, this), net_log);
if (result != net::ERR_IO_PENDING)
DidStart(result);
}
@@ -193,7 +194,8 @@
void TestTransactionConsumer::Read() {
state_ = READING;
read_buf_ = new net::IOBuffer(1024);
- int result = trans_->Read(read_buf_, 1024, this);
+ int result = trans_->Read(
+ read_buf_, 1024, base::Bind(&net::OldCompletionCallbackAdapter, this));
if (result != net::ERR_IO_PENDING)
DidRead(result);
}
@@ -214,7 +216,7 @@
MockNetworkTransaction::MockNetworkTransaction(MockNetworkLayer* factory)
- : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
data_cursor_(0),
transaction_factory_(factory->AsWeakPtr()) {
}
@@ -222,7 +224,7 @@
MockNetworkTransaction::~MockNetworkTransaction() {}
int MockNetworkTransaction::Start(const net::HttpRequestInfo* request,
- net::OldCompletionCallback* callback,
+ const net::CompletionCallback& callback,
const net::BoundNetLog& net_log) {
const MockTransaction* t = FindMockTransaction(request->url);
if (!t)
@@ -261,19 +263,19 @@
}
int MockNetworkTransaction::RestartIgnoringLastError(
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return net::ERR_FAILED;
}
int MockNetworkTransaction::RestartWithCertificate(
net::X509Certificate* client_cert,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return net::ERR_FAILED;
}
int MockNetworkTransaction::RestartWithAuth(
const net::AuthCredentials& credentials,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return net::ERR_FAILED;
}
@@ -282,7 +284,7 @@
}
int MockNetworkTransaction::Read(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
int data_len = static_cast<int>(data_.size());
int num = std::min(buf_len, data_len - data_cursor_);
if (num) {
@@ -317,16 +319,16 @@
return 0;
}
-void MockNetworkTransaction::CallbackLater(net::OldCompletionCallback* callback,
- int result) {
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- &MockNetworkTransaction::RunCallback, ptr_factory_.GetWeakPtr(),
- callback, result));
+void MockNetworkTransaction::CallbackLater(
+ const net::CompletionCallback& callback, int result) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&MockNetworkTransaction::RunCallback,
+ weak_factory_.GetWeakPtr(), callback, result));
}
-void MockNetworkTransaction::RunCallback(net::OldCompletionCallback* callback,
- int result) {
- callback->Run(result);
+void MockNetworkTransaction::RunCallback(
+ const net::CompletionCallback& callback, int result) {
+ callback.Run(result);
}
MockNetworkLayer::MockNetworkLayer()
@@ -359,19 +361,19 @@
int ReadTransaction(net::HttpTransaction* trans, std::string* result) {
int rv;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
std::string content;
do {
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
- rv = trans->Read(buf, 256, &callback);
+ rv = trans->Read(buf, 256, callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
- if (rv > 0) {
+
+ if (rv > 0)
content.append(buf->data(), rv);
- } else if (rv < 0) {
+ else if (rv < 0)
return rv;
- }
} while (rv > 0);
result->swap(content);
diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h
index e4ce1d61..ba24c8c 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -159,24 +159,24 @@
virtual ~MockNetworkTransaction();
virtual int Start(const net::HttpRequestInfo* request,
- net::OldCompletionCallback* callback,
+ const net::CompletionCallback& callback,
const net::BoundNetLog& net_log) OVERRIDE;
virtual int RestartIgnoringLastError(
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int RestartWithCertificate(
net::X509Certificate* client_cert,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int RestartWithAuth(
const net::AuthCredentials& credentials,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual bool IsReadyToRestartForAuth() OVERRIDE;
virtual int Read(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual void StopCaching() OVERRIDE;
@@ -189,10 +189,10 @@
virtual uint64 GetUploadProgress() const OVERRIDE;
private:
- void CallbackLater(net::OldCompletionCallback* callback, int result);
- void RunCallback(net::OldCompletionCallback* callback, int result);
+ void CallbackLater(const net::CompletionCallback& callback, int result);
+ void RunCallback(const net::CompletionCallback& callback, int result);
- base::WeakPtrFactory<MockNetworkTransaction> ptr_factory_;
+ base::WeakPtrFactory<MockNetworkTransaction> weak_factory_;
net::HttpResponseInfo response_;
std::string data_;
int data_cursor_;
diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc
index 4bdedac..24bf4f5a 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -115,8 +115,7 @@
sparse_entry_(true),
truncated_(false),
initial_validation_(false),
- core_(NULL),
- callback_(NULL) {
+ core_(NULL) {
}
PartialData::~PartialData() {
@@ -162,7 +161,7 @@
}
int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK_GE(current_range_start_, 0);
// Scan the disk cache for the first cached portion within this range.
@@ -173,7 +172,7 @@
DVLOG(3) << "ShouldValidateCache len: " << len;
if (sparse_entry_) {
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
Core* core = Core::CreateCore(this);
cached_min_len_ = core->GetAvailableRange(entry, current_range_start_, len,
&cached_start_);
@@ -481,7 +480,7 @@
}
void PartialData::GetAvailableRangeCompleted(int result, int64 start) {
- DCHECK(callback_);
+ DCHECK(!callback_.is_null());
DCHECK_NE(ERR_IO_PENDING, result);
cached_start_ = start;
@@ -489,9 +488,9 @@
if (result >= 0)
result = 1; // Return success, go ahead and validate the entry.
- OldCompletionCallback* cb = callback_;
- callback_ = NULL;
- cb->Run(result);
+ CompletionCallback cb = callback_;
+ callback_.Reset();
+ cb.Run(result);
}
} // namespace net
diff --git a/net/http/partial_data.h b/net/http/partial_data.h
index b996b985..442bbb7 100644
--- a/net/http/partial_data.h
+++ b/net/http/partial_data.h
@@ -55,7 +55,7 @@
// error code. If this method returns ERR_IO_PENDING, the |callback| will be
// notified when the result is ready.
int ShouldValidateCache(disk_cache::Entry* entry,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
// Builds the required |headers| to perform the proper cache validation for
// the next range to be fetched.
@@ -136,7 +136,7 @@
bool truncated_; // We have an incomplete 200 stored.
bool initial_validation_; // Only used for truncated entries.
Core* core_;
- OldCompletionCallback* callback_;
+ CompletionCallback callback_;
DISALLOW_COPY_AND_ASSIGN(PartialData);
};
diff --git a/net/proxy/proxy_resolver_v8.h b/net/proxy/proxy_resolver_v8.h
index ecd8d13..a74f369 100644
--- a/net/proxy/proxy_resolver_v8.h
+++ b/net/proxy/proxy_resolver_v8.h
@@ -26,7 +26,7 @@
// since only one will be running inside V8 at a time.
//
// It is important that *ALL* instances of V8 in the process be using
-// v8::Locker. If not there can be race conditions beween the non-locked V8
+// v8::Locker. If not there can be race conditions between the non-locked V8
// instances and the locked V8 instances used by ProxyResolverV8 (assuming they
// run on different threads).
//
diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc
index 6d3e4e9a..fbe9d80 100644
--- a/net/socket/client_socket_handle.cc
+++ b/net/socket/client_socket_handle.cc
@@ -4,6 +4,8 @@
#include "net/socket/client_socket_handle.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/metrics/histogram.h"
#include "base/logging.h"
@@ -18,8 +20,9 @@
pool_(NULL),
layered_pool_(NULL),
is_reused_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_(this, &ClientSocketHandle::OnIOComplete)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&ClientSocketHandle::OnIOComplete,
+ base::Unretained(this)))),
is_ssl_error_(false) {}
ClientSocketHandle::~ClientSocketHandle() {
diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h
index 003730c..c180832b 100644
--- a/net/socket/client_socket_handle.h
+++ b/net/socket/client_socket_handle.h
@@ -172,7 +172,7 @@
scoped_ptr<StreamSocket> socket_;
std::string group_name_;
bool is_reused_;
- OldCompletionCallbackImpl<ClientSocketHandle> callback_;
+ CompletionCallback callback_;
CompletionCallback user_callback_;
base::TimeDelta idle_time_;
int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation.
@@ -208,7 +208,7 @@
group_name_ = group_name;
init_time_ = base::TimeTicks::Now();
int rv = pool_->RequestSocket(
- group_name, &socket_params, priority, this, &callback_, net_log);
+ group_name, &socket_params, priority, this, callback_, net_log);
if (rv == ERR_IO_PENDING) {
user_callback_ = callback;
} else {
diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h
index 07a05a19..c8e84d0 100644
--- a/net/socket/client_socket_pool.h
+++ b/net/socket/client_socket_pool.h
@@ -78,7 +78,7 @@
const void* params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) = 0;
// RequestSockets is used to request that |num_sockets| be connected in the
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index bb7eb06..fa3c173 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -161,7 +161,7 @@
ClientSocketPoolBaseHelper::Request::Request(
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
RequestPriority priority,
bool ignore_limits,
Flags flags,
@@ -192,7 +192,7 @@
connect_job_factory_(connect_job_factory),
connect_backup_jobs_enabled_(false),
pool_generation_number_(0),
- method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK_LE(0, max_sockets_per_group);
DCHECK_LE(max_sockets_per_group, max_sockets);
@@ -212,6 +212,8 @@
NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
+ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {}
+
// InsertRequestIntoQueue inserts the request into the queue based on
// priority. Highest priorities are closest to the front. Older requests are
// prioritized over requests of equal priority.
@@ -252,7 +254,7 @@
int ClientSocketPoolBaseHelper::RequestSocket(
const std::string& group_name,
const Request* request) {
- CHECK(request->callback());
+ CHECK(!request->callback().is_null());
CHECK(request->handle());
// Cleanup any timed-out idle sockets if no timer is used.
@@ -277,7 +279,7 @@
const std::string& group_name,
const Request& request,
int num_sockets) {
- DCHECK(!request.callback());
+ DCHECK(request.callback().is_null());
DCHECK(!request.handle());
// Cleanup any timed out idle sockets if no timer is used.
@@ -1110,14 +1112,13 @@
}
void ClientSocketPoolBaseHelper::InvokeUserCallbackLater(
- ClientSocketHandle* handle, OldCompletionCallback* callback, int rv) {
+ ClientSocketHandle* handle, const CompletionCallback& callback, int rv) {
CHECK(!ContainsKey(pending_callback_map_, handle));
pending_callback_map_[handle] = CallbackResultPair(callback, rv);
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &ClientSocketPoolBaseHelper::InvokeUserCallback,
- handle));
+ base::Bind(&ClientSocketPoolBaseHelper::InvokeUserCallback,
+ weak_factory_.GetWeakPtr(), handle));
}
void ClientSocketPoolBaseHelper::InvokeUserCallback(
@@ -1129,15 +1130,15 @@
return;
CHECK(!handle->is_initialized());
- OldCompletionCallback* callback = it->second.callback;
+ CompletionCallback callback = it->second.callback;
int result = it->second.result;
pending_callback_map_.erase(it);
- callback->Run(result);
+ callback.Run(result);
}
ClientSocketPoolBaseHelper::Group::Group()
: active_socket_count_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
ClientSocketPoolBaseHelper::Group::~Group() {
CleanupBackupJob();
@@ -1147,13 +1148,13 @@
const std::string& group_name,
ClientSocketPoolBaseHelper* pool) {
// Only allow one timer pending to create a backup socket.
- if (!method_factory_.empty())
+ if (weak_factory_.HasWeakPtrs())
return;
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &Group::OnBackupSocketTimerFired, group_name, pool),
+ base::Bind(&Group::OnBackupSocketTimerFired, weak_factory_.GetWeakPtr(),
+ group_name, pool),
pool->ConnectRetryIntervalMs());
}
@@ -1207,7 +1208,7 @@
STLDeleteElements(&jobs_);
// Cancel pending backup job.
- method_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
}
} // namespace internal
diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
index 052c613..bfe5d45 100644
--- a/net/socket/client_socket_pool_base.h
+++ b/net/socket/client_socket_pool_base.h
@@ -33,6 +33,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "base/time.h"
#include "base/timer.h"
@@ -189,7 +190,7 @@
class NET_EXPORT_PRIVATE Request {
public:
Request(ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
RequestPriority priority,
bool ignore_limits,
Flags flags,
@@ -198,7 +199,7 @@
virtual ~Request();
ClientSocketHandle* handle() const { return handle_; }
- OldCompletionCallback* callback() const { return callback_; }
+ const CompletionCallback& callback() const { return callback_; }
RequestPriority priority() const { return priority_; }
bool ignore_limits() const { return ignore_limits_; }
Flags flags() const { return flags_; }
@@ -206,7 +207,7 @@
private:
ClientSocketHandle* const handle_;
- OldCompletionCallback* const callback_;
+ CompletionCallback callback_;
const RequestPriority priority_;
bool ignore_limits_;
const Flags flags_;
@@ -398,10 +399,10 @@
return pending_requests_.front()->priority();
}
- bool HasBackupJob() const { return !method_factory_.empty(); }
+ bool HasBackupJob() const { return weak_factory_.HasWeakPtrs(); }
void CleanupBackupJob() {
- method_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
}
// Set a timer to create a backup socket if it takes too long to create one.
@@ -437,7 +438,7 @@
RequestQueue pending_requests_;
int active_socket_count_; // number of active sockets used by clients
// A factory to pin the backup_job tasks.
- ScopedRunnableMethodFactory<Group> method_factory_;
+ base::WeakPtrFactory<Group> weak_factory_;
};
typedef std::map<std::string, Group*> GroupMap;
@@ -445,11 +446,12 @@
typedef std::set<ConnectJob*> ConnectJobSet;
struct CallbackResultPair {
- CallbackResultPair() : callback(NULL), result(OK) {}
- CallbackResultPair(OldCompletionCallback* callback_in, int result_in)
+ CallbackResultPair() : result(OK) {}
+ CallbackResultPair(const CompletionCallback& callback_in, int result_in)
: callback(callback_in), result(result_in) {}
+ ~CallbackResultPair();
- OldCompletionCallback* callback;
+ CompletionCallback callback;
int result;
};
@@ -541,7 +543,7 @@
// current message loop. Inserts |callback| into |pending_callback_map_|,
// keyed by |handle|.
void InvokeUserCallbackLater(
- ClientSocketHandle* handle, OldCompletionCallback* callback, int rv);
+ ClientSocketHandle* handle, const CompletionCallback& callback, int rv);
// Invokes the user callback for |handle|. By the time this task has run,
// it's possible that the request has been cancelled, so |handle| may not
@@ -594,7 +596,7 @@
std::set<LayeredPool*> higher_layer_pools_;
- ScopedRunnableMethodFactory<ClientSocketPoolBaseHelper> method_factory_;
+ base::WeakPtrFactory<ClientSocketPoolBaseHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBaseHelper);
};
@@ -607,7 +609,7 @@
class Request : public internal::ClientSocketPoolBaseHelper::Request {
public:
Request(ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
RequestPriority priority,
internal::ClientSocketPoolBaseHelper::Flags flags,
bool ignore_limits,
@@ -674,7 +676,7 @@
const scoped_refptr<SocketParams>& params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) {
Request* request =
new Request(handle, callback, priority,
@@ -692,7 +694,7 @@
int num_sockets,
const BoundNetLog& net_log) {
const Request request(NULL /* no handle */,
- NULL /* no callback */,
+ CompletionCallback(),
LOWEST,
internal::ClientSocketPoolBaseHelper::NO_IDLE_SOCKETS,
params->ignore_limits(),
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index 3520127..be1fdcd 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -425,7 +425,7 @@
const void* params,
net::RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE {
const scoped_refptr<TestSocketParams>* casted_socket_params =
static_cast<const scoped_refptr<TestSocketParams>*>(params);
@@ -728,7 +728,7 @@
TestConnectJobDelegate delegate;
ClientSocketHandle ignored;
TestClientSocketPoolBase::Request request(
- &ignored, NULL, kDefaultPriority,
+ &ignored, CompletionCallback(), kDefaultPriority,
internal::ClientSocketPoolBaseHelper::NORMAL,
false, params_, BoundNetLog());
scoped_ptr<TestConnectJob> job(
@@ -748,7 +748,7 @@
CapturingNetLog log(CapturingNetLog::kUnbounded);
TestClientSocketPoolBase::Request request(
- &ignored, NULL, kDefaultPriority,
+ &ignored, CompletionCallback(), kDefaultPriority,
internal::ClientSocketPoolBaseHelper::NORMAL,
false, params_, BoundNetLog());
// Deleted by TestConnectJobDelegate.
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc
index f4d2afd..275a403 100644
--- a/net/socket/socket_test_util.cc
+++ b/net/socket/socket_test_util.cc
@@ -340,8 +340,6 @@
NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_
<< ": Posting Quit at read " << read_index();
loop_stop_stage_ = sequence_number_;
- if (!callback_.is_null())
- callback_.Run(ERR_IO_PENDING);
}
MockRead OrderedSocketData::GetNextRead() {
@@ -1468,19 +1466,12 @@
MockTransportClientSocketPool::~MockTransportClientSocketPool() {}
int MockTransportClientSocketPool::RequestSocket(
- const std::string& group_name,
- const void* socket_params,
- RequestPriority priority,
- ClientSocketHandle* handle,
- OldCompletionCallback* callback,
- const BoundNetLog& net_log) {
+ const std::string& group_name, const void* socket_params,
+ RequestPriority priority, ClientSocketHandle* handle,
+ const CompletionCallback& callback, const BoundNetLog& net_log) {
StreamSocket* socket = client_socket_factory_->CreateTransportClientSocket(
AddressList(), net_log.net_log(), net::NetLog::Source());
- CompletionCallback cb;
- if (callback) {
- cb = base::Bind(&OldCompletionCallbackAdapter, callback);
- }
- MockConnectJob* job = new MockConnectJob(socket, handle, cb);
+ MockConnectJob* job = new MockConnectJob(socket, handle, callback);
job_list_.push_back(job);
handle->set_pool_id(1);
return job->Connect();
@@ -1579,18 +1570,12 @@
MockSOCKSClientSocketPool::~MockSOCKSClientSocketPool() {}
-int MockSOCKSClientSocketPool::RequestSocket(const std::string& group_name,
- const void* socket_params,
- RequestPriority priority,
- ClientSocketHandle* handle,
- OldCompletionCallback* callback,
- const BoundNetLog& net_log) {
- return transport_pool_->RequestSocket(group_name,
- socket_params,
- priority,
- handle,
- callback,
- net_log);
+int MockSOCKSClientSocketPool::RequestSocket(
+ const std::string& group_name, const void* socket_params,
+ RequestPriority priority, ClientSocketHandle* handle,
+ const CompletionCallback& callback, const BoundNetLog& net_log) {
+ return transport_pool_->RequestSocket(
+ group_name, socket_params, priority, handle, callback, net_log);
}
void MockSOCKSClientSocketPool::CancelRequest(
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 462db35d..393053b 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -345,10 +345,6 @@
MockRead* reads, size_t reads_count,
MockWrite* writes, size_t writes_count);
- void SetCompletionCallback(const CompletionCallback& callback) {
- callback_ = callback;
- }
-
// Posts a quit message to the current message loop, if one is running.
void EndLoop();
@@ -364,7 +360,6 @@
int sequence_number_;
int loop_stop_stage_;
- CompletionCallback callback_;
bool blocked_;
base::WeakPtrFactory<OrderedSocketData> weak_factory_;
};
@@ -942,12 +937,12 @@
int release_count() const { return release_count_; }
int cancel_count() const { return cancel_count_; }
- // TransportClientSocketPool methods.
+ // TransportClientSocketPool implementation.
virtual int RequestSocket(const std::string& group_name,
const void* socket_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
virtual void CancelRequest(const std::string& group_name,
@@ -1021,12 +1016,12 @@
virtual ~MockSOCKSClientSocketPool();
- // SOCKSClientSocketPool methods.
+ // SOCKSClientSocketPool implementation.
virtual int RequestSocket(const std::string& group_name,
const void* socket_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
virtual void CancelRequest(const std::string& group_name,
diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc
index ec47341..b492be18 100644
--- a/net/socket/socks_client_socket_pool.cc
+++ b/net/socket/socks_client_socket_pool.cc
@@ -210,12 +210,10 @@
transport_pool_->RemoveLayeredPool(this);
}
-int SOCKSClientSocketPool::RequestSocket(const std::string& group_name,
- const void* socket_params,
- RequestPriority priority,
- ClientSocketHandle* handle,
- OldCompletionCallback* callback,
- const BoundNetLog& net_log) {
+int SOCKSClientSocketPool::RequestSocket(
+ const std::string& group_name, const void* socket_params,
+ RequestPriority priority, ClientSocketHandle* handle,
+ const CompletionCallback& callback, const BoundNetLog& net_log) {
const scoped_refptr<SOCKSSocketParams>* casted_socket_params =
static_cast<const scoped_refptr<SOCKSSocketParams>*>(socket_params);
diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h
index cacf7af..9282026 100644
--- a/net/socket/socks_client_socket_pool.h
+++ b/net/socket/socks_client_socket_pool.h
@@ -118,12 +118,12 @@
virtual ~SOCKSClientSocketPool();
- // ClientSocketPool methods:
+ // ClientSocketPool implementation.
virtual int RequestSocket(const std::string& group_name,
const void* connect_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
virtual void RequestSockets(const std::string& group_name,
@@ -166,7 +166,7 @@
virtual ClientSocketPoolHistograms* histograms() const OVERRIDE;
- // LayeredPool methods:
+ // LayeredPool implementation.
virtual bool CloseOneIdleConnection() OVERRIDE;
private:
diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc
index b40d2ee8..ace6e0f3 100644
--- a/net/socket/ssl_client_socket_pool.cc
+++ b/net/socket/ssl_client_socket_pool.cc
@@ -511,7 +511,7 @@
const void* socket_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) {
const scoped_refptr<SSLSocketParams>* casted_socket_params =
static_cast<const scoped_refptr<SSLSocketParams>*>(socket_params);
diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h
index 1be34bd..03bdf94 100644
--- a/net/socket/ssl_client_socket_pool.h
+++ b/net/socket/ssl_client_socket_pool.h
@@ -190,12 +190,12 @@
virtual ~SSLClientSocketPool();
- // ClientSocketPool methods:
+ // ClientSocketPool implementation.
virtual int RequestSocket(const std::string& group_name,
const void* connect_params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
virtual void RequestSockets(const std::string& group_name,
@@ -238,13 +238,13 @@
virtual ClientSocketPoolHistograms* histograms() const OVERRIDE;
- // LayeredPool methods:
+ // LayeredPool implementation.
virtual bool CloseOneIdleConnection() OVERRIDE;
private:
typedef ClientSocketPoolBase<SSLSocketParams> PoolBase;
- // SSLConfigService::Observer methods:
+ // SSLConfigService::Observer implementation.
// When the user changes the SSL config, we flush all idle sockets so they
// won't get re-used.
diff --git a/net/socket/transport_client_socket_pool.cc b/net/socket/transport_client_socket_pool.cc
index faf12df..02d48fba 100644
--- a/net/socket/transport_client_socket_pool.cc
+++ b/net/socket/transport_client_socket_pool.cc
@@ -392,7 +392,7 @@
const void* params,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) {
const scoped_refptr<TransportSocketParams>* casted_params =
static_cast<const scoped_refptr<TransportSocketParams>*>(params);
diff --git a/net/socket/transport_client_socket_pool.h b/net/socket/transport_client_socket_pool.h
index 44309d4..a23c8b9 100644
--- a/net/socket/transport_client_socket_pool.h
+++ b/net/socket/transport_client_socket_pool.h
@@ -140,53 +140,38 @@
virtual ~TransportClientSocketPool();
- // ClientSocketPool methods:
-
+ // ClientSocketPool implementation.
virtual int RequestSocket(const std::string& group_name,
const void* resolve_info,
RequestPriority priority,
ClientSocketHandle* handle,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log) OVERRIDE;
-
virtual void RequestSockets(const std::string& group_name,
const void* params,
int num_sockets,
const BoundNetLog& net_log) OVERRIDE;
-
virtual void CancelRequest(const std::string& group_name,
ClientSocketHandle* handle) OVERRIDE;
-
virtual void ReleaseSocket(const std::string& group_name,
StreamSocket* socket,
int id) OVERRIDE;
-
virtual void Flush() OVERRIDE;
-
virtual bool IsStalled() const OVERRIDE;
-
virtual void CloseIdleSockets() OVERRIDE;
-
virtual int IdleSocketCount() const OVERRIDE;
-
virtual int IdleSocketCountInGroup(
const std::string& group_name) const OVERRIDE;
-
virtual LoadState GetLoadState(
const std::string& group_name,
const ClientSocketHandle* handle) const OVERRIDE;
-
virtual void AddLayeredPool(LayeredPool* layered_pool) OVERRIDE;
-
virtual void RemoveLayeredPool(LayeredPool* layered_pool) OVERRIDE;
-
virtual base::DictionaryValue* GetInfoAsValue(
const std::string& name,
const std::string& type,
bool include_nested_pools) const OVERRIDE;
-
virtual base::TimeDelta ConnectionTimeout() const OVERRIDE;
-
virtual ClientSocketPoolHistograms* histograms() const OVERRIDE;
private:
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 22600af8..935debda 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -730,7 +730,7 @@
int rv = auth_handler_->GenerateAuthToken(
&auth_identity_.credentials,
&request_info,
- NULL,
+ CompletionCallback(),
&auth_token);
// TODO(cbentzel): Support async auth handlers.
DCHECK_NE(ERR_IO_PENDING, rv);
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc
index 1a562ce..fcdcd3e 100644
--- a/net/spdy/spdy_http_stream.cc
+++ b/net/spdy/spdy_http_stream.cc
@@ -31,7 +31,6 @@
response_info_(NULL),
download_finished_(false),
response_headers_received_(false),
- user_callback_(NULL),
user_buffer_len_(0),
buffered_read_callback_pending_(false),
more_read_data_pending_(false),
@@ -50,7 +49,7 @@
int SpdyHttpStream::InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& stream_net_log,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(!stream_.get());
if (spdy_session_->IsClosed())
return ERR_CONNECTION_CLOSED;
@@ -82,8 +81,8 @@
return request_body_stream_->position();
}
-int SpdyHttpStream::ReadResponseHeaders(OldCompletionCallback* callback) {
- CHECK(callback);
+int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) {
+ CHECK(!callback.is_null());
CHECK(!stream_->cancelled());
if (stream_->closed())
@@ -96,17 +95,17 @@
}
// Still waiting for the response, return IO_PENDING.
- CHECK(!user_callback_);
- user_callback_ = callback;
+ CHECK(callback_.is_null());
+ callback_ = callback;
return ERR_IO_PENDING;
}
int SpdyHttpStream::ReadResponseBody(
- IOBuffer* buf, int buf_len, OldCompletionCallback* callback) {
+ IOBuffer* buf, int buf_len, const CompletionCallback& callback) {
CHECK(stream_->is_idle());
CHECK(buf);
CHECK(buf_len);
- CHECK(callback);
+ CHECK(!callback.is_null());
// If we have data buffered, complete the IO immediately.
if (!response_body_.empty()) {
@@ -135,11 +134,11 @@
return stream_->response_status();
}
- CHECK(!user_callback_);
+ CHECK(callback_.is_null());
CHECK(!user_buffer_);
CHECK_EQ(0, user_buffer_len_);
- user_callback_ = callback;
+ callback_ = callback;
user_buffer_ = buf;
user_buffer_len_ = buf_len;
return ERR_IO_PENDING;
@@ -190,7 +189,7 @@
int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
base::Time request_time = base::Time::Now();
CHECK(stream_.get());
@@ -216,7 +215,7 @@
delete request_body;
}
- CHECK(callback);
+ CHECK(!callback.is_null());
CHECK(!stream_->cancelled());
CHECK(response);
@@ -252,8 +251,8 @@
bool has_upload_data = request_body_stream_.get() != NULL;
result = stream_->SendRequest(has_upload_data);
if (result == ERR_IO_PENDING) {
- CHECK(!user_callback_);
- user_callback_ = callback;
+ CHECK(callback_.is_null());
+ callback_ = callback;
}
return result;
}
@@ -261,13 +260,13 @@
void SpdyHttpStream::Cancel() {
if (spdy_session_)
spdy_session_->CancelPendingCreateStreams(&stream_);
- user_callback_ = NULL;
+ callback_.Reset();
if (stream_)
stream_->Cancel();
}
bool SpdyHttpStream::OnSendHeadersComplete(int status) {
- if (user_callback_)
+ if (!callback_.is_null())
DoCallback(status);
return request_body_stream_.get() == NULL;
}
@@ -344,8 +343,9 @@
// frame has been received and processed. Move to framer?
response_info_->response_time = response_time;
- if (user_callback_)
+ if (!callback_.is_null())
DoCallback(status);
+
return status;
}
@@ -385,7 +385,7 @@
// We need to complete any pending buffered read now.
invoked_callback = DoBufferedReadCallback();
}
- if (!invoked_callback && user_callback_)
+ if (!invoked_callback && !callback_.is_null())
DoCallback(status);
}
@@ -441,7 +441,7 @@
int rv = 0;
if (user_buffer_) {
- rv = ReadResponseBody(user_buffer_, user_buffer_len_, user_callback_);
+ rv = ReadResponseBody(user_buffer_, user_buffer_len_, callback_);
CHECK_NE(rv, ERR_IO_PENDING);
user_buffer_ = NULL;
user_buffer_len_ = 0;
@@ -453,12 +453,12 @@
void SpdyHttpStream::DoCallback(int rv) {
CHECK_NE(rv, ERR_IO_PENDING);
- CHECK(user_callback_);
+ CHECK(!callback_.is_null());
// Since Run may result in being called back, clear user_callback_ in advance.
- OldCompletionCallback* c = user_callback_;
- user_callback_ = NULL;
- c->Run(rv);
+ CompletionCallback c = callback_;
+ callback_.Reset();
+ c.Run(rv);
}
void SpdyHttpStream::GetSSLInfo(SSLInfo* ssl_info) {
diff --git a/net/spdy/spdy_http_stream.h b/net/spdy/spdy_http_stream.h
index 2d25f17..e44f79c4 100644
--- a/net/spdy/spdy_http_stream.h
+++ b/net/spdy/spdy_http_stream.h
@@ -43,20 +43,20 @@
// Cancels any callbacks from being invoked and deletes the stream.
void Cancel();
- // HttpStream methods:
+ // HttpStream implementation.
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual uint64 GetUploadProgress() const OVERRIDE;
- virtual int ReadResponseHeaders(OldCompletionCallback* callback) OVERRIDE;
+ virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE;
virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
virtual int ReadResponseBody(IOBuffer* buf,
int buf_len,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
virtual void Close(bool not_reusable) OVERRIDE;
virtual HttpStream* RenewStreamForAuth() OVERRIDE;
virtual bool IsResponseBodyComplete() const OVERRIDE;
@@ -72,7 +72,7 @@
virtual void LogNumRttVsBytesMetrics() const OVERRIDE {}
virtual void Drain(HttpNetworkSession* session) OVERRIDE;
- // SpdyStream::Delegate methods:
+ // SpdyStream::Delegate implementation.
virtual bool OnSendHeadersComplete(int status) OVERRIDE;
virtual int OnSendBody() OVERRIDE;
virtual int OnSendBodyComplete(int status, bool* eof) OVERRIDE;
@@ -119,7 +119,7 @@
// TODO(mbelshe): is this infinite buffering?
std::list<scoped_refptr<IOBufferWithSize> > response_body_;
- OldCompletionCallback* user_callback_;
+ CompletionCallback callback_;
// User provided buffer for the ReadResponseBody() response.
scoped_refptr<IOBuffer> user_buffer_;
diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc
index b67a02b..e2c7f8e 100644
--- a/net/spdy/spdy_http_stream_unittest.cc
+++ b/net/spdy/spdy_http_stream_unittest.cc
@@ -73,7 +73,7 @@
HttpRequestInfo request;
request.method = "GET";
request.url = GURL("http://www.google.com/");
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpResponseInfo response;
HttpRequestHeaders headers;
BoundNetLog net_log;
@@ -81,10 +81,10 @@
new SpdyHttpStream(session_.get(), true));
ASSERT_EQ(
OK,
- http_stream->InitializeStream(&request, net_log, NULL));
+ http_stream->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING,
- http_stream->SendRequest(headers, NULL, &response, &callback));
+ EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
+ callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
// This triggers the MockWrite and read 2
@@ -133,19 +133,19 @@
request.upload_data->set_is_chunked(true);
request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false);
request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpResponseInfo response;
HttpRequestHeaders headers;
BoundNetLog net_log;
SpdyHttpStream http_stream(session_.get(), true);
ASSERT_EQ(
OK,
- http_stream.InitializeStream(&request, net_log, NULL));
+ http_stream.InitializeStream(&request, net_log, CompletionCallback()));
UploadDataStream* upload_stream =
UploadDataStream::Create(request.upload_data, NULL);
EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest(
- headers, upload_stream, &response, &callback));
+ headers, upload_stream, &response, callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
// This triggers the MockWrite and read 2
@@ -187,17 +187,17 @@
HttpRequestInfo request;
request.method = "GET";
request.url = GURL(full_url);
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
HttpResponseInfo response;
HttpRequestHeaders headers;
BoundNetLog net_log;
scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream(session_, true));
ASSERT_EQ(
OK,
- http_stream->InitializeStream(&request, net_log, NULL));
+ http_stream->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING,
- http_stream->SendRequest(headers, NULL, &response, &callback));
+ EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
+ callback.callback()));
spdy::SpdyHeaderBlock* spdy_header =
http_stream->stream()->spdy_headers().get();
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 7c2c3694..eb47f40 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -7,6 +7,8 @@
#include <string>
#include <vector>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "net/base/auth.h"
#include "net/base/net_log_unittest.h"
#include "net/http/http_network_session_peer.h"
@@ -57,9 +59,6 @@
spdy::SpdyFramer::set_enable_compression_default(enabled);
}
- class StartTransactionCallback;
- class DeleteSessionCallback;
-
// A helper class that handles all the initial npn/ssl setup.
class NormalSpdyTransactionHelper {
public:
@@ -150,7 +149,7 @@
// Start the transaction, read some data, finish.
void RunDefaultTest() {
- output_.rv = trans_->Start(&request_, &callback, log_);
+ output_.rv = trans_->Start(&request_, callback.callback(), log_);
// We expect an IO Pending or some sort of error.
EXPECT_LT(output_.rv, 0);
@@ -326,7 +325,7 @@
TransactionHelperResult output_;
scoped_ptr<StaticSocketDataProvider> first_transaction_;
SSLVector ssl_vector_;
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
scoped_ptr<HttpNetworkTransaction> trans_;
scoped_ptr<HttpNetworkTransaction> trans_http_;
DataVector data_vector_;
@@ -410,9 +409,9 @@
int bytes_read = 0;
scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(kSize));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
while (true) {
- int rv = trans->Read(buf, kSize, &callback);
+ int rv = trans->Read(buf, kSize, callback.callback());
if (rv == ERR_IO_PENDING) {
// Multiple transactions may be in the data set. Keep pulling off
// reads until we complete our callback.
@@ -460,15 +459,17 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
// Request the pushed path.
scoped_ptr<HttpNetworkTransaction> trans2(
new HttpNetworkTransaction(helper.session()));
- rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog());
+ rv = trans2->Start(
+ &CreateGetPushRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
MessageLoop::current()->RunAllPending();
@@ -500,6 +501,26 @@
VerifyStreamsClosed(helper);
}
+ static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper,
+ int result) {
+ helper->ResetTrans();
+ }
+
+ static void StartTransactionCallback(
+ const scoped_refptr<HttpNetworkSession>& session,
+ int result) {
+ scoped_ptr<HttpNetworkTransaction> trans(
+ new HttpNetworkTransaction(session));
+ TestCompletionCallback callback;
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/");
+ request.load_flags = 0;
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ callback.WaitForResult();
+ }
+
private:
bool google_get_request_initialized_;
bool google_post_request_initialized_;
@@ -672,19 +693,19 @@
scoped_ptr<HttpNetworkTransaction> trans3(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
+ TestCompletionCallback callback3;
HttpRequestInfo httpreq1 = CreateGetRequest();
HttpRequestInfo httpreq2 = CreateGetRequest();
HttpRequestInfo httpreq3 = CreateGetRequest();
- out.rv = trans1->Start(&httpreq1, &callback1, log);
+ out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
- out.rv = trans2->Start(&httpreq2, &callback2, log);
+ out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
- out.rv = trans3->Start(&httpreq3, &callback3, log);
+ out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
out.rv = callback1.WaitForResult();
@@ -757,15 +778,15 @@
scoped_ptr<HttpNetworkTransaction> trans2(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
HttpRequestInfo httpreq1 = CreateGetRequest();
HttpRequestInfo httpreq2 = CreateGetRequest();
- out.rv = trans1->Start(&httpreq1, &callback1, log);
+ out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
- out.rv = trans2->Start(&httpreq2, &callback2, log);
+ out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
out.rv = callback1.WaitForResult();
@@ -846,8 +867,8 @@
scoped_ptr<HttpNetworkTransaction> trans2(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
HttpRequestInfo httpreq = CreateGetRequest();
@@ -863,9 +884,9 @@
http_stream_factory->PreconnectStreams(
1, httpreq, preconnect_ssl_config, preconnect_ssl_config, log);
- out.rv = trans1->Start(&httpreq, &callback1, log);
+ out.rv = trans1->Start(&httpreq, callback1.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
- out.rv = trans2->Start(&httpreq, &callback2, log);
+ out.rv = trans2->Start(&httpreq, callback2.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
out.rv = callback1.WaitForResult();
@@ -971,24 +992,24 @@
scoped_ptr<HttpNetworkTransaction> trans3(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
+ TestCompletionCallback callback3;
HttpRequestInfo httpreq1 = CreateGetRequest();
HttpRequestInfo httpreq2 = CreateGetRequest();
HttpRequestInfo httpreq3 = CreateGetRequest();
- out.rv = trans1->Start(&httpreq1, &callback1, log);
+ out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
// run transaction 1 through quickly to force a read of our SETTINGS
// frame
out.rv = callback1.WaitForResult();
ASSERT_EQ(OK, out.rv);
- out.rv = trans2->Start(&httpreq2, &callback2, log);
+ out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
- out.rv = trans3->Start(&httpreq3, &callback3, log);
+ out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
out.rv = callback2.WaitForResult();
ASSERT_EQ(OK, out.rv);
@@ -1113,10 +1134,10 @@
scoped_ptr<HttpNetworkTransaction> trans4(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
- TestOldCompletionCallback callback3;
- TestOldCompletionCallback callback4;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
+ TestCompletionCallback callback3;
+ TestCompletionCallback callback4;
HttpRequestInfo httpreq1 = CreateGetRequest();
HttpRequestInfo httpreq2 = CreateGetRequest();
@@ -1124,18 +1145,18 @@
HttpRequestInfo httpreq4 = CreateGetRequest();
httpreq4.priority = HIGHEST;
- out.rv = trans1->Start(&httpreq1, &callback1, log);
+ out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
// run transaction 1 through quickly to force a read of our SETTINGS
// frame
out.rv = callback1.WaitForResult();
ASSERT_EQ(OK, out.rv);
- out.rv = trans2->Start(&httpreq2, &callback2, log);
+ out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
- out.rv = trans3->Start(&httpreq3, &callback3, log);
+ out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
- out.rv = trans4->Start(&httpreq4, &callback4, log);
+ out.rv = trans4->Start(&httpreq4, callback4.callback(), log);
ASSERT_EQ(ERR_IO_PENDING, out.rv);
out.rv = callback2.WaitForResult();
@@ -1247,24 +1268,24 @@
scoped_ptr<HttpNetworkTransaction> trans3(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
+ TestCompletionCallback callback3;
HttpRequestInfo httpreq1 = CreateGetRequest();
HttpRequestInfo httpreq2 = CreateGetRequest();
HttpRequestInfo httpreq3 = CreateGetRequest();
- out.rv = trans1->Start(&httpreq1, &callback1, log);
+ out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
// run transaction 1 through quickly to force a read of our SETTINGS
// frame
out.rv = callback1.WaitForResult();
ASSERT_EQ(OK, out.rv);
- out.rv = trans2->Start(&httpreq2, &callback2, log);
+ out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
- out.rv = trans3->Start(&httpreq3, &callback3, log);
+ out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
delete trans3.release();
ASSERT_EQ(out.rv, ERR_IO_PENDING);
out.rv = callback2.WaitForResult();
@@ -1297,19 +1318,28 @@
// The KillerCallback will delete the transaction on error as part of the
// callback.
-class KillerCallback : public TestOldCompletionCallback {
+class KillerCallback : public TestCompletionCallbackBase {
public:
explicit KillerCallback(HttpNetworkTransaction* transaction)
- : transaction_(transaction) {}
-
- virtual void RunWithParams(const Tuple1<int>& params) {
- if (params.a < 0)
- delete transaction_;
- TestOldCompletionCallback::RunWithParams(params);
+ : transaction_(transaction),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&KillerCallback::OnComplete, base::Unretained(this)))) {
}
+ virtual ~KillerCallback() {}
+
+ const CompletionCallback& callback() const { return callback_; }
+
private:
+ void OnComplete(int result) {
+ if (result < 0)
+ delete transaction_;
+
+ SetResult(result);
+ }
+
HttpNetworkTransaction* transaction_;
+ CompletionCallback callback_;
};
// Similar to ThreeGetsMaxConcurrrentDelete above, however, this test
@@ -1365,24 +1395,24 @@
HttpNetworkTransaction trans2(helper.session());
HttpNetworkTransaction* trans3(new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback1;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback1;
+ TestCompletionCallback callback2;
KillerCallback callback3(trans3);
HttpRequestInfo httpreq1 = CreateGetRequest();
HttpRequestInfo httpreq2 = CreateGetRequest();
HttpRequestInfo httpreq3 = CreateGetRequest();
- out.rv = trans1.Start(&httpreq1, &callback1, log);
+ out.rv = trans1.Start(&httpreq1, callback1.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
// run transaction 1 through quickly to force a read of our SETTINGS
// frame
out.rv = callback1.WaitForResult();
ASSERT_EQ(OK, out.rv);
- out.rv = trans2.Start(&httpreq2, &callback2, log);
+ out.rv = trans2.Start(&httpreq2, callback2.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
- out.rv = trans3->Start(&httpreq3, &callback3, log);
+ out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
ASSERT_EQ(out.rv, ERR_IO_PENDING);
out.rv = callback3.WaitForResult();
ASSERT_EQ(ERR_ABORTED, out.rv);
@@ -1759,8 +1789,9 @@
helper.AddDeterministicData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
data->SetStop(2);
@@ -1815,8 +1846,8 @@
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -1910,8 +1941,8 @@
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1967,8 +1998,8 @@
helper.RunPreTestSetup();
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -1992,7 +2023,7 @@
// Issue a read which will cause a WINDOW_UPDATE to be sent and window
// size increased to default.
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kUploadDataSize));
- rv = trans->Read(buf, kUploadDataSize, NULL);
+ rv = trans->Read(buf, kUploadDataSize, CompletionCallback());
EXPECT_EQ(kUploadDataSize, rv);
std::string content(buf->data(), buf->data()+kUploadDataSize);
EXPECT_STREQ(kUploadData, content.c_str());
@@ -2073,8 +2104,8 @@
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -2181,8 +2212,8 @@
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
MessageLoop::current()->RunAllPending(); // Write as much as we can.
@@ -2226,8 +2257,9 @@
helper.AddData(&data);
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
helper.ResetTrans(); // Cancel the transaction.
@@ -2265,9 +2297,10 @@
helper.AddDeterministicData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
data->SetStop(2);
@@ -2279,33 +2312,6 @@
helper.VerifyDataConsumed();
}
-class SpdyNetworkTransactionTest::StartTransactionCallback
- : public CallbackRunner< Tuple1<int> > {
- public:
- explicit StartTransactionCallback(
- const scoped_refptr<HttpNetworkSession>& session,
- NormalSpdyTransactionHelper& helper)
- : session_(session), helper_(helper) {}
-
- // We try to start another transaction, which should succeed.
- virtual void RunWithParams(const Tuple1<int>& params) {
- scoped_ptr<HttpNetworkTransaction> trans(
- new HttpNetworkTransaction(session_));
- TestOldCompletionCallback callback;
- HttpRequestInfo request;
- request.method = "GET";
- request.url = GURL("http://www.google.com/");
- request.load_flags = 0;
- int rv = trans->Start(&request, &callback, BoundNetLog());
- EXPECT_EQ(ERR_IO_PENDING, rv);
- rv = callback.WaitForResult();
- }
-
- private:
- const scoped_refptr<HttpNetworkSession>& session_;
- NormalSpdyTransactionHelper& helper_;
-};
-
// Verify that the client can correctly deal with the user callback attempting
// to start another transaction on a session that is closing down. See
// http://crbug.com/47455
@@ -2352,15 +2358,17 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
- StartTransactionCallback callback2(helper.session(), helper);
const int kSize = 3000;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize));
- rv = trans->Read(buf, kSize, &callback2);
+ rv = trans->Read(
+ buf, kSize,
+ base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback,
+ helper.session()));
// This forces an err_IO_pending, which sets the callback.
data->CompleteRead();
// This finishes the read.
@@ -2368,21 +2376,6 @@
helper.VerifyDataConsumed();
}
-class SpdyNetworkTransactionTest::DeleteSessionCallback
- : public CallbackRunner< Tuple1<int> > {
- public:
- explicit DeleteSessionCallback(NormalSpdyTransactionHelper& helper) :
- helper_(helper) {}
-
- // We kill the transaction, which deletes the session and stream.
- virtual void RunWithParams(const Tuple1<int>& params) {
- helper_.ResetTrans();
- }
-
- private:
- NormalSpdyTransactionHelper& helper_;
-};
-
// Verify that the client can correctly deal with the user callback deleting the
// transaction. Failures will usually be valgrind errors. See
// http://crbug.com/46925
@@ -2410,17 +2403,19 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
// Setup a user callback which will delete the session, and clear out the
// memory holding the stream object. Note that the callback deletes trans.
- DeleteSessionCallback callback2(helper);
const int kSize = 3000;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize));
- rv = trans->Read(buf, kSize, &callback2);
+ rv = trans->Read(
+ buf, kSize,
+ base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback,
+ base::Unretained(&helper)));
ASSERT_EQ(ERR_IO_PENDING, rv);
data->CompleteRead();
@@ -2817,8 +2812,9 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3071,8 +3067,9 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3132,8 +3129,9 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3189,8 +3187,9 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
@@ -3780,14 +3779,15 @@
writes, arraysize(writes)));
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
NormalSpdyTransactionHelper helper(CreateGetRequest(),
BoundNetLog(), GetParam());
helper.RunPreTestSetup();
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
TransactionHelperResult out = helper.output();
@@ -3801,14 +3801,14 @@
out.response_info = *response; // Make a copy so we can verify.
// Read Data
- TestOldCompletionCallback read_callback;
+ TestCompletionCallback read_callback;
std::string content;
do {
// Read small chunks at a time.
const int kSmallReadSize = 3;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize));
- rv = trans->Read(buf, kSmallReadSize, &read_callback);
+ rv = trans->Read(buf, kSmallReadSize, read_callback.callback());
if (rv == net::ERR_IO_PENDING) {
data->CompleteRead();
rv = read_callback.WaitForResult();
@@ -3877,8 +3877,9 @@
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
TransactionHelperResult out = helper.output();
@@ -3892,7 +3893,7 @@
out.response_info = *response; // Make a copy so we can verify.
// Read Data
- TestOldCompletionCallback read_callback;
+ TestCompletionCallback read_callback;
std::string content;
int reads_completed = 0;
@@ -3900,7 +3901,7 @@
// Read small chunks at a time.
const int kSmallReadSize = 14;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize));
- rv = trans->Read(buf, kSmallReadSize, &read_callback);
+ rv = trans->Read(buf, kSmallReadSize, read_callback.callback());
if (rv == net::ERR_IO_PENDING) {
data->CompleteRead();
rv = read_callback.WaitForResult();
@@ -3972,8 +3973,9 @@
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
TransactionHelperResult out = helper.output();
@@ -3987,7 +3989,7 @@
out.response_info = *response; // Make a copy so we can verify.
// Read Data
- TestOldCompletionCallback read_callback;
+ TestCompletionCallback read_callback;
std::string content;
int reads_completed = 0;
@@ -3995,7 +3997,7 @@
// Read small chunks at a time.
const int kSmallReadSize = 14;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize));
- rv = trans->Read(buf, kSmallReadSize, &read_callback);
+ rv = trans->Read(buf, kSmallReadSize, read_callback.callback());
if (rv > 0) {
EXPECT_EQ(kSmallReadSize, rv);
content.append(buf->data(), rv);
@@ -4060,9 +4062,10 @@
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
TransactionHelperResult out = helper.output();
@@ -4076,7 +4079,7 @@
out.response_info = *response; // Make a copy so we can verify.
// Read Data
- TestOldCompletionCallback read_callback;
+ TestCompletionCallback read_callback;
std::string content;
int reads_completed = 0;
@@ -4084,7 +4087,7 @@
// Read small chunks at a time.
const int kSmallReadSize = 14;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize));
- rv = trans->Read(buf, kSmallReadSize, &read_callback);
+ rv = trans->Read(buf, kSmallReadSize, read_callback.callback());
if (rv == net::ERR_IO_PENDING) {
data->CompleteRead();
rv = read_callback.WaitForResult();
@@ -4139,9 +4142,10 @@
helper.RunPreTestSetup();
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
TransactionHelperResult out = helper.output();
@@ -4155,12 +4159,12 @@
out.response_info = *response; // Make a copy so we can verify.
// Read Data
- TestOldCompletionCallback read_callback;
+ TestCompletionCallback read_callback;
do {
const int kReadSize = 256;
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kReadSize));
- rv = trans->Read(buf, kReadSize, &read_callback);
+ rv = trans->Read(buf, kReadSize, read_callback.callback());
if (rv == net::ERR_IO_PENDING) {
// Complete the read now, which causes buffering to start.
data->CompleteRead();
@@ -4451,9 +4455,9 @@
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
TransactionHelperResult out;
- out.rv = trans->Start(&CreateGetRequest(), &callback, log);
+ out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log);
EXPECT_EQ(out.rv, ERR_IO_PENDING);
out.rv = callback.WaitForResult();
@@ -4544,9 +4548,10 @@
}
helper.AddData(data.get());
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -4604,9 +4609,10 @@
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
TransactionHelperResult out;
- out.rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ out.rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(out.rv, ERR_IO_PENDING);
out.rv = callback.WaitForResult();
@@ -4720,8 +4726,9 @@
helper_proxy.AddData(data_proxy.get());
HttpNetworkTransaction* trans_proxy = helper_proxy.trans();
- TestOldCompletionCallback callback_proxy;
- int rv = trans_proxy->Start(&request_proxy, &callback_proxy, BoundNetLog());
+ TestCompletionCallback callback_proxy;
+ int rv = trans_proxy->Start(
+ &request_proxy, callback_proxy.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback_proxy.WaitForResult();
EXPECT_EQ(0, rv);
@@ -4788,8 +4795,9 @@
scoped_ptr<HttpNetworkTransaction> trans(
new HttpNetworkTransaction(helper.session()));
- TestOldCompletionCallback callback;
- int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &helper.request(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// On the second transaction, we trigger the RST.
if (i == 1) {
@@ -4926,10 +4934,10 @@
helper.RunPreTestSetup();
helper.AddData(data.get());
HttpNetworkTransaction* trans = helper.trans();
- TestOldCompletionCallback callback_start;
- const int rv_start = trans->Start(&request, &callback_start, net_log);
+ TestCompletionCallback callback;
+ const int rv_start = trans->Start(&request, callback.callback(), net_log);
EXPECT_EQ(ERR_IO_PENDING, rv_start);
- const int rv_start_complete = callback_start.WaitForResult();
+ const int rv_start_complete = callback.WaitForResult();
EXPECT_EQ(OK, rv_start_complete);
// Make sure the response has an auth challenge.
@@ -4946,8 +4954,9 @@
// Restart with a username/password.
AuthCredentials credentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
- TestOldCompletionCallback callback_restart;
- const int rv_restart = trans->RestartWithAuth(credentials, &callback_restart);
+ TestCompletionCallback callback_restart;
+ const int rv_restart = trans->RestartWithAuth(
+ credentials, callback_restart.callback());
EXPECT_EQ(ERR_IO_PENDING, rv_restart);
const int rv_restart_complete = callback_restart.WaitForResult();
EXPECT_EQ(OK, rv_restart_complete);
@@ -5128,8 +5137,9 @@
data->SetStop(3);
// Start the transaction.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
data->Run();
rv = callback.WaitForResult();
@@ -5139,7 +5149,8 @@
// headers are not yet complete.
scoped_ptr<HttpNetworkTransaction> trans2(
new HttpNetworkTransaction(helper.session()));
- rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog());
+ rv = trans2->Start(
+ &CreateGetPushRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
data->RunFor(3);
MessageLoop::current()->RunAllPending();
@@ -5277,8 +5288,9 @@
data->SetStop(4);
// Start the transaction.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
data->Run();
rv = callback.WaitForResult();
@@ -5288,7 +5300,8 @@
// headers are not yet complete.
scoped_ptr<HttpNetworkTransaction> trans2(
new HttpNetworkTransaction(helper.session()));
- rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog());
+ rv = trans2->Start(
+ &CreateGetPushRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
data->RunFor(3);
MessageLoop::current()->RunAllPending();
@@ -5591,9 +5604,9 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
+ TestCompletionCallback callback;
- int rv = trans->Start(&request, &callback, BoundNetLog());
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
@@ -5649,8 +5662,9 @@
HttpNetworkTransaction* trans = helper.trans();
// Start the transaction with basic parameters.
- TestOldCompletionCallback callback;
- int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
+ TestCompletionCallback callback;
+ int rv = trans->Start(
+ &CreateGetRequest(), callback.callback(), BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = callback.WaitForResult();
EXPECT_EQ(OK, rv);
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index 22b63d4..7267fefe 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -6,6 +6,8 @@
#include <algorithm> // min
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
@@ -29,9 +31,7 @@
const HostPortPair& proxy_server,
HttpAuthCache* auth_cache,
HttpAuthHandlerFactory* auth_handler_factory)
- : ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &SpdyProxyClientSocket::OnIOComplete)),
- next_state_(STATE_DISCONNECTED),
+ : next_state_(STATE_DISCONNECTED),
spdy_stream_(spdy_stream),
endpoint_(endpoint),
auth_(
@@ -304,7 +304,10 @@
int SpdyProxyClientSocket::DoGenerateAuthToken() {
next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE;
- return auth_->MaybeGenerateAuthToken(&request_, &io_callback_, net_log_);
+ return auth_->MaybeGenerateAuthToken(
+ &request_,
+ base::Bind(&SpdyProxyClientSocket::OnIOComplete, base::Unretained(this)),
+ net_log_);
}
int SpdyProxyClientSocket::DoGenerateAuthTokenComplete(int result) {
diff --git a/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h
index 2d594f1..b969499 100644
--- a/net/spdy/spdy_proxy_client_socket.h
+++ b/net/spdy/spdy_proxy_client_socket.h
@@ -128,7 +128,6 @@
// and returns the number of bytes read.
int PopulateUserReadBuffer();
- OldCompletionCallbackImpl<SpdyProxyClientSocket> io_callback_;
State next_state_;
// Pointer to the SPDY Stream that this sits on top of.
diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc
index 5ae0271..1357b7d 100644
--- a/net/spdy/spdy_proxy_client_socket_unittest.cc
+++ b/net/spdy/spdy_proxy_client_socket_unittest.cc
@@ -4,6 +4,8 @@
#include "net/spdy/spdy_proxy_client_socket.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/utf_string_conversions.h"
#include "net/base/address_list.h"
#include "net/base/net_log.h"
@@ -100,7 +102,6 @@
scoped_ptr<SpdyProxyClientSocket> sock_;
TestCompletionCallback read_callback_;
- TestOldCompletionCallback read_callback_old_;
TestCompletionCallback write_callback_;
scoped_refptr<DeterministicSocketData> data_;
@@ -192,7 +193,7 @@
ASSERT_EQ(
OK,
spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(),
- NULL));
+ CompletionCallback()));
// Create the SpdyProxyClientSocket
sock_.reset(
@@ -864,7 +865,7 @@
sock_->Read(NULL, 1, CompletionCallback()));
scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2));
scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream());
- stream->ReadResponseBody(buf, kLen1 + kLen2, &read_callback_old_);
+ stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback());
}
// ----------- Reads and Writes
@@ -1230,22 +1231,30 @@
// CompletionCallback that causes the SpdyProxyClientSocket to be
// deleted when Run is invoked.
-class DeleteSockCallback : public TestOldCompletionCallback {
+class DeleteSockCallback : public TestCompletionCallbackBase {
public:
explicit DeleteSockCallback(scoped_ptr<SpdyProxyClientSocket>* sock)
- : sock_(sock) {
+ : sock_(sock),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&DeleteSockCallback::OnComplete,
+ base::Unretained(this)))) {
}
virtual ~DeleteSockCallback() {
}
- virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE {
- sock_->reset(NULL);
- TestOldCompletionCallback::RunWithParams(params);
- }
+ const CompletionCallback& callback() const { return callback_; }
private:
+ void OnComplete(int result) {
+ sock_->reset(NULL);
+ SetResult(result);
+ }
+
scoped_ptr<SpdyProxyClientSocket>* sock_;
+ CompletionCallback callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback);
};
// If the socket is Reset when both a read and write are pending, and the
@@ -1275,9 +1284,7 @@
scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1));
ASSERT_EQ(ERR_IO_PENDING,
- sock_->Read(read_buf, kLen1,
- base::Bind(&OldCompletionCallbackAdapter,
- &read_callback)));
+ sock_->Read(read_buf, kLen1, read_callback.callback()));
scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1));
EXPECT_EQ(ERR_IO_PENDING, sock_->Write(write_buf, write_buf->size(),
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index b3a883b..596d5693 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -300,6 +300,10 @@
SendSettings();
}
+SpdySession::PendingCreateStream::~PendingCreateStream() {}
+
+SpdySession::CallbackResultPair::~CallbackResultPair() {}
+
SpdySession::~SpdySession() {
if (state_ != CLOSED) {
state_ = CLOSED;
@@ -402,7 +406,7 @@
RequestPriority priority,
scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
if (!max_concurrent_streams_ ||
active_streams_.size() < max_concurrent_streams_) {
return CreateStreamImpl(url, priority, spdy_stream, stream_net_log);
@@ -892,7 +896,7 @@
while (!create_stream_queues_[i].empty()) {
PendingCreateStream pending_create = create_stream_queues_[i].front();
create_stream_queues_[i].pop();
- pending_create.callback->Run(ERR_ABORTED);
+ pending_create.callback.Run(ERR_ABORTED);
}
}
@@ -1770,10 +1774,10 @@
if (it == pending_callback_map_.end())
return;
- OldCompletionCallback* callback = it->second.callback;
+ CompletionCallback callback = it->second.callback;
int result = it->second.result;
pending_callback_map_.erase(it);
- callback->Run(result);
+ callback.Run(result);
}
} // namespace net
diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h
index d79603a..139b6ef 100644
--- a/net/spdy/spdy_session.h
+++ b/net/spdy/spdy_session.h
@@ -86,7 +86,7 @@
RequestPriority priority,
scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
// Remove PendingCreateStream objects on transaction deletion
void CancelPendingCreateStreams(const scoped_refptr<SpdyStream>* spdy_stream);
@@ -237,11 +237,12 @@
int GetPeerAddress(AddressList* address) const;
int GetLocalAddress(IPEndPoint* address) const;
- // LayeredPool methods:
+ // LayeredPool implementation.
virtual bool CloseOneIdleConnection() OVERRIDE;
private:
friend class base::RefCounted<SpdySession>;
+
// Allow tests to access our innards for testing purposes.
FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, Ping);
FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, FailedPing);
@@ -251,15 +252,19 @@
PendingCreateStream(const GURL& url, RequestPriority priority,
scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log,
- OldCompletionCallback* callback)
- : url(&url), priority(priority), spdy_stream(spdy_stream),
- stream_net_log(&stream_net_log), callback(callback) { }
+ const CompletionCallback& callback)
+ : url(&url),
+ priority(priority),
+ spdy_stream(spdy_stream),
+ stream_net_log(&stream_net_log),
+ callback(callback) {}
+ ~PendingCreateStream();
const GURL* url;
RequestPriority priority;
scoped_refptr<SpdyStream>* spdy_stream;
const BoundNetLog* stream_net_log;
- OldCompletionCallback* callback;
+ CompletionCallback callback;
};
typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> >
PendingCreateStreamQueue;
@@ -270,10 +275,11 @@
struct CallbackResultPair {
CallbackResultPair() : result(OK) {}
- CallbackResultPair(OldCompletionCallback* callback_in, int result_in)
+ CallbackResultPair(const CompletionCallback& callback_in, int result_in)
: callback(callback_in), result(result_in) {}
+ ~CallbackResultPair();
- OldCompletionCallback* callback;
+ CompletionCallback callback;
int result;
};
diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc
index 5aaf6bd..fbacb02 100644
--- a/net/spdy/spdy_session_unittest.cc
+++ b/net/spdy/spdy_session_unittest.cc
@@ -29,7 +29,7 @@
class TestSpdyStreamDelegate : public net::SpdyStream::Delegate {
public:
- explicit TestSpdyStreamDelegate(OldCompletionCallback* callback)
+ explicit TestSpdyStreamDelegate(const CompletionCallback& callback)
: callback_(callback) {}
virtual ~TestSpdyStreamDelegate() {}
@@ -56,18 +56,17 @@
}
virtual void OnClose(int status) {
- OldCompletionCallback* callback = callback_;
- callback_ = NULL;
- callback->Run(OK);
+ CompletionCallback callback = callback_;
+ callback_.Reset();
+ callback.Run(OK);
}
virtual void set_chunk_callback(net::ChunkCallback *) {}
private:
- OldCompletionCallback* callback_;
+ CompletionCallback callback_;
};
-
// Test the SpdyIOBuffer class.
TEST_F(SpdySessionTest, SpdyIOBuffer) {
std::priority_queue<SpdyIOBuffer> queue_;
@@ -219,14 +218,14 @@
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
scoped_refptr<SpdyStream> spdy_stream1;
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
EXPECT_EQ(OK, session->CreateStream(url,
MEDIUM,
&spdy_stream1,
BoundNetLog(),
- &callback1));
+ callback1.callback()));
scoped_ptr<TestSpdyStreamDelegate> delegate(
- new TestSpdyStreamDelegate(&callback1));
+ new TestSpdyStreamDelegate(callback1.callback()));
spdy_stream1->SetDelegate(delegate.get());
base::TimeTicks before_ping_time = base::TimeTicks::Now();
@@ -307,14 +306,14 @@
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
scoped_refptr<SpdyStream> spdy_stream1;
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
EXPECT_EQ(OK, session->CreateStream(url,
MEDIUM,
&spdy_stream1,
BoundNetLog(),
- &callback1));
+ callback1.callback()));
scoped_ptr<TestSpdyStreamDelegate> delegate(
- new TestSpdyStreamDelegate(&callback1));
+ new TestSpdyStreamDelegate(callback1.callback()));
spdy_stream1->SetDelegate(delegate.get());
// Enable sending of PING.
@@ -349,32 +348,38 @@
session = NULL;
}
-class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > {
+class StreamReleaserCallback : public TestCompletionCallbackBase {
public:
StreamReleaserCallback(SpdySession* session,
SpdyStream* first_stream)
- : session_(session), first_stream_(first_stream) {}
- ~StreamReleaserCallback() {}
+ : session_(session),
+ first_stream_(first_stream),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&StreamReleaserCallback::OnComplete,
+ base::Unretained(this)))) {
+ }
- int WaitForResult() { return callback_.WaitForResult(); }
+ virtual ~StreamReleaserCallback() {}
- virtual void RunWithParams(const Tuple1<int>& params) {
+ scoped_refptr<SpdyStream>* stream() { return &stream_; }
+
+ const CompletionCallback& callback() const { return callback_; }
+
+ private:
+ void OnComplete(int result) {
session_->CloseSessionOnError(ERR_FAILED, false);
session_ = NULL;
first_stream_->Cancel();
first_stream_ = NULL;
stream_->Cancel();
stream_ = NULL;
- callback_.RunWithParams(params);
+ SetResult(result);
}
- scoped_refptr<SpdyStream>* stream() { return &stream_; }
-
- private:
scoped_refptr<SpdySession> session_;
scoped_refptr<SpdyStream> first_stream_;
scoped_refptr<SpdyStream> stream_;
- TestOldCompletionCallback callback_;
+ CompletionCallback callback_;
};
// TODO(kristianm): Could also test with more sessions where some are idle,
@@ -392,13 +397,13 @@
scoped_refptr<SpdySession> session1 =
spdy_session_pool->Get(pair1, BoundNetLog());
scoped_refptr<SpdyStream> spdy_stream1;
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
GURL url1(kTestHost1);
EXPECT_EQ(OK, session1->CreateStream(url1,
MEDIUM, /* priority, not important */
&spdy_stream1,
BoundNetLog(),
- &callback1));
+ callback1.callback()));
// Set up session 2
const std::string kTestHost2("http://www.b.com");
@@ -407,13 +412,11 @@
scoped_refptr<SpdySession> session2 =
spdy_session_pool->Get(pair2, BoundNetLog());
scoped_refptr<SpdyStream> spdy_stream2;
- TestOldCompletionCallback callback2;
+ TestCompletionCallback callback2;
GURL url2(kTestHost2);
- EXPECT_EQ(OK, session2->CreateStream(url2,
- MEDIUM, /* priority, not important */
- &spdy_stream2,
- BoundNetLog(),
- &callback2));
+ EXPECT_EQ(OK, session2->CreateStream(
+ url2, MEDIUM, /* priority, not important */
+ &spdy_stream2, BoundNetLog(), callback2.callback()));
// Set up session 3
const std::string kTestHost3("http://www.c.com");
@@ -422,13 +425,11 @@
scoped_refptr<SpdySession> session3 =
spdy_session_pool->Get(pair3, BoundNetLog());
scoped_refptr<SpdyStream> spdy_stream3;
- TestOldCompletionCallback callback3;
+ TestCompletionCallback callback3;
GURL url3(kTestHost3);
- EXPECT_EQ(OK, session3->CreateStream(url3,
- MEDIUM, /* priority, not important */
- &spdy_stream3,
- BoundNetLog(),
- &callback3));
+ EXPECT_EQ(OK, session3->CreateStream(
+ url3, MEDIUM, /* priority, not important */
+ &spdy_stream3, BoundNetLog(), callback3.callback()));
// All sessions are active and not closed
EXPECT_TRUE(session1->is_active());
@@ -551,14 +552,14 @@
// Create 2 streams. First will succeed. Second will be pending.
scoped_refptr<SpdyStream> spdy_stream1;
- TestOldCompletionCallback callback1;
+ TestCompletionCallback callback1;
GURL url("http://www.google.com");
EXPECT_EQ(OK,
session->CreateStream(url,
MEDIUM, /* priority, not important */
&spdy_stream1,
BoundNetLog(),
- &callback1));
+ callback1.callback()));
StreamReleaserCallback stream_releaser(session, spdy_stream1);
@@ -567,7 +568,7 @@
MEDIUM, /* priority, not important */
stream_releaser.stream(),
BoundNetLog(),
- &stream_releaser));
+ stream_releaser.callback()));
// Make sure |stream_releaser| holds the last refs.
session = NULL;
@@ -635,7 +636,7 @@
// Use scoped_ptr to let us invalidate the memory when we want to, to trigger
// a valgrind error if the callback is invoked when it's not supposed to be.
- scoped_ptr<TestOldCompletionCallback> callback(new TestOldCompletionCallback);
+ scoped_ptr<TestCompletionCallback> callback(new TestCompletionCallback);
// Create 2 streams. First will succeed. Second will be pending.
scoped_refptr<SpdyStream> spdy_stream1;
@@ -645,7 +646,7 @@
MEDIUM, /* priority, not important */
&spdy_stream1,
BoundNetLog(),
- callback.get()));
+ callback->callback()));
scoped_refptr<SpdyStream> spdy_stream2;
ASSERT_EQ(ERR_IO_PENDING,
@@ -653,7 +654,7 @@
MEDIUM, /* priority, not important */
&spdy_stream2,
BoundNetLog(),
- callback.get()));
+ callback->callback()));
// Release the first one, this will allow the second to be created.
spdy_stream1->Cancel();
diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc
index 4ebe693d..bb47dceb 100644
--- a/net/spdy/spdy_stream_unittest.cc
+++ b/net/spdy/spdy_stream_unittest.cc
@@ -196,7 +196,8 @@
scoped_refptr<SpdyStream> stream;
ASSERT_EQ(
OK,
- session->CreateStream(url, LOWEST, &stream, BoundNetLog(), NULL));
+ session->CreateStream(url, LOWEST, &stream, BoundNetLog(),
+ CompletionCallback()));
scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8));
memcpy(buf->data(), "\0hello!\xff", 8);
TestOldCompletionCallback callback;
diff --git a/net/spdy/spdy_websocket_stream.cc b/net/spdy/spdy_websocket_stream.cc
index fcbb31e0..0ea15c5 100644
--- a/net/spdy/spdy_websocket_stream.cc
+++ b/net/spdy/spdy_websocket_stream.cc
@@ -4,6 +4,8 @@
#include "net/spdy/spdy_websocket_stream.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
#include "net/base/io_buffer.h"
@@ -18,9 +20,7 @@
SpdySession* spdy_session, Delegate* delegate)
: stream_(NULL),
spdy_session_(spdy_session),
- delegate_(delegate),
- ALLOW_THIS_IN_INITIALIZER_LIST(spdy_stream_created_callback_(
- this, &SpdyWebSocketStream::OnSpdyStreamCreated)) {
+ delegate_(delegate) {
DCHECK(spdy_session_);
DCHECK(delegate_);
}
@@ -44,7 +44,8 @@
int result = spdy_session_->CreateStream(
url, request_priority, &stream_, net_log,
- &spdy_stream_created_callback_);
+ base::Bind(&SpdyWebSocketStream::OnSpdyStreamCreated,
+ base::Unretained(this)));
if (result == OK) {
DCHECK(stream_);
diff --git a/net/spdy/spdy_websocket_stream.h b/net/spdy/spdy_websocket_stream.h
index 1f0839e..d39c97c 100644
--- a/net/spdy/spdy_websocket_stream.h
+++ b/net/spdy/spdy_websocket_stream.h
@@ -89,8 +89,6 @@
scoped_refptr<SpdySession> spdy_session_;
Delegate* delegate_;
- OldCompletionCallbackImpl<SpdyWebSocketStream> spdy_stream_created_callback_;
-
DISALLOW_COPY_AND_ASSIGN(SpdyWebSocketStream);
};
diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc
index 310fe87a..7b8c7e25 100644
--- a/net/tools/fetch/fetch_client.cc
+++ b/net/tools/fetch/fetch_client.cc
@@ -5,6 +5,8 @@
#include "build/build_config.h"
#include "base/at_exit.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/message_loop.h"
@@ -56,11 +58,7 @@
public:
Client(net::HttpTransactionFactory* factory, const std::string& url) :
url_(url),
- buffer_(new net::IOBuffer(kBufferSize)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- connect_callback_(this, &Client::OnConnectComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- read_callback_(this, &Client::OnReadComplete)) {
+ buffer_(new net::IOBuffer(kBufferSize)) {
int rv = factory->CreateTransaction(&transaction_);
DCHECK_EQ(net::OK, rv);
buffer_->AddRef();
@@ -68,14 +66,18 @@
request_info_.url = url_;
request_info_.method = "GET";
int state = transaction_->Start(
- &request_info_, &connect_callback_, net::BoundNetLog());
+ &request_info_,
+ base::Bind(&Client::OnConnectComplete, base::Unretained(this)),
+ net::BoundNetLog());
DCHECK(state == net::ERR_IO_PENDING);
};
private:
void OnConnectComplete(int result) {
// Do work here.
- int state = transaction_->Read(buffer_.get(), kBufferSize, &read_callback_);
+ int state = transaction_->Read(
+ buffer_.get(), kBufferSize,
+ base::Bind(&Client::OnReadComplete, base::Unretained(this)));
if (state == net::ERR_IO_PENDING)
return; // IO has started.
if (state < 0)
@@ -94,7 +96,9 @@
bytes_read.Add(result);
// Issue a read for more data.
- int state = transaction_->Read(buffer_.get(), kBufferSize, &read_callback_);
+ int state = transaction_->Read(
+ buffer_.get(), kBufferSize,
+ base::Bind(&Client::OnReadComplete, base::Unretained(this)));
if (state == net::ERR_IO_PENDING)
return; // IO has started.
if (state < 0)
@@ -114,8 +118,6 @@
net::HttpRequestInfo request_info_;
scoped_ptr<net::HttpTransaction> transaction_;
scoped_refptr<net::IOBuffer> buffer_;
- net::OldCompletionCallbackImpl<Client> connect_callback_;
- net::OldCompletionCallbackImpl<Client> read_callback_;
};
int main(int argc, char** argv) {
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index c5b7a2ed9..8ad9dd1 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -200,9 +200,8 @@
proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
server_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_(
- this, &URLRequestHttpJob::OnStartCompleted)),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
- this, &URLRequestHttpJob::OnReadCompleted)),
+ base::Bind(&URLRequestHttpJob::OnStartCompleted,
+ base::Unretained(this)))),
ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_(
base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback,
base::Unretained(this)))),
@@ -338,7 +337,7 @@
}
if (transaction_.get()) {
- rv = transaction_->RestartWithAuth(auth_credentials_, &start_callback_);
+ rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_);
auth_credentials_ = AuthCredentials();
} else {
DCHECK(request_->context());
@@ -350,7 +349,7 @@
if (!URLRequestThrottlerManager::GetInstance()->enforce_throttling() ||
!throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) {
rv = transaction_->Start(
- &request_info_, &start_callback_, request_->net_log());
+ &request_info_, start_callback_, request_->net_log());
start_time_ = base::TimeTicks::Now();
} else {
// Special error code for the exponential back-off module.
@@ -1025,7 +1024,7 @@
// be notifying our consumer asynchronously via OnStartCompleted.
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
- int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_);
+ int rv = transaction_->RestartWithCertificate(client_cert, start_callback_);
if (rv == ERR_IO_PENDING)
return;
@@ -1050,7 +1049,7 @@
// be notifying our consumer asynchronously via OnStartCompleted.
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
- int rv = transaction_->RestartIgnoringLastError(&start_callback_);
+ int rv = transaction_->RestartIgnoringLastError(start_callback_);
if (rv == ERR_IO_PENDING)
return;
@@ -1090,7 +1089,9 @@
DCHECK(bytes_read);
DCHECK(!read_in_progress_);
- int rv = transaction_->Read(buf, buf_size, &read_callback_);
+ int rv = transaction_->Read(
+ buf, buf_size,
+ base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this)));
if (ShouldFixMismatchedContentLength(rv))
rv = 0;
diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h
index a3b475d1..41dec65 100644
--- a/net/url_request/url_request_http_job.h
+++ b/net/url_request/url_request_http_job.h
@@ -105,8 +105,7 @@
AuthState server_auth_state_;
AuthCredentials auth_credentials_;
- OldCompletionCallbackImpl<URLRequestHttpJob> start_callback_;
- OldCompletionCallbackImpl<URLRequestHttpJob> read_callback_;
+ CompletionCallback start_callback_;
CompletionCallback notify_before_headers_sent_callback_;
bool read_in_progress_;