Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: remoting/protocol/port_allocator_base.h

Issue 1571943002: Simplify PortAllocatorBase and make PortAllocator creation synchronous. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ 5 #ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_
6 #define REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ 6 #define REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/weak_ptr.h"
11 #include "third_party/webrtc/p2p/client/basicportallocator.h" 12 #include "third_party/webrtc/p2p/client/basicportallocator.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 namespace protocol { 15 namespace protocol {
15 16
17 class TransportContext;
18
16 class PortAllocatorBase : public cricket::BasicPortAllocator { 19 class PortAllocatorBase : public cricket::BasicPortAllocator {
17 public: 20 public:
18 // The number of HTTP requests we should attempt before giving up. 21 // The number of HTTP requests we should attempt before giving up.
19 static const int kNumRetries; 22 static const int kNumRetries;
20 23
21 PortAllocatorBase(rtc::NetworkManager* network_manager, 24 PortAllocatorBase(scoped_ptr<rtc::NetworkManager> network_manager,
22 rtc::PacketSocketFactory* socket_factory); 25 scoped_ptr<rtc::PacketSocketFactory> socket_factory,
26 scoped_refptr<TransportContext> transport_context);
23 ~PortAllocatorBase() override; 27 ~PortAllocatorBase() override;
24 28
29 scoped_refptr<TransportContext> transport_context() {
30 return transport_context_;
31 }
32
25 // CreateSession is defined in cricket::BasicPortAllocator but is 33 // CreateSession is defined in cricket::BasicPortAllocator but is
26 // redefined here as pure virtual. 34 // redefined here as pure virtual.
27 cricket::PortAllocatorSession* CreateSessionInternal( 35 cricket::PortAllocatorSession* CreateSessionInternal(
28 const std::string& content_name, 36 const std::string& content_name,
29 int component, 37 int component,
30 const std::string& ice_ufrag, 38 const std::string& ice_ufrag,
31 const std::string& ice_pwd) override = 0; 39 const std::string& ice_pwd) override = 0;
32 40
33 void SetStunHosts(const std::vector<rtc::SocketAddress>& hosts);
34 void SetRelayHosts(const std::vector<std::string>& hosts);
35 void SetRelayToken(const std::string& relay);
36
37 const std::vector<rtc::SocketAddress>& stun_hosts() const {
38 return stun_hosts_;
39 }
40
41 const std::vector<std::string>& relay_hosts() const { return relay_hosts_; }
42 const std::string& relay_token() const { return relay_token_; }
43
44 private: 41 private:
45 std::vector<rtc::SocketAddress> stun_hosts_; 42 scoped_ptr<rtc::NetworkManager> network_manager_;
46 std::vector<std::string> relay_hosts_; 43 scoped_ptr<rtc::PacketSocketFactory> socket_factory_;
47 std::string relay_token_; 44 scoped_refptr<TransportContext> transport_context_;
48 }; 45 };
49 46
50 class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession { 47 class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession {
51 public: 48 public:
52 PortAllocatorSessionBase(PortAllocatorBase* allocator, 49 PortAllocatorSessionBase(PortAllocatorBase* allocator,
53 const std::string& content_name, 50 const std::string& content_name,
54 int component, 51 int component,
55 const std::string& ice_ufrag, 52 const std::string& ice_ufrag,
56 const std::string& ice_pwd, 53 const std::string& ice_pwd);
57 const std::vector<rtc::SocketAddress>& stun_hosts,
58 const std::vector<std::string>& relay_hosts,
59 const std::string& relay);
60 ~PortAllocatorSessionBase() override; 54 ~PortAllocatorSessionBase() override;
61 55
56 virtual void SendSessionRequest(const std::string& host) = 0;
57 void ReceiveSessionResponse(const std::string& response);
58
59 protected:
60 std::string GetSessionRequestUrl();
61
62 void GetPortConfigurations() override;
63 void OnJingleInfo(std::vector<rtc::SocketAddress> stun_hosts,
64 std::vector<std::string> relay_hosts,
65 std::string relay_token);
66 void TryCreateRelaySession();
67
68 PortAllocatorBase* allocator() override;
69
62 const std::string& relay_token() const { return relay_token_; } 70 const std::string& relay_token() const { return relay_token_; }
63 71
64 virtual void SendSessionRequest(const std::string& host) = 0; 72 private:
65 virtual void ReceiveSessionResponse(const std::string& response); 73 std::vector<rtc::SocketAddress> stun_hosts_;
74 std::vector<std::string> relay_hosts_;
75 std::string relay_token_;
66 76
67 protected: 77 int attempts_ = 0;
68 std::string GetSessionRequestUrl();
69 void GetPortConfigurations() override;
70 void TryCreateRelaySession();
71 PortAllocatorBase* allocator() override;
72 78
73 private: 79 base::WeakPtrFactory<PortAllocatorSessionBase> weak_factory_;
74 std::vector<std::string> relay_hosts_;
75 std::vector<rtc::SocketAddress> stun_hosts_;
76 std::string relay_token_;
77 int attempts_;
78 }; 80 };
79 81
80 } // namespace protocol 82 } // namespace protocol
81 } // namespace remoting 83 } // namespace remoting
82 84
83 #endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ 85 #endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698