| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ | |
| 6 #define REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "third_party/webrtc/p2p/client/basicportallocator.h" | |
| 13 | |
| 14 namespace remoting { | |
| 15 namespace protocol { | |
| 16 | |
| 17 class TransportContext; | |
| 18 | |
| 19 class PortAllocatorBase : public cricket::BasicPortAllocator { | |
| 20 public: | |
| 21 // The number of HTTP requests we should attempt before giving up. | |
| 22 static const int kNumRetries; | |
| 23 | |
| 24 PortAllocatorBase(scoped_ptr<rtc::NetworkManager> network_manager, | |
| 25 scoped_ptr<rtc::PacketSocketFactory> socket_factory, | |
| 26 scoped_refptr<TransportContext> transport_context); | |
| 27 ~PortAllocatorBase() override; | |
| 28 | |
| 29 scoped_refptr<TransportContext> transport_context() { | |
| 30 return transport_context_; | |
| 31 } | |
| 32 | |
| 33 // CreateSession is defined in cricket::BasicPortAllocator but is | |
| 34 // redefined here as pure virtual. | |
| 35 cricket::PortAllocatorSession* CreateSessionInternal( | |
| 36 const std::string& content_name, | |
| 37 int component, | |
| 38 const std::string& ice_ufrag, | |
| 39 const std::string& ice_pwd) override = 0; | |
| 40 | |
| 41 private: | |
| 42 scoped_ptr<rtc::NetworkManager> network_manager_; | |
| 43 scoped_ptr<rtc::PacketSocketFactory> socket_factory_; | |
| 44 scoped_refptr<TransportContext> transport_context_; | |
| 45 }; | |
| 46 | |
| 47 class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession { | |
| 48 public: | |
| 49 PortAllocatorSessionBase(PortAllocatorBase* allocator, | |
| 50 const std::string& content_name, | |
| 51 int component, | |
| 52 const std::string& ice_ufrag, | |
| 53 const std::string& ice_pwd); | |
| 54 ~PortAllocatorSessionBase() override; | |
| 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 const std::string& relay_token() const { return relay_token_; } | |
| 69 | |
| 70 private: | |
| 71 scoped_refptr<TransportContext> transport_context_; | |
| 72 | |
| 73 std::vector<rtc::SocketAddress> stun_hosts_; | |
| 74 std::vector<std::string> relay_hosts_; | |
| 75 std::string relay_token_; | |
| 76 | |
| 77 int attempts_ = 0; | |
| 78 | |
| 79 base::WeakPtrFactory<PortAllocatorSessionBase> weak_factory_; | |
| 80 }; | |
| 81 | |
| 82 } // namespace protocol | |
| 83 } // namespace remoting | |
| 84 | |
| 85 #endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ | |
| OLD | NEW |