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 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "content/browser/renderer_host/p2p/socket_host.h" | 12 #include "content/browser/renderer_host/p2p/socket_host.h" |
13 #include "content/common/p2p_sockets.h" | 13 #include "content/common/p2p_sockets.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 class ClientSocket; | |
19 class DrainableIOBuffer; | 18 class DrainableIOBuffer; |
20 class GrowableIOBuffer; | 19 class GrowableIOBuffer; |
| 20 class StreamSocket; |
21 } // namespace net | 21 } // namespace net |
22 | 22 |
23 class P2PSocketHostTcp : public P2PSocketHost { | 23 class P2PSocketHostTcp : public P2PSocketHost { |
24 public: | 24 public: |
25 P2PSocketHostTcp(IPC::Message::Sender* message_sender, | 25 P2PSocketHostTcp(IPC::Message::Sender* message_sender, |
26 int routing_id, int id); | 26 int routing_id, int id); |
27 virtual ~P2PSocketHostTcp(); | 27 virtual ~P2PSocketHostTcp(); |
28 | 28 |
29 bool InitAccepted(const net::IPEndPoint& remote_address, | 29 bool InitAccepted(const net::IPEndPoint& remote_address, |
30 net::ClientSocket* socket); | 30 net::StreamSocket* socket); |
31 | 31 |
32 // P2PSocketHost overrides. | 32 // P2PSocketHost overrides. |
33 virtual bool Init(const net::IPEndPoint& local_address, | 33 virtual bool Init(const net::IPEndPoint& local_address, |
34 const net::IPEndPoint& remote_address) OVERRIDE; | 34 const net::IPEndPoint& remote_address) OVERRIDE; |
35 virtual void Send(const net::IPEndPoint& to, | 35 virtual void Send(const net::IPEndPoint& to, |
36 const std::vector<char>& data) OVERRIDE; | 36 const std::vector<char>& data) OVERRIDE; |
37 virtual P2PSocketHost* AcceptIncomingTcpConnection( | 37 virtual P2PSocketHost* AcceptIncomingTcpConnection( |
38 const net::IPEndPoint& remote_address, int id) OVERRIDE; | 38 const net::IPEndPoint& remote_address, int id) OVERRIDE; |
39 | 39 |
40 private: | 40 private: |
41 friend class P2PSocketHostTcpTest; | 41 friend class P2PSocketHostTcpTest; |
42 friend class P2PSocketHostTcpServerTest; | 42 friend class P2PSocketHostTcpServerTest; |
43 | 43 |
44 void OnError(); | 44 void OnError(); |
45 | 45 |
46 void DoRead(); | 46 void DoRead(); |
47 void DidCompleteRead(int result); | 47 void DidCompleteRead(int result); |
48 void OnPacket(std::vector<char>& data); | 48 void OnPacket(std::vector<char>& data); |
49 | 49 |
50 void DoWrite(); | 50 void DoWrite(); |
51 | 51 |
52 // Callbacks for Connect(), Read() and Write(). | 52 // Callbacks for Connect(), Read() and Write(). |
53 void OnConnected(int result); | 53 void OnConnected(int result); |
54 void OnRead(int result); | 54 void OnRead(int result); |
55 void OnWritten(int result); | 55 void OnWritten(int result); |
56 | 56 |
57 net::IPEndPoint remote_address_; | 57 net::IPEndPoint remote_address_; |
58 | 58 |
59 scoped_ptr<net::ClientSocket> socket_; | 59 scoped_ptr<net::StreamSocket> socket_; |
60 scoped_refptr<net::GrowableIOBuffer> read_buffer_; | 60 scoped_refptr<net::GrowableIOBuffer> read_buffer_; |
61 scoped_refptr<net::DrainableIOBuffer> write_buffer_; | 61 scoped_refptr<net::DrainableIOBuffer> write_buffer_; |
62 | 62 |
63 bool authorized_; | 63 bool authorized_; |
64 | 64 |
65 net::CompletionCallbackImpl<P2PSocketHostTcp> connect_callback_; | 65 net::CompletionCallbackImpl<P2PSocketHostTcp> connect_callback_; |
66 net::CompletionCallbackImpl<P2PSocketHostTcp> read_callback_; | 66 net::CompletionCallbackImpl<P2PSocketHostTcp> read_callback_; |
67 net::CompletionCallbackImpl<P2PSocketHostTcp> write_callback_; | 67 net::CompletionCallbackImpl<P2PSocketHostTcp> write_callback_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); | 69 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); |
70 }; | 70 }; |
71 | 71 |
72 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ | 72 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ |
OLD | NEW |