OLD | NEW |
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/chrome_async_socket.h" | 5 #include "jingle/notifier/base/chrome_async_socket.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <cstdlib> | 9 #include <cstdlib> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "net/socket/client_socket_handle.h" | 23 #include "net/socket/client_socket_handle.h" |
24 #include "net/socket/ssl_client_socket.h" | 24 #include "net/socket/ssl_client_socket.h" |
25 #include "net/socket/tcp_client_socket.h" | 25 #include "net/socket/tcp_client_socket.h" |
26 #include "talk/base/socketaddress.h" | 26 #include "talk/base/socketaddress.h" |
27 | 27 |
28 namespace notifier { | 28 namespace notifier { |
29 | 29 |
30 ChromeAsyncSocket::ChromeAsyncSocket( | 30 ChromeAsyncSocket::ChromeAsyncSocket( |
31 ResolvingClientSocketFactory* client_socket_factory, | 31 ResolvingClientSocketFactory* client_socket_factory, |
32 size_t read_buf_size, | 32 size_t read_buf_size, |
33 size_t write_buf_size, | 33 size_t write_buf_size) |
34 net::NetLog* net_log) | |
35 : connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 34 : connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
36 &ChromeAsyncSocket::ProcessConnectDone), | 35 &ChromeAsyncSocket::ProcessConnectDone), |
37 read_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 36 read_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
38 &ChromeAsyncSocket::ProcessReadDone), | 37 &ChromeAsyncSocket::ProcessReadDone), |
39 write_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 38 write_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
40 &ChromeAsyncSocket::ProcessWriteDone), | 39 &ChromeAsyncSocket::ProcessWriteDone), |
41 ssl_connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 40 ssl_connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
42 &ChromeAsyncSocket::ProcessSSLConnectDone), | 41 &ChromeAsyncSocket::ProcessSSLConnectDone), |
43 client_socket_factory_(client_socket_factory), | 42 client_socket_factory_(client_socket_factory), |
44 bound_net_log_( | |
45 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), | |
46 state_(STATE_CLOSED), | 43 state_(STATE_CLOSED), |
47 error_(ERROR_NONE), | 44 error_(ERROR_NONE), |
48 net_error_(net::OK), | 45 net_error_(net::OK), |
49 scoped_runnable_method_factory_( | 46 scoped_runnable_method_factory_( |
50 ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 47 ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
51 read_state_(IDLE), | 48 read_state_(IDLE), |
52 read_buf_(new net::IOBufferWithSize(read_buf_size)), | 49 read_buf_(new net::IOBufferWithSize(read_buf_size)), |
53 read_start_(0U), | 50 read_start_(0U), |
54 read_end_(0U), | 51 read_end_(0U), |
55 write_state_(IDLE), | 52 write_state_(IDLE), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 112 |
116 state_ = STATE_CONNECTING; | 113 state_ = STATE_CONNECTING; |
117 | 114 |
118 DCHECK(scoped_runnable_method_factory_.empty()); | 115 DCHECK(scoped_runnable_method_factory_.empty()); |
119 scoped_runnable_method_factory_.RevokeAll(); | 116 scoped_runnable_method_factory_.RevokeAll(); |
120 | 117 |
121 net::HostPortPair dest_host_port_pair(address.IPAsString(), address.port()); | 118 net::HostPortPair dest_host_port_pair(address.IPAsString(), address.port()); |
122 | 119 |
123 transport_socket_.reset( | 120 transport_socket_.reset( |
124 client_socket_factory_->CreateTransportClientSocket( | 121 client_socket_factory_->CreateTransportClientSocket( |
125 dest_host_port_pair, bound_net_log_.net_log())); | 122 dest_host_port_pair)); |
126 int status = transport_socket_->Connect(&connect_callback_); | 123 int status = transport_socket_->Connect(&connect_callback_); |
127 if (status != net::ERR_IO_PENDING) { | 124 if (status != net::ERR_IO_PENDING) { |
128 // We defer execution of ProcessConnectDone instead of calling it | 125 // We defer execution of ProcessConnectDone instead of calling it |
129 // directly here as the caller may not expect an error/close to | 126 // directly here as the caller may not expect an error/close to |
130 // happen here. This is okay, as from the caller's point of view, | 127 // happen here. This is okay, as from the caller's point of view, |
131 // the connect always happens asynchronously. | 128 // the connect always happens asynchronously. |
132 MessageLoop* message_loop = MessageLoop::current(); | 129 MessageLoop* message_loop = MessageLoop::current(); |
133 CHECK(message_loop); | 130 CHECK(message_loop); |
134 message_loop->PostTask( | 131 message_loop->PostTask( |
135 FROM_HERE, | 132 FROM_HERE, |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 443 } |
447 state_ = STATE_TLS_OPEN; | 444 state_ = STATE_TLS_OPEN; |
448 PostDoRead(); | 445 PostDoRead(); |
449 if (write_end_ > 0U) { | 446 if (write_end_ > 0U) { |
450 PostDoWrite(); | 447 PostDoWrite(); |
451 } | 448 } |
452 SignalSSLConnected(); | 449 SignalSSLConnected(); |
453 } | 450 } |
454 | 451 |
455 } // namespace notifier | 452 } // namespace notifier |
OLD | NEW |