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

Side by Side Diff: jingle/notifier/base/proxy_resolving_client_socket.cc

Issue 8824006: Migrate net/socket/socket.h, net/socket/stream_socket.h to base::Bind(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "jingle/notifier/base/proxy_resolving_client_socket.h" 5 #include "jingle/notifier/base/proxy_resolving_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 18 matching lines...) Expand all
29 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), 29 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
30 &ProxyResolvingClientSocket::ProcessConnectDone), 30 &ProxyResolvingClientSocket::ProcessConnectDone),
31 ssl_config_(ssl_config), 31 ssl_config_(ssl_config),
32 pac_request_(NULL), 32 pac_request_(NULL),
33 dest_host_port_pair_(dest_host_port_pair), 33 dest_host_port_pair_(dest_host_port_pair),
34 tried_direct_connect_fallback_(false), 34 tried_direct_connect_fallback_(false),
35 bound_net_log_( 35 bound_net_log_(
36 net::BoundNetLog::Make( 36 net::BoundNetLog::Make(
37 request_context_getter->GetURLRequestContext()->net_log(), 37 request_context_getter->GetURLRequestContext()->net_log(),
38 net::NetLog::SOURCE_SOCKET)), 38 net::NetLog::SOURCE_SOCKET)),
39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
40 old_user_connect_callback_(NULL) {
41 DCHECK(request_context_getter); 40 DCHECK(request_context_getter);
42 net::URLRequestContext* request_context = 41 net::URLRequestContext* request_context =
43 request_context_getter->GetURLRequestContext(); 42 request_context_getter->GetURLRequestContext();
44 DCHECK(request_context); 43 DCHECK(request_context);
45 net::HttpNetworkSession::Params session_params; 44 net::HttpNetworkSession::Params session_params;
46 session_params.client_socket_factory = socket_factory; 45 session_params.client_socket_factory = socket_factory;
47 session_params.host_resolver = request_context->host_resolver(); 46 session_params.host_resolver = request_context->host_resolver();
48 session_params.cert_verifier = request_context->cert_verifier(); 47 session_params.cert_verifier = request_context->cert_verifier();
49 // TODO(rkn): This is NULL because OriginBoundCertService is not thread safe. 48 // TODO(rkn): This is NULL because OriginBoundCertService is not thread safe.
50 session_params.origin_bound_cert_service = NULL; 49 session_params.origin_bound_cert_service = NULL;
(...skipping 10 matching lines...) Expand all
61 request_context->http_server_properties(); 60 request_context->http_server_properties();
62 session_params.net_log = request_context->net_log(); 61 session_params.net_log = request_context->net_log();
63 network_session_ = new net::HttpNetworkSession(session_params); 62 network_session_ = new net::HttpNetworkSession(session_params);
64 } 63 }
65 64
66 ProxyResolvingClientSocket::~ProxyResolvingClientSocket() { 65 ProxyResolvingClientSocket::~ProxyResolvingClientSocket() {
67 Disconnect(); 66 Disconnect();
68 } 67 }
69 68
70 int ProxyResolvingClientSocket::Read(net::IOBuffer* buf, int buf_len, 69 int ProxyResolvingClientSocket::Read(net::IOBuffer* buf, int buf_len,
71 net::OldCompletionCallback* callback) {
72 if (transport_.get() && transport_->socket())
73 return transport_->socket()->Read(buf, buf_len, callback);
74 NOTREACHED();
75 return net::ERR_SOCKET_NOT_CONNECTED;
76 }
77 int ProxyResolvingClientSocket::Read(net::IOBuffer* buf, int buf_len,
78 const net::CompletionCallback& callback) { 70 const net::CompletionCallback& callback) {
79 if (transport_.get() && transport_->socket()) 71 if (transport_.get() && transport_->socket())
80 return transport_->socket()->Read(buf, buf_len, callback); 72 return transport_->socket()->Read(buf, buf_len, callback);
81 NOTREACHED(); 73 NOTREACHED();
82 return net::ERR_SOCKET_NOT_CONNECTED; 74 return net::ERR_SOCKET_NOT_CONNECTED;
83 } 75 }
84 76
85 int ProxyResolvingClientSocket::Write(net::IOBuffer* buf, int buf_len, 77 int ProxyResolvingClientSocket::Write(
86 net::OldCompletionCallback* callback) { 78 net::IOBuffer* buf,
79 int buf_len,
80 const net::CompletionCallback& callback) {
87 if (transport_.get() && transport_->socket()) 81 if (transport_.get() && transport_->socket())
88 return transport_->socket()->Write(buf, buf_len, callback); 82 return transport_->socket()->Write(buf, buf_len, callback);
89 NOTREACHED(); 83 NOTREACHED();
90 return net::ERR_SOCKET_NOT_CONNECTED; 84 return net::ERR_SOCKET_NOT_CONNECTED;
91 } 85 }
92 86
93 bool ProxyResolvingClientSocket::SetReceiveBufferSize(int32 size) { 87 bool ProxyResolvingClientSocket::SetReceiveBufferSize(int32 size) {
94 if (transport_.get() && transport_->socket()) 88 if (transport_.get() && transport_->socket())
95 return transport_->socket()->SetReceiveBufferSize(size); 89 return transport_->socket()->SetReceiveBufferSize(size);
96 NOTREACHED(); 90 NOTREACHED();
97 return false; 91 return false;
98 } 92 }
99 93
100 bool ProxyResolvingClientSocket::SetSendBufferSize(int32 size) { 94 bool ProxyResolvingClientSocket::SetSendBufferSize(int32 size) {
101 if (transport_.get() && transport_->socket()) 95 if (transport_.get() && transport_->socket())
102 return transport_->socket()->SetSendBufferSize(size); 96 return transport_->socket()->SetSendBufferSize(size);
103 NOTREACHED(); 97 NOTREACHED();
104 return false; 98 return false;
105 } 99 }
106 100
107 int ProxyResolvingClientSocket::Connect(net::OldCompletionCallback* callback) { 101 int ProxyResolvingClientSocket::Connect(
108 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null()); 102 const net::CompletionCallback& callback) {
103 DCHECK(user_connect_callback_.is_null());
109 104
110 tried_direct_connect_fallback_ = false; 105 tried_direct_connect_fallback_ = false;
111 106
112 // First we try and resolve the proxy.
113 GURL url("http://" + dest_host_port_pair_.ToString());
114 int status = network_session_->proxy_service()->ResolveProxy(
115 url,
116 &proxy_info_,
117 &proxy_resolve_callback_,
118 &pac_request_,
119 bound_net_log_);
120 if (status != net::ERR_IO_PENDING) {
121 // We defer execution of ProcessProxyResolveDone instead of calling it
122 // directly here for simplicity. From the caller's point of view,
123 // the connect always happens asynchronously.
124 MessageLoop* message_loop = MessageLoop::current();
125 CHECK(message_loop);
126 message_loop->PostTask(
127 FROM_HERE,
128 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone,
129 weak_factory_.GetWeakPtr(), status));
130 }
131 old_user_connect_callback_ = callback;
132 return net::ERR_IO_PENDING;
133 }
134 int ProxyResolvingClientSocket::Connect(
135 const net::CompletionCallback& callback) {
136 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null());
137
138 tried_direct_connect_fallback_ = false;
139
140 // First we try and resolve the proxy. 107 // First we try and resolve the proxy.
141 GURL url("http://" + dest_host_port_pair_.ToString()); 108 GURL url("http://" + dest_host_port_pair_.ToString());
142 int status = network_session_->proxy_service()->ResolveProxy( 109 int status = network_session_->proxy_service()->ResolveProxy(
143 url, 110 url,
144 &proxy_info_, 111 &proxy_info_,
145 &proxy_resolve_callback_, 112 &proxy_resolve_callback_,
146 &pac_request_, 113 &pac_request_,
147 bound_net_log_); 114 bound_net_log_);
148 if (status != net::ERR_IO_PENDING) { 115 if (status != net::ERR_IO_PENDING) {
149 // We defer execution of ProcessProxyResolveDone instead of calling it 116 // We defer execution of ProcessProxyResolveDone instead of calling it
150 // directly here for simplicity. From the caller's point of view, 117 // directly here for simplicity. From the caller's point of view,
151 // the connect always happens asynchronously. 118 // the connect always happens asynchronously.
152 MessageLoop* message_loop = MessageLoop::current(); 119 MessageLoop* message_loop = MessageLoop::current();
153 CHECK(message_loop); 120 CHECK(message_loop);
154 message_loop->PostTask( 121 message_loop->PostTask(
155 FROM_HERE, 122 FROM_HERE,
156 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, 123 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone,
157 weak_factory_.GetWeakPtr(), status)); 124 weak_factory_.GetWeakPtr(), status));
158 } 125 }
159 user_connect_callback_ = callback; 126 user_connect_callback_ = callback;
160 return net::ERR_IO_PENDING; 127 return net::ERR_IO_PENDING;
161 } 128 }
162 129
163 void ProxyResolvingClientSocket::RunUserConnectCallback(int status) { 130 void ProxyResolvingClientSocket::RunUserConnectCallback(int status) {
164 DCHECK_LE(status, net::OK); 131 DCHECK_LE(status, net::OK);
165 if (old_user_connect_callback_) { 132 net::CompletionCallback user_connect_callback = user_connect_callback_;
166 net::OldCompletionCallback* user_connect_callback = 133 user_connect_callback_.Reset();
167 old_user_connect_callback_; 134 user_connect_callback.Run(status);
168 old_user_connect_callback_ = NULL;
169 user_connect_callback->Run(status);
170 } else {
171 net::CompletionCallback user_connect_callback = user_connect_callback_;
172 user_connect_callback_.Reset();
173 user_connect_callback.Run(status);
174 }
175 } 135 }
176 136
177 // Always runs asynchronously. 137 // Always runs asynchronously.
178 void ProxyResolvingClientSocket::ProcessProxyResolveDone(int status) { 138 void ProxyResolvingClientSocket::ProcessProxyResolveDone(int status) {
179 pac_request_ = NULL; 139 pac_request_ = NULL;
180 140
181 DCHECK_NE(status, net::ERR_IO_PENDING); 141 DCHECK_NE(status, net::ERR_IO_PENDING);
182 if (status == net::OK) { 142 if (status == net::OK) {
183 // Remove unsupported proxies from the list. 143 // Remove unsupported proxies from the list.
184 proxy_info_.RemoveProxiesWithoutScheme( 144 proxy_info_.RemoveProxiesWithoutScheme(
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 283 }
324 284
325 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { 285 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() {
326 network_session_->proxy_service()->ReportSuccess(proxy_info_); 286 network_session_->proxy_service()->ReportSuccess(proxy_info_);
327 } 287 }
328 288
329 void ProxyResolvingClientSocket::Disconnect() { 289 void ProxyResolvingClientSocket::Disconnect() {
330 CloseTransportSocket(); 290 CloseTransportSocket();
331 if (pac_request_) 291 if (pac_request_)
332 network_session_->proxy_service()->CancelPacRequest(pac_request_); 292 network_session_->proxy_service()->CancelPacRequest(pac_request_);
333 old_user_connect_callback_ = NULL;
334 user_connect_callback_.Reset(); 293 user_connect_callback_.Reset();
335 } 294 }
336 295
337 bool ProxyResolvingClientSocket::IsConnected() const { 296 bool ProxyResolvingClientSocket::IsConnected() const {
338 if (!transport_.get() || !transport_->socket()) 297 if (!transport_.get() || !transport_->socket())
339 return false; 298 return false;
340 return transport_->socket()->IsConnected(); 299 return transport_->socket()->IsConnected();
341 } 300 }
342 301
343 bool ProxyResolvingClientSocket::IsConnectedAndIdle() const { 302 bool ProxyResolvingClientSocket::IsConnectedAndIdle() const {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return base::TimeDelta::FromMicroseconds(-1); 370 return base::TimeDelta::FromMicroseconds(-1);
412 } 371 }
413 372
414 void ProxyResolvingClientSocket::CloseTransportSocket() { 373 void ProxyResolvingClientSocket::CloseTransportSocket() {
415 if (transport_.get() && transport_->socket()) 374 if (transport_.get() && transport_->socket())
416 transport_->socket()->Disconnect(); 375 transport_->socket()->Disconnect();
417 transport_.reset(); 376 transport_.reset();
418 } 377 }
419 378
420 } // namespace notifier 379 } // namespace notifier
OLDNEW
« no previous file with comments | « jingle/notifier/base/proxy_resolving_client_socket.h ('k') | jingle/notifier/base/proxy_resolving_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698