OLD | NEW |
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_H_ | 5 #ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ |
6 #define REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ | 6 #define REMOTING_PROTOCOL_PORT_ALLOCATOR_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 "base/memory/weak_ptr.h" |
12 #include "remoting/base/url_request.h" | 12 #include "remoting/base/url_request.h" |
13 #include "remoting/protocol/ice_config.h" | 13 #include "remoting/protocol/ice_config.h" |
14 #include "remoting/protocol/transport_context.h" | 14 #include "remoting/protocol/transport_context.h" |
15 #include "third_party/webrtc/p2p/client/basicportallocator.h" | 15 #include "third_party/webrtc/p2p/client/basicportallocator.h" |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 namespace protocol { | 18 namespace protocol { |
19 | 19 |
20 class PortAllocator : public cricket::BasicPortAllocator { | 20 class PortAllocator : public cricket::BasicPortAllocator { |
21 public: | 21 public: |
22 PortAllocator(scoped_ptr<rtc::NetworkManager> network_manager, | 22 PortAllocator(std::unique_ptr<rtc::NetworkManager> network_manager, |
23 scoped_ptr<rtc::PacketSocketFactory> socket_factory, | 23 std::unique_ptr<rtc::PacketSocketFactory> socket_factory, |
24 scoped_refptr<TransportContext> transport_context); | 24 scoped_refptr<TransportContext> transport_context); |
25 ~PortAllocator() override; | 25 ~PortAllocator() override; |
26 | 26 |
27 scoped_refptr<TransportContext> transport_context() { | 27 scoped_refptr<TransportContext> transport_context() { |
28 return transport_context_; | 28 return transport_context_; |
29 } | 29 } |
30 | 30 |
31 cricket::PortAllocatorSession* CreateSessionInternal( | 31 cricket::PortAllocatorSession* CreateSessionInternal( |
32 const std::string& content_name, | 32 const std::string& content_name, |
33 int component, | 33 int component, |
34 const std::string& ice_ufrag, | 34 const std::string& ice_ufrag, |
35 const std::string& ice_pwd) override; | 35 const std::string& ice_pwd) override; |
36 | 36 |
37 private: | 37 private: |
38 scoped_ptr<rtc::NetworkManager> network_manager_; | 38 std::unique_ptr<rtc::NetworkManager> network_manager_; |
39 scoped_ptr<rtc::PacketSocketFactory> socket_factory_; | 39 std::unique_ptr<rtc::PacketSocketFactory> socket_factory_; |
40 scoped_refptr<TransportContext> transport_context_; | 40 scoped_refptr<TransportContext> transport_context_; |
41 }; | 41 }; |
42 | 42 |
43 class PortAllocatorSession : public cricket::BasicPortAllocatorSession { | 43 class PortAllocatorSession : public cricket::BasicPortAllocatorSession { |
44 public: | 44 public: |
45 PortAllocatorSession(PortAllocator* allocator, | 45 PortAllocatorSession(PortAllocator* allocator, |
46 const std::string& content_name, | 46 const std::string& content_name, |
47 int component, | 47 int component, |
48 const std::string& ice_ufrag, | 48 const std::string& ice_ufrag, |
49 const std::string& ice_pwd); | 49 const std::string& ice_pwd); |
50 ~PortAllocatorSession() override; | 50 ~PortAllocatorSession() override; |
51 | 51 |
52 private: | 52 private: |
53 bool relay_enabled() { | 53 bool relay_enabled() { |
54 return !(flags() & cricket::PORTALLOCATOR_DISABLE_RELAY); | 54 return !(flags() & cricket::PORTALLOCATOR_DISABLE_RELAY); |
55 } | 55 } |
56 | 56 |
57 // BasicPortAllocatorSession overrides. | 57 // BasicPortAllocatorSession overrides. |
58 void GetPortConfigurations() override; | 58 void GetPortConfigurations() override; |
59 | 59 |
60 // Callback for TransportContext::GetIceConfig(). | 60 // Callback for TransportContext::GetIceConfig(). |
61 void OnIceConfig(const IceConfig& ice_config); | 61 void OnIceConfig(const IceConfig& ice_config); |
62 | 62 |
63 // Creates PortConfiguration that inclues STUN and TURN servers from | 63 // Creates PortConfiguration that inclues STUN and TURN servers from |
64 // |ice_config_|. | 64 // |ice_config_|. |
65 scoped_ptr<cricket::PortConfiguration> GetPortConfiguration(); | 65 std::unique_ptr<cricket::PortConfiguration> GetPortConfiguration(); |
66 | 66 |
67 // Attempts to allocate relay session. | 67 // Attempts to allocate relay session. |
68 void TryCreateRelaySession(); | 68 void TryCreateRelaySession(); |
69 | 69 |
70 // Result handler for UrlRequest objects in |url_requests_|. | 70 // Result handler for UrlRequest objects in |url_requests_|. |
71 void OnSessionRequestResult(const UrlRequest::Result& result); | 71 void OnSessionRequestResult(const UrlRequest::Result& result); |
72 | 72 |
73 scoped_refptr<TransportContext> transport_context_; | 73 scoped_refptr<TransportContext> transport_context_; |
74 | 74 |
75 IceConfig ice_config_; | 75 IceConfig ice_config_; |
76 | 76 |
77 int attempts_ = 0; | 77 int attempts_ = 0; |
78 | 78 |
79 std::set<scoped_ptr<UrlRequest>> url_requests_; | 79 std::set<std::unique_ptr<UrlRequest>> url_requests_; |
80 | 80 |
81 base::WeakPtrFactory<PortAllocatorSession> weak_factory_; | 81 base::WeakPtrFactory<PortAllocatorSession> weak_factory_; |
82 }; | 82 }; |
83 | 83 |
84 } // namespace protocol | 84 } // namespace protocol |
85 } // namespace remoting | 85 } // namespace remoting |
86 | 86 |
87 #endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ | 87 #endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ |
OLD | NEW |