Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / renderer_host / p2p / socket_host_udp.h
blob1839663637b7a5dda49f2e44377c1176a549941f
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_UDP_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_
8 #include <deque>
9 #include <set>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "content/browser/renderer_host/p2p/socket_host.h"
17 #include "content/common/content_export.h"
18 #include "content/common/p2p_socket_type.h"
19 #include "net/base/ip_endpoint.h"
20 #include "net/udp/udp_server_socket.h"
21 #include "third_party/webrtc/base/asyncpacketsocket.h"
23 namespace content {
25 class P2PMessageThrottler;
27 class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
28 public:
29 P2PSocketHostUdp(IPC::Sender* message_sender,
30 int socket_id,
31 P2PMessageThrottler* throttler);
32 ~P2PSocketHostUdp() override;
34 // P2PSocketHost overrides.
35 bool Init(const net::IPEndPoint& local_address,
36 const P2PHostAndIPEndPoint& remote_address) override;
37 void Send(const net::IPEndPoint& to,
38 const std::vector<char>& data,
39 const rtc::PacketOptions& options,
40 uint64 packet_id) override;
41 P2PSocketHost* AcceptIncomingTcpConnection(
42 const net::IPEndPoint& remote_address,
43 int id) override;
44 bool SetOption(P2PSocketOption option, int value) override;
46 private:
47 friend class P2PSocketHostUdpTest;
49 typedef std::set<net::IPEndPoint> ConnectedPeerSet;
51 struct PendingPacket {
52 PendingPacket(const net::IPEndPoint& to,
53 const std::vector<char>& content,
54 const rtc::PacketOptions& options,
55 uint64 id);
56 ~PendingPacket();
57 net::IPEndPoint to;
58 scoped_refptr<net::IOBuffer> data;
59 int size;
60 rtc::PacketOptions packet_options;
61 uint64 id;
64 void OnError();
66 void SetSendBufferSize();
68 void DoRead();
69 void OnRecv(int result);
70 void HandleReadResult(int result);
72 void DoSend(const PendingPacket& packet);
73 void OnSend(uint64 packet_id, uint64 tick_received, int result);
74 void HandleSendResult(uint64 packet_id, uint64 tick_received, int result);
76 scoped_ptr<net::DatagramServerSocket> socket_;
77 scoped_refptr<net::IOBuffer> recv_buffer_;
78 net::IPEndPoint recv_address_;
80 std::deque<PendingPacket> send_queue_;
81 bool send_pending_;
82 net::DiffServCodePoint last_dscp_;
84 // Set of peer for which we have received STUN binding request or
85 // response or relay allocation request or response.
86 ConnectedPeerSet connected_peers_;
87 P2PMessageThrottler* throttler_;
89 // Keep track of the send socket buffer size under experiment.
90 size_t send_buffer_size_;
92 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp);
95 } // namespace content
97 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_