OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_TRANSPORT_CONTEXT_H_ | 5 #ifndef REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
6 #define REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 6 #define REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
7 | 7 |
| 8 #include <array> |
8 #include <list> | 9 #include <list> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "remoting/protocol/ice_config.h" | 16 #include "remoting/protocol/ice_config.h" |
16 #include "remoting/protocol/network_settings.h" | 17 #include "remoting/protocol/network_settings.h" |
17 #include "remoting/protocol/transport.h" | 18 #include "remoting/protocol/transport.h" |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 | 21 |
21 class SignalStrategy; | 22 class SignalStrategy; |
22 class UrlRequestFactory; | 23 class UrlRequestFactory; |
23 | 24 |
24 namespace protocol { | 25 namespace protocol { |
25 | 26 |
26 class PortAllocatorFactory; | 27 class PortAllocatorFactory; |
27 class IceConfigRequest; | 28 class IceConfigRequest; |
28 | 29 |
29 // TransportContext is responsible for storing all parameters required for | 30 // TransportContext is responsible for storing all parameters required for |
30 // P2P transport initialization. It's also responsible for fetching STUN and | 31 // P2P transport initialization. It's also responsible for fetching STUN and |
31 // TURN configuration. | 32 // TURN configuration. |
32 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { | 33 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { |
33 public: | 34 public: |
| 35 enum RelayMode { |
| 36 GTURN, |
| 37 TURN, |
| 38 |
| 39 LAST_RELAYMODE = TURN |
| 40 }; |
| 41 static const int kNumRelayModes = RelayMode::LAST_RELAYMODE + 1; |
| 42 |
34 typedef base::Callback<void(const IceConfig& ice_config)> | 43 typedef base::Callback<void(const IceConfig& ice_config)> |
35 GetIceConfigCallback; | 44 GetIceConfigCallback; |
36 | 45 |
37 static scoped_refptr<TransportContext> ForTests(TransportRole role); | 46 static scoped_refptr<TransportContext> ForTests(TransportRole role); |
38 | 47 |
39 TransportContext(SignalStrategy* signal_strategy, | 48 TransportContext(SignalStrategy* signal_strategy, |
40 scoped_ptr<PortAllocatorFactory> port_allocator_factory, | 49 scoped_ptr<PortAllocatorFactory> port_allocator_factory, |
41 scoped_ptr<UrlRequestFactory> url_request_factory, | 50 scoped_ptr<UrlRequestFactory> url_request_factory, |
42 const NetworkSettings& network_settings, | 51 const NetworkSettings& network_settings, |
43 TransportRole role); | 52 TransportRole role); |
44 | 53 |
45 // Enables standard TURN servers. | 54 void set_ice_config_url(const std::string& ice_config_url) { |
46 void UseTurn(const std::string& ice_config_url) { | |
47 ice_config_url_ = ice_config_url; | 55 ice_config_url_ = ice_config_url; |
48 } | 56 } |
49 | 57 |
| 58 // Sets relay mode for all future calls of GetIceConfig(). Doesn't affect |
| 59 // previous GetIceConfig() requests. |
| 60 void set_relay_mode(RelayMode relay_mode) { relay_mode_ = relay_mode; } |
| 61 |
50 // Prepares fresh JingleInfo. It may be called while connection is being | 62 // Prepares fresh JingleInfo. It may be called while connection is being |
51 // negotiated to minimize the chance that the following GetIceConfig() will | 63 // negotiated to minimize the chance that the following GetIceConfig() will |
52 // be blocking. | 64 // be blocking. |
53 void Prepare(); | 65 void Prepare(); |
54 | 66 |
55 // Requests fresh STUN and TURN information. | 67 // Requests fresh STUN and TURN information. |
56 void GetIceConfig(const GetIceConfigCallback& callback); | 68 void GetIceConfig(const GetIceConfigCallback& callback); |
57 | 69 |
58 PortAllocatorFactory* port_allocator_factory() { | 70 PortAllocatorFactory* port_allocator_factory() { |
59 return port_allocator_factory_.get(); | 71 return port_allocator_factory_.get(); |
60 } | 72 } |
61 UrlRequestFactory* url_request_factory() { | 73 UrlRequestFactory* url_request_factory() { |
62 return url_request_factory_.get(); | 74 return url_request_factory_.get(); |
63 } | 75 } |
64 const NetworkSettings& network_settings() const { return network_settings_; } | 76 const NetworkSettings& network_settings() const { return network_settings_; } |
65 TransportRole role() const { return role_; } | 77 TransportRole role() const { return role_; } |
66 | 78 |
67 private: | 79 private: |
68 friend class base::RefCountedThreadSafe<TransportContext>; | 80 friend class base::RefCountedThreadSafe<TransportContext>; |
69 | 81 |
70 ~TransportContext(); | 82 ~TransportContext(); |
71 | 83 |
72 void EnsureFreshJingleInfo(); | 84 void EnsureFreshIceConfig(); |
73 void OnIceConfig(const IceConfig& ice_config); | 85 void OnIceConfig(RelayMode relay_mode, const IceConfig& ice_config); |
74 | 86 |
75 SignalStrategy* signal_strategy_; | 87 SignalStrategy* signal_strategy_; |
76 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; | 88 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; |
77 scoped_ptr<UrlRequestFactory> url_request_factory_; | 89 scoped_ptr<UrlRequestFactory> url_request_factory_; |
78 NetworkSettings network_settings_; | 90 NetworkSettings network_settings_; |
79 TransportRole role_; | 91 TransportRole role_; |
80 | 92 |
81 std::string ice_config_url_; | 93 std::string ice_config_url_; |
| 94 RelayMode relay_mode_ = RelayMode::GTURN; |
82 | 95 |
83 scoped_ptr<IceConfigRequest> ice_config_request_; | 96 std::array<scoped_ptr<IceConfigRequest>, kNumRelayModes> ice_config_request_; |
| 97 std::array<IceConfig, kNumRelayModes> ice_config_; |
84 | 98 |
85 IceConfig ice_config_; | 99 // When there is an active |ice_config_request_| stores list of callbacks to |
86 | |
87 // When there is an active |jingle_info_request_| stores list of callbacks to | |
88 // be called once the request is finished. | 100 // be called once the request is finished. |
89 std::list<GetIceConfigCallback> pending_ice_config_callbacks_; | 101 std::array<std::list<GetIceConfigCallback>, kNumRelayModes> |
| 102 pending_ice_config_callbacks_; |
90 | 103 |
91 DISALLOW_COPY_AND_ASSIGN(TransportContext); | 104 DISALLOW_COPY_AND_ASSIGN(TransportContext); |
92 }; | 105 }; |
93 | 106 |
94 } // namespace protocol | 107 } // namespace protocol |
95 } // namespace remoting | 108 } // namespace remoting |
96 | 109 |
97 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 110 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
OLD | NEW |