OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "remoting/protocol/jingle_session_manager.h" | 5 #include "remoting/protocol/jingle_session_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "remoting/jingle_glue/iq_sender.h" | 8 #include "remoting/jingle_glue/iq_sender.h" |
9 #include "remoting/jingle_glue/jingle_info_request.h" | 9 #include "remoting/jingle_glue/jingle_info_request.h" |
10 #include "remoting/jingle_glue/signal_strategy.h" | 10 #include "remoting/jingle_glue/signal_strategy.h" |
11 #include "remoting/protocol/authenticator.h" | 11 #include "remoting/protocol/authenticator.h" |
12 #include "remoting/protocol/content_description.h" | 12 #include "remoting/protocol/content_description.h" |
13 #include "remoting/protocol/jingle_messages.h" | 13 #include "remoting/protocol/jingle_messages.h" |
14 #include "remoting/protocol/jingle_session.h" | 14 #include "remoting/protocol/jingle_session.h" |
15 #include "third_party/libjingle/source/talk/base/socketaddress.h" | 15 #include "third_party/libjingle/source/talk/base/socketaddress.h" |
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
17 | 17 |
18 using buzz::QName; | 18 using buzz::QName; |
19 | 19 |
20 namespace remoting { | 20 namespace remoting { |
21 namespace protocol { | 21 namespace protocol { |
22 | 22 |
23 JingleSessionManager::JingleSessionManager( | 23 JingleSessionManager::JingleSessionManager( |
24 scoped_ptr<TransportFactory> transport_factory) | 24 scoped_ptr<TransportFactory> transport_factory, |
| 25 bool fetch_nat_traversal_config) |
25 : transport_factory_(transport_factory.Pass()), | 26 : transport_factory_(transport_factory.Pass()), |
| 27 fetch_nat_traversal_config_(fetch_nat_traversal_config), |
26 signal_strategy_(NULL), | 28 signal_strategy_(NULL), |
27 listener_(NULL), | 29 listener_(NULL), |
28 ready_(false) { | 30 ready_(false) { |
29 } | 31 } |
30 | 32 |
31 JingleSessionManager::~JingleSessionManager() { | 33 JingleSessionManager::~JingleSessionManager() { |
32 Close(); | 34 Close(); |
33 } | 35 } |
34 | 36 |
35 void JingleSessionManager::Init( | 37 void JingleSessionManager::Init( |
36 SignalStrategy* signal_strategy, | 38 SignalStrategy* signal_strategy, |
37 SessionManager::Listener* listener, | 39 SessionManager::Listener* listener) { |
38 const NetworkSettings& network_settings) { | |
39 listener_ = listener; | 40 listener_ = listener; |
40 signal_strategy_ = signal_strategy; | 41 signal_strategy_ = signal_strategy; |
41 iq_sender_.reset(new IqSender(signal_strategy_)); | 42 iq_sender_.reset(new IqSender(signal_strategy_)); |
42 | 43 |
43 transport_config_.nat_traversal_mode = network_settings.nat_traversal_mode; | |
44 transport_config_.min_port = network_settings.min_port; | |
45 transport_config_.max_port = network_settings.max_port; | |
46 | |
47 signal_strategy_->AddListener(this); | 44 signal_strategy_->AddListener(this); |
48 | 45 |
49 OnSignalStrategyStateChange(signal_strategy_->GetState()); | 46 OnSignalStrategyStateChange(signal_strategy_->GetState()); |
50 } | 47 } |
51 | 48 |
52 void JingleSessionManager::OnJingleInfo( | 49 void JingleSessionManager::OnJingleInfo( |
53 const std::string& relay_token, | 50 const std::string& relay_token, |
54 const std::vector<std::string>& relay_hosts, | 51 const std::vector<std::string>& relay_hosts, |
55 const std::vector<talk_base::SocketAddress>& stun_hosts) { | 52 const std::vector<talk_base::SocketAddress>& stun_hosts) { |
56 DCHECK(CalledOnValidThread()); | 53 DCHECK(CalledOnValidThread()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 95 } |
99 | 96 |
100 void JingleSessionManager::set_authenticator_factory( | 97 void JingleSessionManager::set_authenticator_factory( |
101 scoped_ptr<AuthenticatorFactory> authenticator_factory) { | 98 scoped_ptr<AuthenticatorFactory> authenticator_factory) { |
102 DCHECK(CalledOnValidThread()); | 99 DCHECK(CalledOnValidThread()); |
103 authenticator_factory_ = authenticator_factory.Pass(); | 100 authenticator_factory_ = authenticator_factory.Pass(); |
104 } | 101 } |
105 | 102 |
106 void JingleSessionManager::OnSignalStrategyStateChange( | 103 void JingleSessionManager::OnSignalStrategyStateChange( |
107 SignalStrategy::State state) { | 104 SignalStrategy::State state) { |
108 // If NAT traversal is enabled then we need to request STUN/Relay info. | |
109 if (state == SignalStrategy::CONNECTED) { | 105 if (state == SignalStrategy::CONNECTED) { |
110 if (transport_config_.nat_traversal_mode == | 106 // Request STUN/Relay info if necessary. |
111 TransportConfig::NAT_TRAVERSAL_ENABLED) { | 107 if (fetch_nat_traversal_config_) { |
112 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_)); | 108 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_)); |
113 jingle_info_request_->Send(base::Bind(&JingleSessionManager::OnJingleInfo, | 109 jingle_info_request_->Send(base::Bind(&JingleSessionManager::OnJingleInfo, |
114 base::Unretained(this))); | 110 base::Unretained(this))); |
115 } else if (!ready_) { | 111 } else if (!ready_) { |
116 ready_ = true; | 112 ready_ = true; |
117 listener_->OnSessionManagerReady(); | 113 listener_->OnSessionManagerReady(); |
118 } | 114 } |
119 } | 115 } |
120 } | 116 } |
121 | 117 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 signal_strategy_->SendStanza( | 190 signal_strategy_->SendStanza( |
195 JingleMessageReply(error).ToXml(original_stanza)); | 191 JingleMessageReply(error).ToXml(original_stanza)); |
196 } | 192 } |
197 | 193 |
198 void JingleSessionManager::SessionDestroyed(JingleSession* session) { | 194 void JingleSessionManager::SessionDestroyed(JingleSession* session) { |
199 sessions_.erase(session->session_id_); | 195 sessions_.erase(session->session_id_); |
200 } | 196 } |
201 | 197 |
202 } // namespace protocol | 198 } // namespace protocol |
203 } // namespace remoting | 199 } // namespace remoting |
OLD | NEW |