| 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" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 talk_base::DiffServCodePoint dscp) OVERRIDE; | 55 talk_base::DiffServCodePoint dscp) OVERRIDE; |
| 56 virtual int Close() OVERRIDE; | 56 virtual int Close() OVERRIDE; |
| 57 virtual State GetState() const OVERRIDE; | 57 virtual State GetState() const OVERRIDE; |
| 58 virtual int GetOption(talk_base::Socket::Option opt, int* value) OVERRIDE; | 58 virtual int GetOption(talk_base::Socket::Option opt, int* value) OVERRIDE; |
| 59 virtual int SetOption(talk_base::Socket::Option opt, int value) OVERRIDE; | 59 virtual int SetOption(talk_base::Socket::Option opt, int value) OVERRIDE; |
| 60 virtual int GetError() const OVERRIDE; | 60 virtual int GetError() const OVERRIDE; |
| 61 virtual void SetError(int error) OVERRIDE; | 61 virtual void SetError(int error) OVERRIDE; |
| 62 | 62 |
| 63 // P2PSocketClient::Delegate implementation. | 63 // P2PSocketClient::Delegate implementation. |
| 64 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; | 64 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; |
| 65 virtual void OnIncomingTcpConnection(const net::IPEndPoint& address, | 65 virtual void OnIncomingTcpConnection( |
| 66 P2PSocketClient* client) OVERRIDE; | 66 const net::IPEndPoint& address, |
| 67 P2PSocketClient* client) OVERRIDE; |
| 67 virtual void OnSendComplete() OVERRIDE; | 68 virtual void OnSendComplete() OVERRIDE; |
| 68 virtual void OnError() OVERRIDE; | 69 virtual void OnError() OVERRIDE; |
| 69 virtual void OnDataReceived(const net::IPEndPoint& address, | 70 virtual void OnDataReceived(const net::IPEndPoint& address, |
| 70 const std::vector<char>& data) OVERRIDE; | 71 const std::vector<char>& data) OVERRIDE; |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 enum InternalState { | 74 enum InternalState { |
| 74 IS_UNINITIALIZED, | 75 IS_UNINITIALIZED, |
| 75 IS_OPENING, | 76 IS_OPENING, |
| 76 IS_OPEN, | 77 IS_OPEN, |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 P2PSocketDispatcher* socket_dispatcher) | 396 P2PSocketDispatcher* socket_dispatcher) |
| 396 : socket_dispatcher_(socket_dispatcher) { | 397 : socket_dispatcher_(socket_dispatcher) { |
| 397 } | 398 } |
| 398 | 399 |
| 399 IpcPacketSocketFactory::~IpcPacketSocketFactory() { | 400 IpcPacketSocketFactory::~IpcPacketSocketFactory() { |
| 400 } | 401 } |
| 401 | 402 |
| 402 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateUdpSocket( | 403 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateUdpSocket( |
| 403 const talk_base::SocketAddress& local_address, int min_port, int max_port) { | 404 const talk_base::SocketAddress& local_address, int min_port, int max_port) { |
| 404 talk_base::SocketAddress crome_address; | 405 talk_base::SocketAddress crome_address; |
| 405 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_); | 406 P2PSocketClientImpl* socket_client = |
| 407 new P2PSocketClientImpl(socket_dispatcher_); |
| 406 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 408 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 407 // TODO(sergeyu): Respect local_address and port limits here (need | 409 // TODO(sergeyu): Respect local_address and port limits here (need |
| 408 // to pass them over IPC channel to the browser). | 410 // to pass them over IPC channel to the browser). |
| 409 if (!socket->Init(P2P_SOCKET_UDP, socket_client, | 411 if (!socket->Init(P2P_SOCKET_UDP, socket_client, |
| 410 local_address, talk_base::SocketAddress())) { | 412 local_address, talk_base::SocketAddress())) { |
| 411 return NULL; | 413 return NULL; |
| 412 } | 414 } |
| 413 return socket.release(); | 415 return socket.release(); |
| 414 } | 416 } |
| 415 | 417 |
| 416 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateServerTcpSocket( | 418 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateServerTcpSocket( |
| 417 const talk_base::SocketAddress& local_address, int min_port, int max_port, | 419 const talk_base::SocketAddress& local_address, int min_port, int max_port, |
| 418 int opts) { | 420 int opts) { |
| 419 // TODO(sergeyu): Implement SSL support. | 421 // TODO(sergeyu): Implement SSL support. |
| 420 if (opts & talk_base::PacketSocketFactory::OPT_SSLTCP) | 422 if (opts & talk_base::PacketSocketFactory::OPT_SSLTCP) |
| 421 return NULL; | 423 return NULL; |
| 422 | 424 |
| 423 P2PSocketType type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? | 425 P2PSocketType type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
| 424 P2P_SOCKET_STUN_TCP_SERVER : P2P_SOCKET_TCP_SERVER; | 426 P2P_SOCKET_STUN_TCP_SERVER : P2P_SOCKET_TCP_SERVER; |
| 425 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_); | 427 P2PSocketClientImpl* socket_client = |
| 428 new P2PSocketClientImpl(socket_dispatcher_); |
| 426 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 429 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 427 if (!socket->Init(type, socket_client, local_address, | 430 if (!socket->Init(type, socket_client, local_address, |
| 428 talk_base::SocketAddress())) { | 431 talk_base::SocketAddress())) { |
| 429 return NULL; | 432 return NULL; |
| 430 } | 433 } |
| 431 return socket.release(); | 434 return socket.release(); |
| 432 } | 435 } |
| 433 | 436 |
| 434 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateClientTcpSocket( | 437 talk_base::AsyncPacketSocket* IpcPacketSocketFactory::CreateClientTcpSocket( |
| 435 const talk_base::SocketAddress& local_address, | 438 const talk_base::SocketAddress& local_address, |
| 436 const talk_base::SocketAddress& remote_address, | 439 const talk_base::SocketAddress& remote_address, |
| 437 const talk_base::ProxyInfo& proxy_info, | 440 const talk_base::ProxyInfo& proxy_info, |
| 438 const std::string& user_agent, int opts) { | 441 const std::string& user_agent, int opts) { |
| 439 P2PSocketType type; | 442 P2PSocketType type; |
| 440 if (opts & talk_base::PacketSocketFactory::OPT_SSLTCP) { | 443 if (opts & talk_base::PacketSocketFactory::OPT_SSLTCP) { |
| 441 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? | 444 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
| 442 P2P_SOCKET_STUN_SSLTCP_CLIENT : P2P_SOCKET_SSLTCP_CLIENT; | 445 P2P_SOCKET_STUN_SSLTCP_CLIENT : P2P_SOCKET_SSLTCP_CLIENT; |
| 443 } else if (opts & talk_base::PacketSocketFactory::OPT_TLS) { | 446 } else if (opts & talk_base::PacketSocketFactory::OPT_TLS) { |
| 444 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? | 447 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
| 445 P2P_SOCKET_STUN_TLS_CLIENT : P2P_SOCKET_TLS_CLIENT; | 448 P2P_SOCKET_STUN_TLS_CLIENT : P2P_SOCKET_TLS_CLIENT; |
| 446 } else { | 449 } else { |
| 447 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? | 450 type = (opts & talk_base::PacketSocketFactory::OPT_STUN) ? |
| 448 P2P_SOCKET_STUN_TCP_CLIENT : P2P_SOCKET_TCP_CLIENT; | 451 P2P_SOCKET_STUN_TCP_CLIENT : P2P_SOCKET_TCP_CLIENT; |
| 449 } | 452 } |
| 450 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_); | 453 P2PSocketClientImpl* socket_client = |
| 454 new P2PSocketClientImpl(socket_dispatcher_); |
| 451 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); | 455 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); |
| 452 if (!socket->Init(type, socket_client, local_address, | 456 if (!socket->Init(type, socket_client, local_address, remote_address)) |
| 453 remote_address)) | |
| 454 return NULL; | 457 return NULL; |
| 455 return socket.release(); | 458 return socket.release(); |
| 456 } | 459 } |
| 457 | 460 |
| 458 } // namespace content | 461 } // namespace content |
| OLD | NEW |