| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/glue/chrome_async_socket.h" | 5 #include "jingle/glue/chrome_async_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 resolving_client_socket_factory_->CreateTransportClientSocket( | 110 resolving_client_socket_factory_->CreateTransportClientSocket( |
| 111 dest_host_port_pair)); | 111 dest_host_port_pair)); |
| 112 int status = transport_socket_->Connect( | 112 int status = transport_socket_->Connect( |
| 113 base::Bind(&ChromeAsyncSocket::ProcessConnectDone, | 113 base::Bind(&ChromeAsyncSocket::ProcessConnectDone, |
| 114 weak_ptr_factory_.GetWeakPtr())); | 114 weak_ptr_factory_.GetWeakPtr())); |
| 115 if (status != net::ERR_IO_PENDING) { | 115 if (status != net::ERR_IO_PENDING) { |
| 116 // We defer execution of ProcessConnectDone instead of calling it | 116 // We defer execution of ProcessConnectDone instead of calling it |
| 117 // directly here as the caller may not expect an error/close to | 117 // directly here as the caller may not expect an error/close to |
| 118 // happen here. This is okay, as from the caller's point of view, | 118 // happen here. This is okay, as from the caller's point of view, |
| 119 // the connect always happens asynchronously. | 119 // the connect always happens asynchronously. |
| 120 MessageLoop* message_loop = MessageLoop::current(); | 120 base::MessageLoop* message_loop = base::MessageLoop::current(); |
| 121 CHECK(message_loop); | 121 CHECK(message_loop); |
| 122 message_loop->PostTask( | 122 message_loop->PostTask( |
| 123 FROM_HERE, | 123 FROM_HERE, |
| 124 base::Bind(&ChromeAsyncSocket::ProcessConnectDone, | 124 base::Bind(&ChromeAsyncSocket::ProcessConnectDone, |
| 125 weak_ptr_factory_.GetWeakPtr(), status)); | 125 weak_ptr_factory_.GetWeakPtr(), status)); |
| 126 } | 126 } |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // STATE_CONNECTING -> STATE_OPEN | 130 // STATE_CONNECTING -> STATE_OPEN |
| (...skipping 16 matching lines...) Expand all Loading... |
| 147 SignalConnected(); | 147 SignalConnected(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // read_state_ == IDLE -> read_state_ == POSTED | 150 // read_state_ == IDLE -> read_state_ == POSTED |
| 151 | 151 |
| 152 void ChromeAsyncSocket::PostDoRead() { | 152 void ChromeAsyncSocket::PostDoRead() { |
| 153 DCHECK(IsOpen()); | 153 DCHECK(IsOpen()); |
| 154 DCHECK_EQ(read_state_, IDLE); | 154 DCHECK_EQ(read_state_, IDLE); |
| 155 DCHECK_EQ(read_start_, 0U); | 155 DCHECK_EQ(read_start_, 0U); |
| 156 DCHECK_EQ(read_end_, 0U); | 156 DCHECK_EQ(read_end_, 0U); |
| 157 MessageLoop* message_loop = MessageLoop::current(); | 157 base::MessageLoop* message_loop = base::MessageLoop::current(); |
| 158 CHECK(message_loop); | 158 CHECK(message_loop); |
| 159 message_loop->PostTask( | 159 message_loop->PostTask( |
| 160 FROM_HERE, | 160 FROM_HERE, |
| 161 base::Bind(&ChromeAsyncSocket::DoRead, | 161 base::Bind(&ChromeAsyncSocket::DoRead, |
| 162 weak_ptr_factory_.GetWeakPtr())); | 162 weak_ptr_factory_.GetWeakPtr())); |
| 163 read_state_ = POSTED; | 163 read_state_ = POSTED; |
| 164 } | 164 } |
| 165 | 165 |
| 166 // read_state_ == POSTED -> read_state_ == PENDING | 166 // read_state_ == POSTED -> read_state_ == PENDING |
| 167 | 167 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 281 } |
| 282 return true; | 282 return true; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // write_state_ == IDLE -> write_state_ == POSTED | 285 // write_state_ == IDLE -> write_state_ == POSTED |
| 286 | 286 |
| 287 void ChromeAsyncSocket::PostDoWrite() { | 287 void ChromeAsyncSocket::PostDoWrite() { |
| 288 DCHECK(IsOpen()); | 288 DCHECK(IsOpen()); |
| 289 DCHECK_EQ(write_state_, IDLE); | 289 DCHECK_EQ(write_state_, IDLE); |
| 290 DCHECK_GT(write_end_, 0U); | 290 DCHECK_GT(write_end_, 0U); |
| 291 MessageLoop* message_loop = MessageLoop::current(); | 291 base::MessageLoop* message_loop = base::MessageLoop::current(); |
| 292 CHECK(message_loop); | 292 CHECK(message_loop); |
| 293 message_loop->PostTask( | 293 message_loop->PostTask( |
| 294 FROM_HERE, | 294 FROM_HERE, |
| 295 base::Bind(&ChromeAsyncSocket::DoWrite, | 295 base::Bind(&ChromeAsyncSocket::DoWrite, |
| 296 weak_ptr_factory_.GetWeakPtr())); | 296 weak_ptr_factory_.GetWeakPtr())); |
| 297 write_state_ = POSTED; | 297 write_state_ = POSTED; |
| 298 } | 298 } |
| 299 | 299 |
| 300 // write_state_ == POSTED -> write_state_ == PENDING | 300 // write_state_ == POSTED -> write_state_ == PENDING |
| 301 | 301 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 scoped_ptr<net::ClientSocketHandle> socket_handle( | 405 scoped_ptr<net::ClientSocketHandle> socket_handle( |
| 406 new net::ClientSocketHandle()); | 406 new net::ClientSocketHandle()); |
| 407 socket_handle->set_socket(transport_socket_.release()); | 407 socket_handle->set_socket(transport_socket_.release()); |
| 408 transport_socket_.reset( | 408 transport_socket_.reset( |
| 409 resolving_client_socket_factory_->CreateSSLClientSocket( | 409 resolving_client_socket_factory_->CreateSSLClientSocket( |
| 410 socket_handle.release(), net::HostPortPair(domain_name, 443))); | 410 socket_handle.release(), net::HostPortPair(domain_name, 443))); |
| 411 int status = transport_socket_->Connect( | 411 int status = transport_socket_->Connect( |
| 412 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, | 412 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, |
| 413 weak_ptr_factory_.GetWeakPtr())); | 413 weak_ptr_factory_.GetWeakPtr())); |
| 414 if (status != net::ERR_IO_PENDING) { | 414 if (status != net::ERR_IO_PENDING) { |
| 415 MessageLoop* message_loop = MessageLoop::current(); | 415 base::MessageLoop* message_loop = base::MessageLoop::current(); |
| 416 CHECK(message_loop); | 416 CHECK(message_loop); |
| 417 message_loop->PostTask( | 417 message_loop->PostTask( |
| 418 FROM_HERE, | 418 FROM_HERE, |
| 419 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, | 419 base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, |
| 420 weak_ptr_factory_.GetWeakPtr(), status)); | 420 weak_ptr_factory_.GetWeakPtr(), status)); |
| 421 } | 421 } |
| 422 return true; | 422 return true; |
| 423 } | 423 } |
| 424 | 424 |
| 425 // STATE_TLS_CONNECTING -> STATE_TLS_OPEN | 425 // STATE_TLS_CONNECTING -> STATE_TLS_OPEN |
| (...skipping 15 matching lines...) Expand all Loading... |
| 441 } | 441 } |
| 442 state_ = STATE_TLS_OPEN; | 442 state_ = STATE_TLS_OPEN; |
| 443 PostDoRead(); | 443 PostDoRead(); |
| 444 if (write_end_ > 0U) { | 444 if (write_end_ > 0U) { |
| 445 PostDoWrite(); | 445 PostDoWrite(); |
| 446 } | 446 } |
| 447 SignalSSLConnected(); | 447 SignalSSLConnected(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace jingle_glue | 450 } // namespace jingle_glue |
| OLD | NEW |