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/renderer/p2p/ipc_socket_factory.h" | 5 #include "content/renderer/p2p/ipc_socket_factory.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "content/renderer/p2p/socket_client.h" | 13 #include "content/renderer/p2p/socket_client.h" |
14 #include "content/renderer/p2p/socket_dispatcher.h" | 14 #include "content/renderer/p2p/socket_dispatcher.h" |
15 #include "jingle/glue/utils.h" | 15 #include "jingle/glue/utils.h" |
16 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" | 16 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 bool IsTcpClientSocket(P2PSocketType type) { | 22 bool IsTcpClientSocket(P2PSocketType type) { |
23 return (type == P2P_SOCKET_STUN_TCP_CLIENT) || | 23 return (type == P2P_SOCKET_STUN_TCP_CLIENT) || |
24 (type == P2P_SOCKET_TCP_CLIENT) || | 24 (type == P2P_SOCKET_TCP_CLIENT) || |
25 (type == P2P_SOCKET_STUN_SSLTCP_CLIENT) || | 25 (type == P2P_SOCKET_STUN_SSLTCP_CLIENT) || |
26 (type == P2P_SOCKET_SSLTCP_CLIENT); | 26 (type == P2P_SOCKET_SSLTCP_CLIENT) || |
| 27 (type == P2P_SOCKET_TLS_CLIENT) || |
| 28 (type == P2P_SOCKET_STUN_TLS_CLIENT); |
27 } | 29 } |
28 | 30 |
29 // TODO(miu): This needs tuning. http://crbug.com/237960 | 31 // TODO(miu): This needs tuning. http://crbug.com/237960 |
30 const size_t kMaximumInFlightBytes = 64 * 1024; // 64 KB | 32 const size_t kMaximumInFlightBytes = 64 * 1024; // 64 KB |
31 | 33 |
32 // IpcPacketSocket implements talk_base::AsyncPacketSocket interface | 34 // IpcPacketSocket implements talk_base::AsyncPacketSocket interface |
33 // using P2PSocketClient that works over IPC-channel. It must be used | 35 // using P2PSocketClient that works over IPC-channel. It must be used |
34 // on the thread it was created. | 36 // on the thread it was created. |
35 class IpcPacketSocket : public talk_base::AsyncPacketSocket, | 37 class IpcPacketSocket : public talk_base::AsyncPacketSocket, |
36 public P2PSocketClient::Delegate { | 38 public P2PSocketClient::Delegate { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 428 |
427 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateClientTcpSocket( | 429 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateClientTcpSocket( |
428 const talk_base::SocketAddress& local_address, | 430 const talk_base::SocketAddress& local_address, |
429 const talk_base::SocketAddress& remote_address, | 431 const talk_base::SocketAddress& remote_address, |
430 const talk_base::ProxyInfo& proxy_info, | 432 const talk_base::ProxyInfo& proxy_info, |
431 const std::string& user_agent, int opts) { | 433 const std::string& user_agent, int opts) { |
432 P2PSocketType type; | 434 P2PSocketType type; |
433 if (opts & talk_base::PacketSocketFactory::OPT_SSLTCP) { | 435 if (opts & talk_base::PacketSocketFactory::OPT_SSLTCP) { |
434 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? | 436 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
435 P2P_SOCKET_STUN_SSLTCP_CLIENT : P2P_SOCKET_SSLTCP_CLIENT; | 437 P2P_SOCKET_STUN_SSLTCP_CLIENT : P2P_SOCKET_SSLTCP_CLIENT; |
| 438 } else if (opts & talk_base::PacketSocketFactory::OPT_TLS) { |
| 439 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
| 440 P2P_SOCKET_STUN_TLS_CLIENT : P2P_SOCKET_TLS_CLIENT; |
436 } else { | 441 } else { |
437 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? | 442 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
438 P2P_SOCKET_STUN_TCP_CLIENT : P2P_SOCKET_TCP_CLIENT; | 443 P2P_SOCKET_STUN_TCP_CLIENT : P2P_SOCKET_TCP_CLIENT; |
439 } | 444 } |
440 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_); | 445 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_); |
441 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 446 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
442 if (!socket->Init(type, socket_client, local_address, | 447 if (!socket->Init(type, socket_client, local_address, |
443 remote_address)) | 448 remote_address)) |
444 return NULL; | 449 return NULL; |
445 return socket.release(); | 450 return socket.release(); |
446 } | 451 } |
447 | 452 |
448 } // namespace content | 453 } // namespace content |
OLD | NEW |