Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / p2p / port_allocator.h
blob65250a447f534712546f26fcdde077748ead8ed0
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_RENDERER_P2P_PORT_ALLOCATOR_H_
6 #define CONTENT_RENDERER_P2P_PORT_ALLOCATOR_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/net_util.h"
11 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
12 #include "third_party/libjingle/source/talk/p2p/client/basicportallocator.h"
14 namespace blink {
15 class WebFrame;
16 class WebURLLoader;
17 } // namespace blink
19 namespace content {
21 class P2PHostAddressRequest;
22 class P2PPortAllocatorSession;
23 class P2PSocketDispatcher;
25 // TODO(sergeyu): There is overlap between this class and HttpPortAllocator.
26 // Refactor this class to inherit from HttpPortAllocator to avoid code
27 // duplication.
28 class P2PPortAllocator : public cricket::BasicPortAllocator {
29 public:
30 struct Config {
31 Config();
32 ~Config();
34 struct RelayServerConfig {
35 RelayServerConfig();
36 ~RelayServerConfig();
38 std::string username;
39 std::string password;
40 std::string server_address;
41 int port;
42 std::string transport_type;
43 bool secure;
46 std::set<rtc::SocketAddress> stun_servers;
48 std::vector<RelayServerConfig> relays;
50 bool legacy_relay;
51 // Disable TCP-based transport when set to true.
52 bool disable_tcp_transport;
55 P2PPortAllocator(blink::WebFrame* web_frame,
56 P2PSocketDispatcher* socket_dispatcher,
57 rtc::NetworkManager* network_manager,
58 rtc::PacketSocketFactory* socket_factory,
59 const Config& config);
60 virtual ~P2PPortAllocator();
62 virtual cricket::PortAllocatorSession* CreateSessionInternal(
63 const std::string& content_name,
64 int component,
65 const std::string& ice_username_fragment,
66 const std::string& ice_password) OVERRIDE;
68 private:
69 friend class P2PPortAllocatorSession;
71 blink::WebFrame* web_frame_;
72 P2PSocketDispatcher* socket_dispatcher_;
73 Config config_;
75 DISALLOW_COPY_AND_ASSIGN(P2PPortAllocator);
78 class P2PPortAllocatorSession : public cricket::BasicPortAllocatorSession,
79 public blink::WebURLLoaderClient {
80 public:
81 P2PPortAllocatorSession(
82 P2PPortAllocator* allocator,
83 const std::string& content_name,
84 int component,
85 const std::string& ice_username_fragment,
86 const std::string& ice_password);
87 virtual ~P2PPortAllocatorSession();
89 // blink::WebURLLoaderClient overrides.
90 virtual void didReceiveData(blink::WebURLLoader* loader,
91 const char* data,
92 int data_length,
93 int encoded_data_length) OVERRIDE;
94 virtual void didFinishLoading(blink::WebURLLoader* loader,
95 double finish_time,
96 int64_t total_encoded_data_length) OVERRIDE;
97 virtual void didFail(blink::WebURLLoader* loader,
98 const blink::WebURLError& error) OVERRIDE;
100 protected:
101 // Overrides for cricket::BasicPortAllocatorSession.
102 virtual void GetPortConfigurations() OVERRIDE;
104 private:
105 // This method allocates non-TURN relay sessions.
106 void AllocateLegacyRelaySession();
107 void ParseRelayResponse();
109 void AddConfig();
111 P2PPortAllocator* allocator_;
113 scoped_ptr<blink::WebURLLoader> relay_session_request_;
114 int relay_session_attempts_;
115 std::string relay_session_response_;
116 rtc::SocketAddress relay_ip_;
117 int relay_udp_port_;
118 int relay_tcp_port_;
119 int relay_ssltcp_port_;
120 int pending_relay_requests_;
122 DISALLOW_COPY_AND_ASSIGN(P2PPortAllocatorSession);
125 } // namespace content
127 #endif // CONTENT_RENDERER_P2P_PORT_ALLOCATOR_H_