Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2229)

Unified Diff: jingle/notifier/base/proxy_resolving_client_socket.cc

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jingle/notifier/base/proxy_resolving_client_socket.h ('k') | net/curvecp/client_packetizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jingle/notifier/base/proxy_resolving_client_socket.cc
diff --git a/jingle/notifier/base/proxy_resolving_client_socket.cc b/jingle/notifier/base/proxy_resolving_client_socket.cc
index 4c31ba3d017171246d01c0c112d87237b3e439ff..b3a95f946e36df80e4cc95f7e5fb0385c928cef3 100644
--- a/jingle/notifier/base/proxy_resolving_client_socket.cc
+++ b/jingle/notifier/base/proxy_resolving_client_socket.cc
@@ -37,7 +37,7 @@ ProxyResolvingClientSocket::ProxyResolvingClientSocket(
request_context_getter->GetURLRequestContext()->net_log(),
net::NetLog::SOURCE_SOCKET)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
- user_connect_callback_(NULL) {
+ old_user_connect_callback_(NULL) {
DCHECK(request_context_getter);
net::URLRequestContext* request_context =
request_context_getter->GetURLRequestContext();
@@ -97,7 +97,35 @@ bool ProxyResolvingClientSocket::SetSendBufferSize(int32 size) {
}
int ProxyResolvingClientSocket::Connect(net::OldCompletionCallback* callback) {
- DCHECK(!user_connect_callback_);
+ DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null());
+
+ tried_direct_connect_fallback_ = false;
+
+ // First we try and resolve the proxy.
+ GURL url("http://" + dest_host_port_pair_.ToString());
+ int status = network_session_->proxy_service()->ResolveProxy(
+ url,
+ &proxy_info_,
+ &proxy_resolve_callback_,
+ &pac_request_,
+ bound_net_log_);
+ if (status != net::ERR_IO_PENDING) {
+ // We defer execution of ProcessProxyResolveDone instead of calling it
+ // directly here for simplicity. From the caller's point of view,
+ // the connect always happens asynchronously.
+ MessageLoop* message_loop = MessageLoop::current();
+ CHECK(message_loop);
+ message_loop->PostTask(
+ FROM_HERE,
+ base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone,
+ weak_factory_.GetWeakPtr(), status));
+ }
+ old_user_connect_callback_ = callback;
+ return net::ERR_IO_PENDING;
+}
+int ProxyResolvingClientSocket::Connect(
+ const net::CompletionCallback& callback) {
+ DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null());
tried_direct_connect_fallback_ = false;
@@ -126,9 +154,16 @@ int ProxyResolvingClientSocket::Connect(net::OldCompletionCallback* callback) {
void ProxyResolvingClientSocket::RunUserConnectCallback(int status) {
DCHECK_LE(status, net::OK);
- net::OldCompletionCallback* user_connect_callback = user_connect_callback_;
- user_connect_callback_ = NULL;
- user_connect_callback->Run(status);
+ if (old_user_connect_callback_) {
+ net::OldCompletionCallback* user_connect_callback =
+ old_user_connect_callback_;
+ old_user_connect_callback_ = NULL;
+ user_connect_callback->Run(status);
+ } else {
+ net::CompletionCallback user_connect_callback = user_connect_callback_;
+ user_connect_callback_.Reset();
+ user_connect_callback.Run(status);
+ }
}
// Always runs asynchronously.
@@ -287,7 +322,8 @@ void ProxyResolvingClientSocket::Disconnect() {
CloseTransportSocket();
if (pac_request_)
network_session_->proxy_service()->CancelPacRequest(pac_request_);
- user_connect_callback_ = NULL;
+ old_user_connect_callback_ = NULL;
+ user_connect_callback_.Reset();
}
bool ProxyResolvingClientSocket::IsConnected() const {
« no previous file with comments | « jingle/notifier/base/proxy_resolving_client_socket.h ('k') | net/curvecp/client_packetizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698