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 "content/browser/renderer_host/p2p/socket_host_tcp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
6 | 6 |
| 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" |
7 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
8 #include "content/common/p2p_messages.h" | 10 #include "content/common/p2p_messages.h" |
9 #include "ipc/ipc_sender.h" | 11 #include "ipc/ipc_sender.h" |
10 #include "jingle/glue/fake_ssl_client_socket.h" | 12 #include "jingle/glue/fake_ssl_client_socket.h" |
11 #include "jingle/glue/proxy_resolving_client_socket.h" | 13 #include "jingle/glue/proxy_resolving_client_socket.h" |
12 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
13 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
15 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
16 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 int status = socket_->Connect( | 112 int status = socket_->Connect( |
111 base::Bind(&P2PSocketHostTcpBase::OnConnected, | 113 base::Bind(&P2PSocketHostTcpBase::OnConnected, |
112 base::Unretained(this))); | 114 base::Unretained(this))); |
113 if (status != net::ERR_IO_PENDING) { | 115 if (status != net::ERR_IO_PENDING) { |
114 // We defer execution of ProcessConnectDone instead of calling it | 116 // We defer execution of ProcessConnectDone instead of calling it |
115 // 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 |
116 // 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, |
117 // the connect always happens asynchronously. | 119 // the connect always happens asynchronously. |
118 base::MessageLoop* message_loop = base::MessageLoop::current(); | 120 base::MessageLoop* message_loop = base::MessageLoop::current(); |
119 CHECK(message_loop); | 121 CHECK(message_loop); |
120 message_loop->PostTask( | 122 message_loop->task_runner()->PostTask( |
121 FROM_HERE, | 123 FROM_HERE, base::Bind(&P2PSocketHostTcpBase::OnConnected, |
122 base::Bind(&P2PSocketHostTcpBase::OnConnected, | 124 base::Unretained(this), status)); |
123 base::Unretained(this), status)); | |
124 } | 125 } |
125 | 126 |
126 return state_ != STATE_ERROR; | 127 return state_ != STATE_ERROR; |
127 } | 128 } |
128 | 129 |
129 void P2PSocketHostTcpBase::OnError() { | 130 void P2PSocketHostTcpBase::OnError() { |
130 socket_.reset(); | 131 socket_.reset(); |
131 | 132 |
132 if (state_ == STATE_UNINITIALIZED || state_ == STATE_CONNECTING || | 133 if (state_ == STATE_UNINITIALIZED || state_ == STATE_CONNECTING || |
133 state_ == STATE_TLS_CONNECTING || state_ == STATE_OPEN) { | 134 state_ == STATE_TLS_CONNECTING || state_ == STATE_OPEN) { |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 } else { | 627 } else { |
627 packet_size += kTurnChannelDataHeaderSize; | 628 packet_size += kTurnChannelDataHeaderSize; |
628 // Calculate any padding if present. | 629 // Calculate any padding if present. |
629 if (packet_size % 4) | 630 if (packet_size % 4) |
630 *pad_bytes = 4 - packet_size % 4; | 631 *pad_bytes = 4 - packet_size % 4; |
631 } | 632 } |
632 return packet_size; | 633 return packet_size; |
633 } | 634 } |
634 | 635 |
635 } // namespace content | 636 } // namespace content |
OLD | NEW |