| 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> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace remoting { | 23 namespace remoting { |
| 24 | 24 |
| 25 class SignalStrategy; | 25 class SignalStrategy; |
| 26 | 26 |
| 27 namespace protocol { | 27 namespace protocol { |
| 28 | 28 |
| 29 class PortAllocatorFactory; | 29 class PortAllocatorFactory; |
| 30 | 30 |
| 31 // TransportContext is responsible for storing all parameters required for | 31 // TransportContext is responsible for storing all parameters required for |
| 32 // P2P transport initialization. It's also responsible for making JingleInfo | 32 // P2P transport initialization. It's also responsible for making JingleInfo |
| 33 // request and creation of PortAllocators configured according to the JingleInfo | 33 // request. |
| 34 // result. | |
| 35 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { | 34 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { |
| 36 public: | 35 public: |
| 37 typedef base::Callback<void(scoped_ptr<cricket::PortAllocator> | 36 typedef base::Callback<void(std::vector<rtc::SocketAddress> stun_hosts, |
| 38 port_allocator)> CreatePortAllocatorCallback; | 37 std::vector<std::string> relay_hosts, |
| 38 std::string relay_token)> GetJingleInfoCallback; |
| 39 | 39 |
| 40 static scoped_refptr<TransportContext> ForTests(TransportRole role); | 40 static scoped_refptr<TransportContext> ForTests(TransportRole role); |
| 41 | 41 |
| 42 TransportContext( | 42 TransportContext(SignalStrategy* signal_strategy, |
| 43 SignalStrategy* signal_strategy, | 43 scoped_ptr<PortAllocatorFactory> port_allocator_factory, |
| 44 scoped_ptr<PortAllocatorFactory> port_allocator_factory, | 44 const NetworkSettings& network_settings, |
| 45 const NetworkSettings& network_settings, | 45 TransportRole role); |
| 46 TransportRole role); | |
| 47 | 46 |
| 48 // Prepares to create new PortAllocator instances. It may be called while | 47 // Prepares fresh JingleInfo. It may be called while connection is being |
| 49 // connection is being negotiated to minimize the chance that the following | 48 // negotiated to minimize the chance that the following GetJingleInfo() will |
| 50 // CreatePortAllocator() will be blocking. | 49 // be blocking. |
| 51 void Prepare(); | 50 void Prepare(); |
| 52 | 51 |
| 53 // Creates new PortAllocator making sure that it has correct STUN and TURN | 52 // Requests fresh STUN and TURN information. |
| 54 // information. | 53 void GetJingleInfo(const GetJingleInfoCallback& callback); |
| 55 void CreatePortAllocator(const CreatePortAllocatorCallback& callback); | |
| 56 | 54 |
| 57 const NetworkSettings& network_settings() { return network_settings_; } | 55 PortAllocatorFactory* port_allocator_factory() { |
| 58 TransportRole role() { return role_; } | 56 return port_allocator_factory_.get(); |
| 57 } |
| 58 const NetworkSettings& network_settings() const { return network_settings_; } |
| 59 TransportRole role() const { return role_; } |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 friend class base::RefCountedThreadSafe<TransportContext>; | 62 friend class base::RefCountedThreadSafe<TransportContext>; |
| 62 | 63 |
| 63 ~TransportContext(); | 64 ~TransportContext(); |
| 64 | 65 |
| 65 void EnsureFreshJingleInfo(); | 66 void EnsureFreshJingleInfo(); |
| 66 void OnJingleInfo(const std::string& relay_token, | 67 void OnJingleInfo(const std::string& relay_token, |
| 67 const std::vector<std::string>& relay_hosts, | 68 const std::vector<std::string>& relay_hosts, |
| 68 const std::vector<rtc::SocketAddress>& stun_hosts); | 69 const std::vector<rtc::SocketAddress>& stun_hosts); |
| 69 | 70 |
| 70 scoped_ptr<cricket::PortAllocator> CreatePortAllocatorInternal(); | |
| 71 | |
| 72 SignalStrategy* signal_strategy_; | 71 SignalStrategy* signal_strategy_; |
| 73 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; | 72 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; |
| 74 NetworkSettings network_settings_; | 73 NetworkSettings network_settings_; |
| 75 TransportRole role_; | 74 TransportRole role_; |
| 76 | 75 |
| 77 base::TimeTicks last_jingle_info_update_time_; | 76 base::TimeTicks last_jingle_info_update_time_; |
| 78 scoped_ptr<JingleInfoRequest> jingle_info_request_; | 77 scoped_ptr<JingleInfoRequest> jingle_info_request_; |
| 79 | 78 |
| 79 std::vector<rtc::SocketAddress> stun_hosts_; |
| 80 std::vector<std::string> relay_hosts_; |
| 80 std::string relay_token_; | 81 std::string relay_token_; |
| 81 std::vector<std::string> relay_hosts_; | |
| 82 std::vector<rtc::SocketAddress> stun_hosts_; | |
| 83 | 82 |
| 84 // When there is an active |jingle_info_request_| stores list of callbacks to | 83 // When there is an active |jingle_info_request_| stores list of callbacks to |
| 85 // be called once the |jingle_info_request_| is finished. | 84 // be called once the request is finished. |
| 86 std::list<CreatePortAllocatorCallback> pending_port_allocator_requests_; | 85 std::list<GetJingleInfoCallback> pending_jingle_info_callbacks_; |
| 87 | 86 |
| 88 DISALLOW_COPY_AND_ASSIGN(TransportContext); | 87 DISALLOW_COPY_AND_ASSIGN(TransportContext); |
| 89 }; | 88 }; |
| 90 | 89 |
| 91 } // namespace protocol | 90 } // namespace protocol |
| 92 } // namespace remoting | 91 } // namespace remoting |
| 93 | 92 |
| 94 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 93 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
| OLD | NEW |