Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / content / browser / renderer_host / p2p / socket_host_tcp.h
blobb84efc7c2828ca0f96c1ecb704cb8e1f76d2f660
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_
8 #include <queue>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "content/browser/renderer_host/p2p/socket_host.h"
16 #include "content/public/common/p2p_socket_type.h"
17 #include "net/base/completion_callback.h"
18 #include "net/base/ip_endpoint.h"
20 namespace net {
21 class DrainableIOBuffer;
22 class GrowableIOBuffer;
23 class StreamSocket;
24 class URLRequestContextGetter;
25 } // namespace net
27 namespace content {
29 class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
30 public:
31 P2PSocketHostTcpBase(IPC::Sender* message_sender,
32 int id,
33 P2PSocketType type,
34 net::URLRequestContextGetter* url_context);
35 virtual ~P2PSocketHostTcpBase();
37 bool InitAccepted(const net::IPEndPoint& remote_address,
38 net::StreamSocket* socket);
40 // P2PSocketHost overrides.
41 virtual bool Init(const net::IPEndPoint& local_address,
42 const net::IPEndPoint& remote_address) OVERRIDE;
43 virtual void Send(const net::IPEndPoint& to,
44 const std::vector<char>& data,
45 net::DiffServCodePoint dscp,
46 uint64 packet_id) OVERRIDE;
47 virtual P2PSocketHost* AcceptIncomingTcpConnection(
48 const net::IPEndPoint& remote_address, int id) OVERRIDE;
50 protected:
51 // Derived classes will provide the implementation.
52 virtual int ProcessInput(char* input, int input_len) = 0;
53 virtual void DoSend(const net::IPEndPoint& to,
54 const std::vector<char>& data) = 0;
56 void WriteOrQueue(scoped_refptr<net::DrainableIOBuffer>& buffer);
57 void OnPacket(const std::vector<char>& data);
58 void OnError();
60 private:
61 friend class P2PSocketHostTcpTestBase;
62 friend class P2PSocketHostTcpServerTest;
64 // SSL/TLS connection functions.
65 void StartTls();
66 void ProcessTlsSslConnectDone(int status);
68 void DidCompleteRead(int result);
69 void DoRead();
71 void DoWrite();
72 void HandleWriteResult(int result);
74 // Callbacks for Connect(), Read() and Write().
75 void OnConnected(int result);
76 void OnRead(int result);
77 void OnWritten(int result);
79 // Helper method to send socket create message and start read.
80 void OnOpen();
81 void DoSendSocketCreateMsg();
83 net::IPEndPoint remote_address_;
85 scoped_ptr<net::StreamSocket> socket_;
86 scoped_refptr<net::GrowableIOBuffer> read_buffer_;
87 std::queue<scoped_refptr<net::DrainableIOBuffer> > write_queue_;
88 scoped_refptr<net::DrainableIOBuffer> write_buffer_;
90 bool write_pending_;
92 bool connected_;
93 P2PSocketType type_;
94 scoped_refptr<net::URLRequestContextGetter> url_context_;
96 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase);
99 class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase {
100 public:
101 P2PSocketHostTcp(IPC::Sender* message_sender,
102 int id,
103 P2PSocketType type,
104 net::URLRequestContextGetter* url_context);
105 virtual ~P2PSocketHostTcp();
107 protected:
108 virtual int ProcessInput(char* input, int input_len) OVERRIDE;
109 virtual void DoSend(const net::IPEndPoint& to,
110 const std::vector<char>& data) OVERRIDE;
111 private:
112 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp);
115 // P2PSocketHostStunTcp class provides the framing of STUN messages when used
116 // with TURN. These messages will not have length at front of the packet and
117 // are padded to multiple of 4 bytes.
118 // Formatting of messages is defined in RFC5766.
119 class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase {
120 public:
121 P2PSocketHostStunTcp(IPC::Sender* message_sender,
122 int id,
123 P2PSocketType type,
124 net::URLRequestContextGetter* url_context);
126 virtual ~P2PSocketHostStunTcp();
128 protected:
129 virtual int ProcessInput(char* input, int input_len) OVERRIDE;
130 virtual void DoSend(const net::IPEndPoint& to,
131 const std::vector<char>& data) OVERRIDE;
132 private:
133 int GetExpectedPacketSize(const char* data, int len, int* pad_bytes);
135 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp);
139 } // namespace content
141 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_