1 // Copyright (c) 2012 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_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_
13 #include "content/browser/renderer_host/p2p/socket_host_throttler.h"
14 #include "content/common/p2p_socket_type.h"
15 #include "content/public/browser/browser_message_filter.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/render_process_host.h"
18 #include "net/base/ip_endpoint.h"
19 #include "net/base/network_change_notifier.h"
22 class URLRequestContextGetter
;
32 class ResourceContext
;
34 class P2PSocketDispatcherHost
35 : public content::BrowserMessageFilter
,
36 public net::NetworkChangeNotifier::IPAddressObserver
{
38 P2PSocketDispatcherHost(content::ResourceContext
* resource_context
,
39 net::URLRequestContextGetter
* url_context
);
41 // content::BrowserMessageFilter overrides.
42 void OnChannelClosing() override
;
43 void OnDestruct() const override
;
44 bool OnMessageReceived(const IPC::Message
& message
) override
;
46 // net::NetworkChangeNotifier::IPAddressObserver interface.
47 void OnIPAddressChanged() override
;
49 // Starts the RTP packet header dumping. Must be called on the IO thread.
53 const RenderProcessHost::WebRtcRtpPacketCallback
& packet_callback
);
55 // Stops the RTP packet header dumping. Must be Called on the UI thread.
56 void StopRtpDumpOnUIThread(bool incoming
, bool outgoing
);
59 ~P2PSocketDispatcherHost() override
;
62 friend struct BrowserThread::DeleteOnThread
<BrowserThread::IO
>;
63 friend class base::DeleteHelper
<P2PSocketDispatcherHost
>;
65 typedef std::map
<int, P2PSocketHost
*> SocketsMap
;
69 P2PSocketHost
* LookupSocket(int socket_id
);
71 // Handlers for the messages coming from the renderer.
72 void OnStartNetworkNotifications();
73 void OnStopNetworkNotifications();
74 void OnGetHostAddress(const std::string
& host_name
,
77 void OnCreateSocket(P2PSocketType type
,
79 const net::IPEndPoint
& local_address
,
80 const P2PHostAndIPEndPoint
& remote_address
);
81 void OnAcceptIncomingTcpConnection(int listen_socket_id
,
82 const net::IPEndPoint
& remote_address
,
83 int connected_socket_id
);
84 void OnSend(int socket_id
,
85 const net::IPEndPoint
& socket_address
,
86 const std::vector
<char>& data
,
87 const rtc::PacketOptions
& options
,
89 void OnSetOption(int socket_id
, P2PSocketOption option
, int value
);
90 void OnDestroySocket(int socket_id
);
92 void DoGetNetworkList();
93 void SendNetworkList(const net::NetworkInterfaceList
& list
);
95 void OnAddressResolved(DnsRequest
* request
,
96 const net::IPAddressList
& addresses
);
98 void StopRtpDumpOnIOThread(bool incoming
, bool outgoing
);
100 content::ResourceContext
* resource_context_
;
101 scoped_refptr
<net::URLRequestContextGetter
> url_context_
;
105 bool monitoring_networks_
;
107 std::set
<DnsRequest
*> dns_requests_
;
108 P2PMessageThrottler throttler_
;
110 bool dump_incoming_rtp_packet_
;
111 bool dump_outgoing_rtp_packet_
;
112 RenderProcessHost::WebRtcRtpPacketCallback packet_callback_
;
114 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcherHost
);
117 } // namespace content
119 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_