summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-20 23:22:41 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-20 23:22:41 +0000
commit49639fa94a527376c0e9b93d4c54c1b8c835c041 (patch)
treedd03b9fd758c7b19b25e9934f9de9def738cdc33 /net/http
parent5fc2429ede8409759abf8d0c23ef5076e8e31fcf (diff)
downloadchromium_src-49639fa94a527376c0e9b93d4c54c1b8c835c041.zip
chromium_src-49639fa94a527376c0e9b93d4c54c1b8c835c041.tar.gz
chromium_src-49639fa94a527376c0e9b93d4c54c1b8c835c041.tar.bz2
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
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_auth_cache_unittest.cc2
-rw-r--r--net/http/http_auth_controller.cc34
-rw-r--r--net/http/http_auth_controller.h5
-rw-r--r--net/http/http_auth_controller_unittest.cc12
-rw-r--r--net/http/http_auth_handler.cc34
-rw-r--r--net/http/http_auth_handler.h17
-rw-r--r--net/http/http_auth_handler_basic.cc6
-rw-r--r--net/http/http_auth_handler_basic.h2
-rw-r--r--net/http/http_auth_handler_basic_unittest.cc2
-rw-r--r--net/http/http_auth_handler_digest.cc6
-rw-r--r--net/http/http_auth_handler_digest.h2
-rw-r--r--net/http/http_auth_handler_digest_unittest.cc6
-rw-r--r--net/http/http_auth_handler_mock.cc41
-rw-r--r--net/http/http_auth_handler_mock.h8
-rw-r--r--net/http/http_auth_handler_negotiate.cc19
-rw-r--r--net/http/http_auth_handler_negotiate.h4
-rw-r--r--net/http/http_auth_handler_negotiate_unittest.cc28
-rw-r--r--net/http/http_auth_handler_ntlm.cc6
-rw-r--r--net/http/http_auth_handler_ntlm.h2
-rw-r--r--net/http/http_auth_handler_unittest.cc4
-rw-r--r--net/http/http_basic_stream.cc12
-rw-r--r--net/http/http_basic_stream.h8
-rw-r--r--net/http/http_cache.cc20
-rw-r--r--net/http/http_cache_transaction.cc62
-rw-r--r--net/http/http_cache_transaction.h19
-rw-r--r--net/http/http_cache_unittest.cc173
-rw-r--r--net/http/http_network_layer_unittest.cc4
-rw-r--r--net/http/http_network_transaction.cc53
-rw-r--r--net/http/http_network_transaction.h17
-rw-r--r--net/http/http_network_transaction_unittest.cc688
-rw-r--r--net/http/http_pipelined_connection_impl.cc81
-rw-r--r--net/http/http_pipelined_connection_impl.h19
-rw-r--r--net/http/http_pipelined_connection_impl_unittest.cc339
-rw-r--r--net/http/http_pipelined_network_transaction_unittest.cc120
-rw-r--r--net/http/http_pipelined_stream.cc18
-rw-r--r--net/http/http_pipelined_stream.h8
-rw-r--r--net/http/http_proxy_client_socket.cc26
-rw-r--r--net/http/http_proxy_client_socket.h4
-rw-r--r--net/http/http_proxy_client_socket_pool.cc19
-rw-r--r--net/http/http_proxy_client_socket_pool.h10
-rw-r--r--net/http/http_response_body_drainer.cc6
-rw-r--r--net/http/http_response_body_drainer.h3
-rw-r--r--net/http/http_response_body_drainer_unittest.cc36
-rw-r--r--net/http/http_stream.h8
-rw-r--r--net/http/http_stream_factory_impl_job.cc4
-rw-r--r--net/http/http_stream_factory_impl_job.h1
-rw-r--r--net/http/http_stream_factory_impl_unittest.cc2
-rw-r--r--net/http/http_stream_parser.cc33
-rw-r--r--net/http/http_stream_parser.h13
-rw-r--r--net/http/http_transaction.h20
-rw-r--r--net/http/http_transaction_unittest.cc44
-rw-r--r--net/http/http_transaction_unittest.h16
-rw-r--r--net/http/partial_data.cc15
-rw-r--r--net/http/partial_data.h4
54 files changed, 1096 insertions, 1049 deletions
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 @@ class MockAuthHandler : public HttpAuthHandler {
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 @@ HttpAuthController::HttpAuthController(
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 @@ int HttpAuthController::MaybeGenerateAuthToken(const HttpRequestInfo* request,
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 @@ void HttpAuthController::OnIOComplete(int result) {
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 @@ class NET_EXPORT_PRIVATE HttpAuthController
// 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 @@ class NET_EXPORT_PRIVATE HttpAuthController
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..a50d767 100644
--- a/net/http/http_auth_controller_unittest.cc
+++ b/net/http/http_auth_controller_unittest.cc
@@ -77,10 +77,10 @@ void RunSingleRoundAuthTest(HandlerRunMode run_mode,
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 @@ TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) {
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 @@ TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) {
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 @@ TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) {
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 @@ HttpAuthHandler::HttpAuthHandler()
: 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 @@ NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) {
} // 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 @@ bool HttpAuthHandler::AllowsExplicitCredentials() {
}
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 @@ class NET_EXPORT_PRIVATE HttpAuthHandler {
// 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 @@ class NET_EXPORT_PRIVATE HttpAuthHandler {
// 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 @@ class NET_EXPORT_PRIVATE HttpAuthHandler {
// 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 @@ class NET_EXPORT_PRIVATE HttpAuthHandler {
// 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 @@ class NET_EXPORT_PRIVATE HttpAuthHandler {
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 @@ HttpAuth::AuthorizationResult HttpAuthHandlerBasic::HandleAnotherChallenge(
}
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 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerBasic : public HttpAuthHandler {
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 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) {
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 2b5c026..7ac8b1c 100644
--- a/net/http/http_auth_handler_digest.cc
+++ b/net/http/http_auth_handler_digest.cc
@@ -137,10 +137,8 @@ bool HttpAuthHandlerDigest::Init(HttpAuth::ChallengeTokenizer* challenge) {
}
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 03406a2..e960779 100644
--- a/net/http/http_auth_handler_digest.h
+++ b/net/http/http_auth_handler_digest.h
@@ -86,7 +86,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerDigest : public HttpAuthHandler {
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 0bce2a4..c5549e7 100644
--- a/net/http/http_auth_handler_digest_unittest.cc
+++ b/net/http/http_auth_handler_digest_unittest.cc
@@ -63,13 +63,13 @@ bool RespondToChallenge(HttpAuth::Target target,
// 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..8ed8f31 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 @@ bool HttpAuthHandlerMock::NeedsCanonicalName() {
}
}
-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 @@ int HttpAuthHandlerMock::ResolveCanonicalName(HostResolver* host_resolver,
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 @@ bool HttpAuthHandlerMock::Init(HttpAuth::ChallengeTokenizer* challenge) {
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 @@ int HttpAuthHandlerMock::GenerateAuthTokenImpl(
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 @@ class HttpAuthHandlerMock : public HttpAuthHandler {
virtual bool NeedsCanonicalName();
virtual int ResolveCanonicalName(HostResolver* host_resolver,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
void SetGenerateExpectation(bool async, int rv);
@@ -99,7 +99,7 @@ class HttpAuthHandlerMock : public HttpAuthHandler {
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
@@ -108,8 +108,8 @@ class HttpAuthHandlerMock : public HttpAuthHandler {
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 @@ HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate(
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 @@ bool HttpAuthHandlerNegotiate::Init(HttpAuth::ChallengeTokenizer* challenge) {
}
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 HttpAuthHandlerNegotiate::GenerateAuthTokenImpl(
}
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
@@ -245,10 +242,10 @@ void HttpAuthHandlerNegotiate::OnIOComplete(int result) {
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 868d88a..9e00c3b 100644
--- a/net/http/http_auth_handler_negotiate.h
+++ b/net/http/http_auth_handler_negotiate.h
@@ -118,7 +118,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerNegotiate : public HttpAuthHandler {
virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
const HttpRequestInfo* request,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
std::string* auth_token) OVERRIDE;
private:
@@ -156,7 +156,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerNegotiate : public HttpAuthHandler {
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 4c013d2..f43e39a 100644
--- a/net/http/http_auth_handler_negotiate_unittest.cc
+++ b/net/http/http_auth_handler_negotiate_unittest.cc
@@ -220,11 +220,11 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) {
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 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) {
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 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) {
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 @@ TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) {
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 @@ TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) {
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 @@ TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) {
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 @@ TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) {
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 @@ bool HttpAuthHandlerNTLM::Init(HttpAuth::ChallengeTokenizer* tok) {
}
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 542fd82..eb87795 100644
--- a/net/http/http_auth_handler_ntlm.h
+++ b/net/http/http_auth_handler_ntlm.h
@@ -121,7 +121,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerNTLM : public HttpAuthHandler {
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 011c689..84809e1 100644
--- a/net/http/http_auth_handler_unittest.cc
+++ b/net/http/http_auth_handler_unittest.cc
@@ -29,7 +29,7 @@ TEST(HttpAuthHandlerTest, NetLog) {
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 @@ TEST(HttpAuthHandlerTest, NetLog) {
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(ClientSocketHandle* connection,
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::InitializeStream(const HttpRequestInfo* request_info,
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 @@ uint64 HttpBasicStream::GetUploadProgress() const {
return parser_->GetUploadProgress();
}
-int HttpBasicStream::ReadResponseHeaders(OldCompletionCallback* callback) {
+int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) {
return parser_->ReadResponseHeaders(callback);
}
@@ -75,7 +75,7 @@ const HttpResponseInfo* HttpBasicStream::GetResponseInfo() const {
}
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 @@ class HttpBasicStream : public HttpStream {
// 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 @@ class HttpCache::WorkItem {
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::BackendCallback : public CallbackRunner<Tuple1<int> > {
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 @@ class HttpCache::MetadataWriter {
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 @@ void HttpCache::MetadataWriter::Write(const GURL& url,
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 @@ void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) {
// 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 @@ void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) {
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..58ad27e 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -107,7 +107,6 @@ HttpCache::Transaction::Transaction(HttpCache* cache)
entry_(NULL),
new_entry_(NULL),
network_trans_(NULL),
- callback_(NULL),
new_response_(NULL),
mode_(NONE),
target_state_(STATE_NONE),
@@ -123,8 +122,8 @@ HttpCache::Transaction::Transaction(HttpCache* cache)
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(HttpCache* cache)
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 @@ const BoundNetLog& HttpCache::Transaction::net_log() const {
}
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::Start(const HttpRequestInfo* request,
}
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::RestartIgnoringLastError(
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::RestartWithCertificate(
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 @@ bool HttpCache::Transaction::IsReadyToRestartForAuth() {
}
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 @@ int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len,
}
if (rv == ERR_IO_PENDING) {
- DCHECK(!callback_);
+ DCHECK(callback_.is_null());
callback_ = callback;
}
return rv;
@@ -415,18 +414,19 @@ uint64 HttpCache::Transaction::GetUploadProgress() const {
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 @@ int HttpCache::Transaction::DoSendRequest() {
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::DoSuccessfulSendRequest() {
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 @@ int HttpCache::Transaction::DoStartPartialCacheValidation() {
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 @@ int HttpCache::Transaction::RestartNetworkRequest() {
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 @@ int HttpCache::Transaction::RestartNetworkRequestWithCertificate(
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 @@ int HttpCache::Transaction::RestartNetworkRequestWithAuth(
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..7629c0b 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -93,23 +93,24 @@ class HttpCache::Transaction : public HttpTransaction {
// 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 @@ class HttpCache::Transaction : public HttpTransaction {
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 @@ class HttpCache::Transaction : public HttpTransaction {
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 @@ void RunTransactionTestWithRequestAndLog(net::HttpCache* cache,
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 @@ void RunTransactionTestWithRequestAndLog(net::HttpCache* cache,
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 @@ struct Context {
Context() : result(net::ERR_IO_PENDING) {}
int result;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans;
};
@@ -503,7 +503,7 @@ TEST(HttpCache, SimpleGETWithDiskFailures2) {
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 @@ TEST(HttpCache, SimpleGETWithDiskFailures3) {
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 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
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 @@ TEST(HttpCache, SimpleGET_ManyReaders) {
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 @@ TEST(HttpCache, SimpleGET_RacingReaders) {
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 @@ TEST(HttpCache, SimpleGET_DoomWithPending) {
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 @@ TEST(HttpCache, FastNoStoreGET_DoneWithPending) {
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 @@ TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
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 @@ TEST(HttpCache, SimpleGET_ManyWriters_CancelCreate) {
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 @@ TEST(HttpCache, SimpleGET_CancelCreate) {
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 @@ TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) {
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 @@ TEST(HttpCache, SimpleGET_AbandonedCacheRead) {
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 @@ TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) {
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 @@ TEST(HttpCache, SimpleGET_WaitForBackend) {
}
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 @@ TEST(HttpCache, SimpleGET_WaitForBackend_CancelCreate) {
}
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 @@ TEST(HttpCache, DeleteCacheWaitingForBackend) {
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 @@ TEST(HttpCache, DeleteCacheWaitingForBackend2) {
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 @@ TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) {
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 @@ TEST(HttpCache, RangeGET_Cancel) {
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 @@ TEST(HttpCache, RangeGET_Cancel) {
// 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 @@ TEST(HttpCache, RangeGET_Cancel2) {
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 @@ TEST(HttpCache, RangeGET_Cancel2) {
// 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 @@ TEST(HttpCache, RangeGET_Cancel3) {
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 @@ TEST(HttpCache, RangeGET_Cancel3) {
// 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 @@ TEST(HttpCache, RangeGET_Cancel3) {
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 @@ TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) {
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 @@ TEST(HttpCache, DoomOnDestruction) {
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 @@ TEST(HttpCache, DoomOnDestruction2) {
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 @@ TEST(HttpCache, DoomOnDestruction2) {
// 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 @@ TEST(HttpCache, DoomOnDestruction3) {
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 @@ TEST(HttpCache, DoomOnDestruction3) {
// 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 @@ TEST(HttpCache, SetTruncatedFlag) {
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 @@ TEST(HttpCache, SetTruncatedFlag) {
// 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 @@ TEST(HttpCache, DontSetTruncatedFlag) {
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 @@ TEST(HttpCache, GET_IncompleteResource3) {
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 @@ TEST(HttpCache, GET_CancelIncompleteResource) {
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 @@ TEST(HttpCache, CachedRedirect) {
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 @@ TEST(HttpCache, CachedRedirect) {
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 @@ TEST(HttpCache, CachedRedirect) {
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 @@ TEST(HttpCache, SimpleGET_SSLError) {
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 @@ TEST(HttpCache, ReadMetadata) {
// of the stream.
TEST(HttpCache, FilterCompletion) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
{
scoped_ptr<net::HttpTransaction> trans;
@@ -4466,11 +4477,11 @@ TEST(HttpCache, FilterCompletion) {
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 @@ TEST(HttpCache, FilterCompletion) {
// 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 @@ TEST(HttpCache, StopCachingDeletesEntry) {
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 @@ TEST(HttpCache, StopCachingDeletesEntry) {
// 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 @@ TEST(HttpCache, StopCachingSavesEntry) {
"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 @@ TEST(HttpCache, StopCachingSavesEntry) {
// 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 @@ TEST(HttpCache, StopCachingTruncatedEntry) {
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 @@ TEST(HttpCache, StopCachingTruncatedEntry) {
// a Content-Length header.
TEST(HttpCache, TruncatedByContentLength) {
MockHttpCache cache;
- TestOldCompletionCallback callback;
+ net::TestCompletionCallback callback;
MockTransaction transaction(kSimpleGET_Transaction);
AddMockTransaction(&transaction);
@@ -4651,7 +4662,7 @@ TEST(HttpCache, TruncatedByContentLength) {
// 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 @@ TEST_F(HttpNetworkLayerTest, GET) {
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 @@ TEST_F(HttpNetworkLayerTest, GET) {
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..631434d 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 @@ bool IsClientCertificateError(int error) {
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 @@ HttpNetworkTransaction::~HttpNetworkTransaction() {
}
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 @@ int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info,
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 HttpNetworkTransaction::RestartIgnoringLastError(
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 @@ int HttpNetworkTransaction::RestartWithCertificate(
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 @@ int HttpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials,
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 @@ int HttpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials,
}
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
@@ -297,7 +298,7 @@ bool HttpNetworkTransaction::IsReadyToRestartForAuth() {
}
int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(buf);
DCHECK_LT(0, buf_len);
@@ -331,7 +332,7 @@ int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len,
next_state_ = next_state;
int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return rv;
}
@@ -469,12 +470,12 @@ bool HttpNetworkTransaction::is_https_request() const {
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::DoCreateStreamComplete(int result) {
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 @@ int HttpNetworkTransaction::DoGenerateProxyAuthToken() {
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 @@ int HttpNetworkTransaction::DoGenerateServerAuthToken() {
if (!ShouldApplyServerAuth())
return OK;
return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
- &io_callback_,
+ io_callback_,
net_log_);
}
@@ -761,7 +762,7 @@ int HttpNetworkTransaction::DoSendRequest() {
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::DoSendRequestComplete(int result) {
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 @@ int HttpNetworkTransaction::DoReadBody() {
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..7ad9f7e 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -43,19 +43,20 @@ class NET_EXPORT_PRIVATE HttpNetworkTransaction
// 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 @@ class NET_EXPORT_PRIVATE HttpNetworkTransaction
// 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 @@ class HttpNetworkTransactionTest : public PlatformTest {
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 @@ class CaptureGroupNameSocketPool : public ParentPool {
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 @@ TEST_F(HttpNetworkTransactionTest, SingleLocationHeader) {
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 @@ TEST_F(HttpNetworkTransactionTest, Head) {
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 @@ TEST_F(HttpNetworkTransactionTest, ReuseConnection) {
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 @@ TEST_F(HttpNetworkTransactionTest, Ignores100) {
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 @@ TEST_F(HttpNetworkTransactionTest, Ignores1xx) {
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 @@ TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) {
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 @@ TEST_F(HttpNetworkTransactionTest, EmptyResponse) {
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 @@ void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
};
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 @@ TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
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 @@ TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
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 @@ TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) {
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 @@ TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) {
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 @@ void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus(
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
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 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) {
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 @@ TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
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 @@ TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) {
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 @@ TEST_F(HttpNetworkTransactionTest, RecycleSocket) {
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 @@ TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) {
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 @@ TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
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 @@ TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
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 @@ TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
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 @@ TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
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 @@ TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) {
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 @@ TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) {
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 @@ TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
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 @@ TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) {
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 @@ TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) {
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 @@ TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) {
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 @@ TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) {
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 @@ TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaHttpsProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaSpdyProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) {
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 @@ TEST_F(HttpNetworkTransactionTest,
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) {
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 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) {
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 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
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 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
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 @@ TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) {
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 @@ TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) {
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 @@ int GroupNameTransactionHelper(
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 @@ TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
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 @@ void BypassHostCacheOnRefreshHelper(int load_flags) {
// 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 @@ void BypassHostCacheOnRefreshHelper(int load_flags) {
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 @@ TEST_F(HttpNetworkTransactionTest, RequestWriteError) {
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 @@ TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) {
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 @@ TEST_F(HttpNetworkTransactionTest, DrainResetOK) {
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 @@ TEST_F(HttpNetworkTransactionTest, DrainResetOK) {
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 @@ TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) {
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 @@ TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
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 @@ TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
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 @@ TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) {
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 @@ TEST_F(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) {
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 @@ TEST_F(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) {
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 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) {
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 @@ TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) {
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 @@ TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) {
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 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) {
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 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) {
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 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) {
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 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) {
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 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
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 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
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 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
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 @@ TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
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 @@ TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) {
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 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) {
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 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) {
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 @@ TEST_F(HttpNetworkTransactionTest,
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 @@ TEST_F(HttpNetworkTransactionTest,
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 @@ TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) {
&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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, RestartAfterTLSDecompressionFailure) {
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 @@ TEST_F(HttpNetworkTransactionTest,
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 @@ TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) {
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 @@ TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) {
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 @@ TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
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 @@ TEST_F(HttpNetworkTransactionTest, SimpleCancel) {
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 @@ TEST_F(HttpNetworkTransactionTest, ProxyGet) {
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 @@ TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) {
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 @@ TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) {
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 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
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 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
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 @@ static void CheckErrorIsPassedBack(int error, bool async) {
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 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) {
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 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) {
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 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) {
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 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) {
// 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 @@ TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
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 @@ TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
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 @@ TEST_F(HttpNetworkTransactionTest,
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 @@ TEST_F(HttpNetworkTransactionTest,
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 @@ TEST_F(HttpNetworkTransactionTest, CloseOldSpdySessionToOpenNewOne) {
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 @@ TEST_F(HttpNetworkTransactionTest, CloseOldSpdySessionToOpenNewOne) {
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 @@ TEST_F(HttpNetworkTransactionTest, CloseOldSpdySessionToOpenNewOne) {
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 e8a3e78..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 @@ HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl(
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 @@ void HttpPipelinedConnectionImpl::InitializeParser(
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 @@ void HttpPipelinedConnectionImpl::OnStreamDeleted(int pipeline_id) {
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 @@ int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) {
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 @@ int HttpPipelinedConnectionImpl::DoEvictPendingSendRequests(int result) {
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 @@ int HttpPipelinedConnectionImpl::DoReadHeaders(int result) {
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 @@ int HttpPipelinedConnectionImpl::DoReadStreamClosed() {
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 @@ void HttpPipelinedConnectionImpl::Close(int pipeline_id,
}
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 @@ void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id,
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 @@ void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo(
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::ReportPipelineFeedback(int pipeline_id,
}
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::PendingSendRequest::~PendingSendRequest() {
}
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 d0d62d0..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 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
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 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
HttpRequestHeaders headers;
UploadDataStream* request_body;
HttpResponseInfo* response;
- OldCompletionCallback* callback;
+ CompletionCallback callback;
};
struct StreamInfo {
@@ -174,8 +175,8 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
~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 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
// 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 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
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 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
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 @@ class HttpPipelinedConnectionImplTest : public testing::Test {
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 @@ class HttpPipelinedConnectionImplTest : public testing::Test {
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 @@ class HttpPipelinedConnectionImplTest : public testing::Test {
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 @@ class HttpPipelinedConnectionImplTest : public testing::Test {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, AsyncSingleRequest) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, TwoResponsesInOnePacket) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, ReadOrderSwapped) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, SendWhileReading) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, UnsentStreamAllowsLaterUse) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, FailedSend) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, FailedSend) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
EXPECT_EQ(ERR_PIPELINE_EVICTION,
send_rejected_stream->SendRequest(headers, NULL, &response,
- &callback_));
+ callback_.callback()));
send_rejected_stream->Close(true);
}
@@ -634,14 +645,14 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) {
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 @@ class StreamDeleter {
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 @@ class StreamDeleter {
}
HttpStream* stream_;
- OldCompletionCallbackImpl<StreamDeleter> callback_;
+ CompletionCallback callback_;
};
TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) {
@@ -967,7 +985,8 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringReadCallback) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest,
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 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
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));
+ TestCompletionCallback ok_callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ ok_stream->ReadResponseHeaders(ok_callback.callback()));
- TestOldCompletionCallback evicted_callback;
+ TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->ReadResponseHeaders(&evicted_callback));
+ evicted_stream->ReadResponseHeaders(evicted_callback.callback()));
data_->RunFor(1);
EXPECT_LE(OK, ok_callback.WaitForResult());
@@ -1259,7 +1292,7 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) {
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 @@ TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
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 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test {
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 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test {
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 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test {
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 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, OneRequest) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, ErrorEvictsToNewPipeline) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, SendErrorEvictsToNewPipeline) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, RedirectDrained) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, BasicHttpAuthentication) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, OldVersionDisablesPipelining) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) {
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 @@ TEST_F(HttpPipelinedNetworkTransactionTest, OpenPipelinesWhileBinding) {
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 @@ HttpPipelinedStream::~HttpPipelinedStream() {
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 @@ uint64 HttpPipelinedStream::GetUploadProgress() const {
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 @@ const HttpResponseInfo* HttpPipelinedStream::GetResponseInfo() const {
}
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 @@ class HttpPipelinedStream : public HttpStream {
// 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 e4d4182..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 @@ HttpProxyClientSocket::HttpProxyClientSocket(
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 @@ HttpProxyClientSocket::~HttpProxyClientSocket() {
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 @@ int HttpProxyClientSocket::RestartWithAuth(OldCompletionCallback* callback) {
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::DoLoop(int last_io_result) {
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 @@ int HttpProxyClientSocket::DoSendRequest() {
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::DoSendRequestComplete(int result) {
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 @@ int HttpProxyClientSocket::DoDrainBody() {
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 @@ class HttpProxyClientSocket : public ProxyClientSocket {
// 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 @@ class HttpProxyClientSocket : public ProxyClientSocket {
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 a353b2c..c9831c3 100644
--- a/net/http/http_proxy_client_socket_pool.cc
+++ b/net/http/http_proxy_client_socket_pool.cc
@@ -86,8 +86,6 @@ HttpProxyConnectJob::HttpProxyConnectJob(
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 @@ int HttpProxyConnectJob::DoSpdyProxyCreateStream() {
}
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 @@ HttpProxyClientSocketPool::~HttpProxyClientSocketPool() {
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..6b982dc 100644
--- a/net/http/http_proxy_client_socket_pool.h
+++ b/net/http/http_proxy_client_socket_pool.h
@@ -157,7 +157,6 @@ class HttpProxyConnectJob : public ConnectJob {
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 HttpProxyConnectJob : public ConnectJob {
};
class NET_EXPORT_PRIVATE HttpProxyClientSocketPool
- : public ClientSocketPool, public LayeredPool {
+ : public ClientSocketPool,
+ public LayeredPool {
public:
HttpProxyClientSocketPool(
int max_sockets,
@@ -185,12 +185,12 @@ class NET_EXPORT_PRIVATE HttpProxyClientSocketPool
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 @@ class NET_EXPORT_PRIVATE HttpProxyClientSocketPool
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 @@ HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStream* stream)
: 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 @@ int HttpResponseBodyDrainer::DoDrainResponseBody() {
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 859fd17..ff4d61a 100644
--- a/net/http/http_response_body_drainer.h
+++ b/net/http/http_response_body_drainer.h
@@ -60,8 +60,7 @@ class NET_EXPORT_PRIVATE HttpResponseBodyDrainer {
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 7568944..79d9f6f 100644
--- a/net/http/http_response_body_drainer_unittest.cc
+++ b/net/http/http_response_body_drainer_unittest.cc
@@ -65,28 +65,27 @@ class MockHttpStream : public HttpStream {
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 @@ class MockHttpStream : public HttpStream {
// 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 @@ class MockHttpStream : public HttpStream {
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 @@ int MockHttpStream::ReadResponseBody(
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 @@ int MockHttpStream::ReadResponseBody(
}
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, CancelledBySession) {
}
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, DrainBodyTooLarge) {
}
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, StartBodyTooLarge) {
}
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..e52b957 100644
--- a/net/http/http_stream.h
+++ b/net/http/http_stream.h
@@ -41,7 +41,7 @@ class NET_EXPORT_PRIVATE HttpStream {
// 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 @@ class NET_EXPORT_PRIVATE HttpStream {
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 @@ class NET_EXPORT_PRIVATE HttpStream {
// 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 @@ class NET_EXPORT_PRIVATE HttpStream {
// 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 b29e9f1..f401db6 100644
--- a/net/http/http_stream_factory_impl_job.cc
+++ b/net/http/http_stream_factory_impl_job.cc
@@ -115,8 +115,6 @@ HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory,
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 @@ int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() {
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..e93b111 100644
--- a/net/http/http_stream_factory_impl_job.h
+++ b/net/http/http_stream_factory_impl_job.h
@@ -209,7 +209,6 @@ class HttpStreamFactoryImpl::Job {
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 @@ class CapturePreconnectsSocketPool : public ParentPool {
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 @@ HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection,
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 @@ int HttpStreamParser::SendRequest(const std::string& request_line,
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 @@ int HttpStreamParser::SendRequest(const std::string& request_line,
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 @@ int HttpStreamParser::ReadResponseHeaders(OldCompletionCallback* callback) {
result = DoLoop(result);
if (result == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return result > 0 ? OK : result;
}
@@ -177,10 +176,10 @@ void HttpStreamParser::Close(bool not_reusable) {
}
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 HttpStreamParser::ReadResponseBody(IOBuffer* buf, int buf_len,
int result = DoLoop(OK);
if (result == ERR_IO_PENDING)
- user_callback_ = callback;
+ callback_ = callback;
return result;
}
@@ -202,10 +201,10 @@ void HttpStreamParser::OnIOComplete(int result) {
// 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 @@ class HttpStreamParser : public ChunkCallback {
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 @@ class HttpStreamParser : public ChunkCallback {
// 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 @@ class NET_EXPORT_PRIVATE HttpTransaction {
//
// 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 @@ class NET_EXPORT_PRIVATE HttpTransaction {
//
// 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 @@ class NET_EXPORT_PRIVATE HttpTransaction {
//
// 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 @@ class NET_EXPORT_PRIVATE HttpTransaction {
//
// 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 @@ class NET_EXPORT_PRIVATE HttpTransaction {
// 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 @@ TestTransactionConsumer::~TestTransactionConsumer() {
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::DidFinish(int result) {
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 @@ void TestTransactionConsumer::RunWithParams(const Tuple1<int>& params) {
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(MockNetworkLayer* factory)
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::Start(const net::HttpRequestInfo* request,
}
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 @@ bool MockNetworkTransaction::IsReadyToRestartForAuth() {
}
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 @@ uint64 MockNetworkTransaction::GetUploadProgress() const {
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 @@ net::HttpNetworkSession* MockNetworkLayer::GetSession() {
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 e4ce1d6..ba24c8c 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -159,24 +159,24 @@ class MockNetworkTransaction : public net::HttpTransaction {
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 @@ class MockNetworkTransaction : public net::HttpTransaction {
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..24bf4f5 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -115,8 +115,7 @@ PartialData::PartialData()
sparse_entry_(true),
truncated_(false),
initial_validation_(false),
- core_(NULL),
- callback_(NULL) {
+ core_(NULL) {
}
PartialData::~PartialData() {
@@ -162,7 +161,7 @@ void PartialData::RestoreHeaders(HttpRequestHeaders* headers) const {
}
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 @@ int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
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 @@ int PartialData::GetNextRangeLen() {
}
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 @@ void PartialData::GetAvailableRangeCompleted(int result, int64 start) {
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 b996b98..442bbb7 100644
--- a/net/http/partial_data.h
+++ b/net/http/partial_data.h
@@ -55,7 +55,7 @@ class PartialData {
// 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 @@ class PartialData {
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);
};