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

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 #include "net/proxy/proxy_service.h"
20 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_context_getter.h"
19 22
20 namespace net { 23 namespace net {
21 class DrainableIOBuffer; 24 class DrainableIOBuffer;
22 class GrowableIOBuffer; 25 class GrowableIOBuffer;
23 class StreamSocket; 26 class StreamSocket;
24 } // namespace net 27 } // namespace net
25 28
26 namespace content { 29 namespace content {
27 30
28 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { 31 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
29 public: 32 public:
30 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id); 33 P2PSocketHostTcpBase(IPC::Sender* message_sender, int id,
34 net::URLRequestContextGetter* getter);
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
75 //base::WeakPtrFactory<P2PSocketHostTcpBase> weak_ptr_factory_;
76
72 scoped_ptr<net::StreamSocket> socket_; 77 scoped_ptr<net::StreamSocket> socket_;
73 scoped_refptr<net::GrowableIOBuffer> read_buffer_; 78 scoped_refptr<net::GrowableIOBuffer> read_buffer_;
74 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_; 79 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_;
75 scoped_refptr<net::DrainableIOBuffer> write_buffer_; 80 scoped_refptr<net::DrainableIOBuffer> write_buffer_;
76 81
77 bool write_pending_; 82 bool write_pending_;
78 83
79 bool connected_; 84 bool connected_;
80 85
86 scoped_refptr<net::URLRequestContextGetter> context_getter_;
87 net::ProxyService* proxy_service_;
88
81 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); 89 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase);
82 }; 90 };
83 91
84 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { 92 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase {
85 public: 93 public:
86 P2PSocketHostTcp(IPC::Sender* message_sender, int id); 94 P2PSocketHostTcp(IPC::Sender* message_sender, int id,
95 net::URLRequestContextGetter* getter);
87 virtual ~P2PSocketHostTcp(); 96 virtual ~P2PSocketHostTcp();
88 97
89 protected: 98 protected:
90 virtual int ProcessInput(char* input, int input_len) OVERRIDE; 99 virtual int ProcessInput(char* input, int input_len) OVERRIDE;
91 virtual void DoSend(const net::IPEndPoint& to, 100 virtual void DoSend(const net::IPEndPoint& to,
92 const std::vector<char>& data) OVERRIDE; 101 const std::vector<char>& data) OVERRIDE;
93 private: 102 private:
94 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); 103 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp);
95 }; 104 };
96 105
97 // P2PSocketHostStunTcp class provides the framing of STUN messages when used 106 // P2PSocketHostStunTcp class provides the framing of STUN messages when used
98 // with TURN. These messages will not have length at front of the packet and 107 // with TURN. These messages will not have length at front of the packet and
99 // are padded to multiple of 4 bytes. 108 // are padded to multiple of 4 bytes.
100 // Formatting of messages is defined in RFC5766. 109 // Formatting of messages is defined in RFC5766.
101 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { 110 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase {
102 public: 111 public:
103 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id); 112 P2PSocketHostStunTcp(IPC::Sender* message_sender, int id,
113 net::URLRequestContextGetter* getter);
104 virtual ~P2PSocketHostStunTcp(); 114 virtual ~P2PSocketHostStunTcp();
105 115
106 protected: 116 protected:
107 virtual int ProcessInput(char* input, int input_len) OVERRIDE; 117 virtual int ProcessInput(char* input, int input_len) OVERRIDE;
108 virtual void DoSend(const net::IPEndPoint& to, 118 virtual void DoSend(const net::IPEndPoint& to,
109 const std::vector<char>& data) OVERRIDE; 119 const std::vector<char>& data) OVERRIDE;
110 private: 120 private:
111 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes); 121 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes);
112 122
113 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); 123 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp);
114 }; 124 };
115 125
116 126
117 } // namespace content 127 } // namespace content
118 128
119 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ 129 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698