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/public/browser/browser_message_filter.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/common/p2p_socket_type.h"
17 #include "net/base/ip_endpoint.h"
18 #include "net/base/network_change_notifier.h"
21 class URLRequestContextGetter
;
27 class ResourceContext
;
29 class P2PSocketDispatcherHost
30 : public content::BrowserMessageFilter
,
31 public net::NetworkChangeNotifier::IPAddressObserver
{
33 P2PSocketDispatcherHost(content::ResourceContext
* resource_context
,
34 net::URLRequestContextGetter
* url_context
);
36 // content::BrowserMessageFilter overrides.
37 virtual void OnChannelClosing() OVERRIDE
;
38 virtual void OnDestruct() const OVERRIDE
;
39 virtual bool OnMessageReceived(const IPC::Message
& message
,
40 bool* message_was_ok
) OVERRIDE
;
42 // net::NetworkChangeNotifier::IPAddressObserver interface.
43 virtual void OnIPAddressChanged() OVERRIDE
;
46 virtual ~P2PSocketDispatcherHost();
49 friend struct BrowserThread::DeleteOnThread
<BrowserThread::IO
>;
50 friend class base::DeleteHelper
<P2PSocketDispatcherHost
>;
52 typedef std::map
<int, P2PSocketHost
*> SocketsMap
;
56 P2PSocketHost
* LookupSocket(int socket_id
);
58 // Handlers for the messages coming from the renderer.
59 void OnStartNetworkNotifications(const IPC::Message
& msg
);
60 void OnStopNetworkNotifications(const IPC::Message
& msg
);
62 void OnGetHostAddress(const std::string
& host_name
,
65 void OnCreateSocket(P2PSocketType type
,
67 const net::IPEndPoint
& local_address
,
68 const net::IPEndPoint
& remote_address
);
69 void OnAcceptIncomingTcpConnection(int listen_socket_id
,
70 const net::IPEndPoint
& remote_address
,
71 int connected_socket_id
);
72 void OnSend(int socket_id
,
73 const net::IPEndPoint
& socket_address
,
74 const std::vector
<char>& data
,
75 net::DiffServCodePoint dscp
,
77 void OnDestroySocket(int socket_id
);
79 void DoGetNetworkList();
80 void SendNetworkList(const net::NetworkInterfaceList
& list
);
82 void OnAddressResolved(DnsRequest
* request
,
83 const net::IPAddressNumber
& result
);
85 content::ResourceContext
* resource_context_
;
86 scoped_refptr
<net::URLRequestContextGetter
> url_context_
;
90 bool monitoring_networks_
;
92 std::set
<DnsRequest
*> dns_requests_
;
93 P2PMessageThrottler throttler_
;
95 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcherHost
);
98 } // namespace content
100 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_