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 <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "remoting/protocol/ice_config.h" |
15 #include "remoting/protocol/network_settings.h" | 16 #include "remoting/protocol/network_settings.h" |
16 #include "remoting/protocol/transport.h" | 17 #include "remoting/protocol/transport.h" |
17 #include "remoting/signaling/jingle_info_request.h" | |
18 | |
19 | 18 |
20 namespace remoting { | 19 namespace remoting { |
21 | 20 |
22 class SignalStrategy; | 21 class SignalStrategy; |
23 class UrlRequestFactory; | 22 class UrlRequestFactory; |
24 | 23 |
25 namespace protocol { | 24 namespace protocol { |
26 | 25 |
27 class PortAllocatorFactory; | 26 class PortAllocatorFactory; |
| 27 class IceConfigRequest; |
28 | 28 |
29 // TransportContext is responsible for storing all parameters required for | 29 // TransportContext is responsible for storing all parameters required for |
30 // P2P transport initialization. It's also responsible for making JingleInfo | 30 // P2P transport initialization. It's also responsible for fetching STUN and |
31 // request. | 31 // TURN configuration. |
32 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { | 32 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { |
33 public: | 33 public: |
34 typedef base::Callback<void(std::vector<rtc::SocketAddress> stun_hosts, | 34 typedef base::Callback<void(const IceConfig& ice_config)> |
35 std::vector<std::string> relay_hosts, | 35 GetIceConfigCallback; |
36 std::string relay_token)> GetJingleInfoCallback; | |
37 | 36 |
38 static scoped_refptr<TransportContext> ForTests(TransportRole role); | 37 static scoped_refptr<TransportContext> ForTests(TransportRole role); |
39 | 38 |
40 TransportContext(SignalStrategy* signal_strategy, | 39 TransportContext(SignalStrategy* signal_strategy, |
41 scoped_ptr<PortAllocatorFactory> port_allocator_factory, | 40 scoped_ptr<PortAllocatorFactory> port_allocator_factory, |
42 scoped_ptr<UrlRequestFactory> url_request_factory, | 41 scoped_ptr<UrlRequestFactory> url_request_factory, |
43 const NetworkSettings& network_settings, | 42 const NetworkSettings& network_settings, |
44 TransportRole role); | 43 TransportRole role); |
45 | 44 |
46 // Prepares fresh JingleInfo. It may be called while connection is being | 45 // Prepares fresh JingleInfo. It may be called while connection is being |
47 // negotiated to minimize the chance that the following GetJingleInfo() will | 46 // negotiated to minimize the chance that the following GetIceConfig() will |
48 // be blocking. | 47 // be blocking. |
49 void Prepare(); | 48 void Prepare(); |
50 | 49 |
51 // Requests fresh STUN and TURN information. | 50 // Requests fresh STUN and TURN information. |
52 void GetJingleInfo(const GetJingleInfoCallback& callback); | 51 void GetIceConfig(const GetIceConfigCallback& callback); |
53 | 52 |
54 PortAllocatorFactory* port_allocator_factory() { | 53 PortAllocatorFactory* port_allocator_factory() { |
55 return port_allocator_factory_.get(); | 54 return port_allocator_factory_.get(); |
56 } | 55 } |
57 UrlRequestFactory* url_request_factory() { | 56 UrlRequestFactory* url_request_factory() { |
58 return url_request_factory_.get(); | 57 return url_request_factory_.get(); |
59 } | 58 } |
60 const NetworkSettings& network_settings() const { return network_settings_; } | 59 const NetworkSettings& network_settings() const { return network_settings_; } |
61 TransportRole role() const { return role_; } | 60 TransportRole role() const { return role_; } |
62 | 61 |
63 private: | 62 private: |
64 friend class base::RefCountedThreadSafe<TransportContext>; | 63 friend class base::RefCountedThreadSafe<TransportContext>; |
65 | 64 |
66 ~TransportContext(); | 65 ~TransportContext(); |
67 | 66 |
68 void EnsureFreshJingleInfo(); | 67 void EnsureFreshJingleInfo(); |
69 void OnJingleInfo(const std::string& relay_token, | 68 void OnIceConfig(const IceConfig& ice_config); |
70 const std::vector<std::string>& relay_hosts, | |
71 const std::vector<rtc::SocketAddress>& stun_hosts); | |
72 | 69 |
73 SignalStrategy* signal_strategy_; | 70 SignalStrategy* signal_strategy_; |
74 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; | 71 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; |
75 scoped_ptr<UrlRequestFactory> url_request_factory_; | 72 scoped_ptr<UrlRequestFactory> url_request_factory_; |
76 NetworkSettings network_settings_; | 73 NetworkSettings network_settings_; |
77 TransportRole role_; | 74 TransportRole role_; |
78 | 75 |
79 base::TimeTicks last_jingle_info_update_time_; | 76 scoped_ptr<IceConfigRequest> ice_config_request_; |
80 scoped_ptr<JingleInfoRequest> jingle_info_request_; | |
81 | 77 |
82 std::vector<rtc::SocketAddress> stun_hosts_; | 78 IceConfig ice_config_; |
83 std::vector<std::string> relay_hosts_; | |
84 std::string relay_token_; | |
85 | 79 |
86 // When there is an active |jingle_info_request_| stores list of callbacks to | 80 // When there is an active |jingle_info_request_| stores list of callbacks to |
87 // be called once the request is finished. | 81 // be called once the request is finished. |
88 std::list<GetJingleInfoCallback> pending_jingle_info_callbacks_; | 82 std::list<GetIceConfigCallback> pending_ice_config_callbacks_; |
89 | 83 |
90 DISALLOW_COPY_AND_ASSIGN(TransportContext); | 84 DISALLOW_COPY_AND_ASSIGN(TransportContext); |
91 }; | 85 }; |
92 | 86 |
93 } // namespace protocol | 87 } // namespace protocol |
94 } // namespace remoting | 88 } // namespace remoting |
95 | 89 |
96 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 90 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
OLD | NEW |