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. 4 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 #include <vector> 12 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" 19 20 namespace net { 21 class URLRequestContextGetter; 22 } 23 24 namespace content { 25 26 class P2PSocketHost; 27 class ResourceContext; 28 29 class P2PSocketDispatcherHost 30 : public content::BrowserMessageFilter, 31 public net::NetworkChangeNotifier::IPAddressObserver { 32 public: 33 P2PSocketDispatcherHost(content::ResourceContext* resource_context, 34 net::URLRequestContextGetter* url_context); 35 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; 41 42 // net::NetworkChangeNotifier::IPAddressObserver interface. 43 virtual void OnIPAddressChanged() OVERRIDE; 44 45 protected: 46 virtual ~P2PSocketDispatcherHost(); 47 48 private: 49 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; 50 friend class base::DeleteHelper<P2PSocketDispatcherHost>; 51 52 typedef std::map<int, P2PSocketHost*> SocketsMap; 53 54 class DnsRequest; 55 56 P2PSocketHost* LookupSocket(int socket_id); 57 58 // Handlers for the messages coming from the renderer. 59 void OnStartNetworkNotifications(const IPC::Message& msg); 60 void OnStopNetworkNotifications(const IPC::Message& msg); 61 62 void OnGetHostAddress(const std::string& host_name, 63 int32 request_id); 64 65 void OnCreateSocket(P2PSocketType type, 66 int socket_id, 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, 76 uint64 packet_id); 77 void OnDestroySocket(int socket_id); 78 79 void DoGetNetworkList(); 80 void SendNetworkList(const net::NetworkInterfaceList& list); 81 82 void OnAddressResolved(DnsRequest* request, 83 const net::IPAddressNumber& result); 84 85 content::ResourceContext* resource_context_; 86 scoped_refptr<net::URLRequestContextGetter> url_context_; 87 88 SocketsMap sockets_; 89 90 bool monitoring_networks_; 91 92 std::set<DnsRequest*> dns_requests_; 93 P2PMessageThrottler throttler_; 94 95 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcherHost); 96 }; 97 98 } // namespace content 99 100 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_ 101