Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / p2p / socket_host_tcp_server.h
blob72ce64434814aca0cb24d19b83243fa26ffdab4d
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_SERVER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_SERVER_H_
8 #include <map>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "content/browser/renderer_host/p2p/socket_host.h"
15 #include "content/common/content_export.h"
16 #include "content/common/p2p_socket_type.h"
17 #include "ipc/ipc_sender.h"
18 #include "net/base/completion_callback.h"
19 #include "net/socket/tcp_server_socket.h"
21 namespace net {
22 class StreamSocket;
23 } // namespace net
25 namespace content {
27 class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost {
28 public:
29 typedef std::map<net::IPEndPoint, net::StreamSocket*> AcceptedSocketsMap;
31 P2PSocketHostTcpServer(IPC::Sender* message_sender,
32 int socket_id,
33 P2PSocketType client_type);
34 virtual ~P2PSocketHostTcpServer();
36 // P2PSocketHost overrides.
37 virtual bool Init(const net::IPEndPoint& local_address,
38 const P2PHostAndIPEndPoint& remote_address) OVERRIDE;
39 virtual void Send(const net::IPEndPoint& to,
40 const std::vector<char>& data,
41 const rtc::PacketOptions& options,
42 uint64 packet_id) OVERRIDE;
43 virtual P2PSocketHost* AcceptIncomingTcpConnection(
44 const net::IPEndPoint& remote_address, int id) OVERRIDE;
45 virtual bool SetOption(P2PSocketOption option, int value) OVERRIDE;
48 private:
49 friend class P2PSocketHostTcpServerTest;
51 void OnError();
53 void DoAccept();
54 void HandleAcceptResult(int result);
56 // Callback for Accept().
57 void OnAccepted(int result);
59 const P2PSocketType client_type_;
60 scoped_ptr<net::ServerSocket> socket_;
61 net::IPEndPoint local_address_;
63 scoped_ptr<net::StreamSocket> accept_socket_;
64 AcceptedSocketsMap accepted_sockets_;
66 net::CompletionCallback accept_callback_;
68 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpServer);
71 } // namespace content
73 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_SERVER_H_