Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_tcp.h

Issue 17132012: Proxy support for P2P TCP Socket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <queue> 8 #include <queue>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "content/browser/renderer_host/p2p/socket_host.h" 15 #include "content/browser/renderer_host/p2p/socket_host.h"
16 #include "content/common/p2p_sockets.h" 16 #include "content/common/p2p_sockets.h"
17 #include "net/base/completion_callback.h" 17 #include "net/base/completion_callback.h"
18 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
19 19
20 namespace net { 20 namespace net {
21 class DrainableIOBuffer; 21 class DrainableIOBuffer;
22 class GrowableIOBuffer; 22 class GrowableIOBuffer;
23 class StreamSocket; 23 class StreamSocket;
24 class URLRequestContextGetter;
24 } // namespace net 25 } // namespace net
25 26
26 namespace content { 27 namespace content {
27 28
28 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { 29 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
29 public: 30 public:
30 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id, P2PSocketType type); 31 P2PSocketHostTcpBase(IPC::Sender* message_sender,
32 int id,
33 P2PSocketType type,
34 net::URLRequestContextGetter* url_context);
31 virtual ~P2PSocketHostTcpBase(); 35 virtual ~P2PSocketHostTcpBase();
32 36
33 bool InitAccepted(const net::IPEndPoint& remote_address, 37 bool InitAccepted(const net::IPEndPoint& remote_address,
34 net::StreamSocket* socket); 38 net::StreamSocket* socket);
35 39
36 // P2PSocketHost overrides. 40 // P2PSocketHost overrides.
37 virtual bool Init(const net::IPEndPoint& local_address, 41 virtual bool Init(const net::IPEndPoint& local_address,
38 const net::IPEndPoint& remote_address) OVERRIDE; 42 const net::IPEndPoint& remote_address) OVERRIDE;
39 virtual void Send(const net::IPEndPoint& to, 43 virtual void Send(const net::IPEndPoint& to,
40 const std::vector<char>& data) OVERRIDE; 44 const std::vector<char>& data) OVERRIDE;
41 virtual P2PSocketHost* AcceptIncomingTcpConnection( 45 virtual P2PSocketHost* AcceptIncomingTcpConnection(
42 const net::IPEndPoint& remote_address, int id) OVERRIDE; 46 const net::IPEndPoint& remote_address, int id) OVERRIDE;
43 47
44 protected: 48 protected:
45 // Derived classes will provide the implementation. 49 // Derived classes will provide the implementation.
46 virtual int ProcessInput(char* input, int input_len) = 0; 50 virtual int ProcessInput(char* input, int input_len) = 0;
47 virtual void DoSend(const net::IPEndPoint& to, 51 virtual void DoSend(const net::IPEndPoint& to,
48 const std::vector<char>& data) = 0; 52 const std::vector<char>& data) = 0;
49 53
50 void WriteOrQueue(scoped_refptr<net::DrainableIOBuffer>& buffer); 54 void WriteOrQueue(scoped_refptr<net::DrainableIOBuffer>& buffer);
51 void OnPacket(const std::vector<char>& data); 55 void OnPacket(const std::vector<char>& data);
52 void OnError(); 56 void OnError();
53 57
54 private: 58 private:
55 friend class P2PSocketHostTcpTest; 59 friend class P2PSocketHostTcpTestBase;
56 friend class P2PSocketHostTcpServerTest; 60 friend class P2PSocketHostTcpServerTest;
57 friend class P2PSocketHostStunTcpTest;
58 61
59 void DidCompleteRead(int result); 62 void DidCompleteRead(int result);
60 void DoRead(); 63 void DoRead();
61 64
62 void DoWrite(); 65 void DoWrite();
63 void HandleWriteResult(int result); 66 void HandleWriteResult(int result);
64 67
65 // Callbacks for Connect(), Read() and Write(). 68 // Callbacks for Connect(), Read() and Write().
66 void OnConnected(int result); 69 void OnConnected(int result);
67 void OnRead(int result); 70 void OnRead(int result);
68 void OnWritten(int result); 71 void OnWritten(int result);
69 72
70 net::IPEndPoint remote_address_; 73 net::IPEndPoint remote_address_;
71 74
72 scoped_ptr<net::StreamSocket> socket_; 75 scoped_ptr<net::StreamSocket> socket_;
73 scoped_refptr<net::GrowableIOBuffer> read_buffer_; 76 scoped_refptr<net::GrowableIOBuffer> read_buffer_;
74 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_; 77 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_;
75 scoped_refptr<net::DrainableIOBuffer> write_buffer_; 78 scoped_refptr<net::DrainableIOBuffer> write_buffer_;
76 79
77 bool write_pending_; 80 bool write_pending_;
78 81
79 bool connected_; 82 bool connected_;
80
81 P2PSocketType type_; 83 P2PSocketType type_;
84 scoped_refptr<net::URLRequestContextGetter> url_context_;
82 85
83 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); 86 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase);
84 }; 87 };
85 88
86 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { 89 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase {
87 public: 90 public:
88 P2PSocketHostTcp(IPC::Sender* message_sender, int id, P2PSocketType type); 91 P2PSocketHostTcp(IPC::Sender* message_sender,
92 int id,
93 P2PSocketType type,
94 net::URLRequestContextGetter* url_context);
89 virtual ~P2PSocketHostTcp(); 95 virtual ~P2PSocketHostTcp();
90 96
91 protected: 97 protected:
92 virtual int ProcessInput(char* input, int input_len) OVERRIDE; 98 virtual int ProcessInput(char* input, int input_len) OVERRIDE;
93 virtual void DoSend(const net::IPEndPoint& to, 99 virtual void DoSend(const net::IPEndPoint& to,
94 const std::vector<char>& data) OVERRIDE; 100 const std::vector<char>& data) OVERRIDE;
95 private: 101 private:
96 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); 102 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp);
97 }; 103 };
98 104
99 // P2PSocketHostStunTcp class provides the framing of STUN messages when used 105 // P2PSocketHostStunTcp class provides the framing of STUN messages when used
100 // with TURN. These messages will not have length at front of the packet and 106 // with TURN. These messages will not have length at front of the packet and
101 // are padded to multiple of 4 bytes. 107 // are padded to multiple of 4 bytes.
102 // Formatting of messages is defined in RFC5766. 108 // Formatting of messages is defined in RFC5766.
103 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { 109 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase {
104 public: 110 public:
105 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id, P2PSocketType type); 111 P2PSocketHostStunTcp(IPC::Sender* message_sender,
112 int id,
113 P2PSocketType type,
114 net::URLRequestContextGetter* url_context);
115
106 virtual ~P2PSocketHostStunTcp(); 116 virtual ~P2PSocketHostStunTcp();
107 117
108 protected: 118 protected:
109 virtual int ProcessInput(char* input, int input_len) OVERRIDE; 119 virtual int ProcessInput(char* input, int input_len) OVERRIDE;
110 virtual void DoSend(const net::IPEndPoint& to, 120 virtual void DoSend(const net::IPEndPoint& to,
111 const std::vector<char>& data) OVERRIDE; 121 const std::vector<char>& data) OVERRIDE;
112 private: 122 private:
113 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes); 123 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes);
114 124
115 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); 125 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp);
116 }; 126 };
117 127
118 128
119 } // namespace content 129 } // namespace content
120 130
121 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ 131 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host.cc ('k') | content/browser/renderer_host/p2p/socket_host_tcp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698