Chromium Code Reviews| 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/protocol/authenticator.h" | 8 #include "remoting/protocol/authenticator.h" |
| 9 #include "remoting/protocol/content_description.h" | 9 #include "remoting/protocol/content_description.h" |
| 10 #include "remoting/protocol/jingle_messages.h" | 10 #include "remoting/protocol/jingle_messages.h" |
| 11 #include "remoting/protocol/jingle_session.h" | 11 #include "remoting/protocol/jingle_session.h" |
| 12 #include "remoting/protocol/transport.h" | 12 #include "remoting/protocol/transport.h" |
| 13 #include "remoting/signaling/iq_sender.h" | 13 #include "remoting/signaling/iq_sender.h" |
| 14 #include "remoting/signaling/signal_strategy.h" | 14 #include "remoting/signaling/signal_strategy.h" |
| 15 #include "third_party/webrtc/base/socketaddress.h" | 15 #include "third_party/webrtc/base/socketaddress.h" |
| 16 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 16 #include "third_party/webrtc/libjingle/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 : protocol_config_(CandidateSessionConfig::CreateDefault()), | 25 SignalStrategy* signal_strategy) |
| 26 transport_factory_(transport_factory.Pass()) {} | 26 : transport_factory_(transport_factory.Pass()), |
| 27 | 27 signal_strategy_(signal_strategy), |
| 28 JingleSessionManager::~JingleSessionManager() { | 28 protocol_config_(CandidateSessionConfig::CreateDefault()), |
| 29 Close(); | 29 iq_sender_(new IqSender(signal_strategy_)) { |
| 30 } | |
| 31 | |
| 32 void JingleSessionManager::Init( | |
| 33 SignalStrategy* signal_strategy, | |
| 34 SessionManager::Listener* listener) { | |
| 35 listener_ = listener; | |
| 36 signal_strategy_ = signal_strategy; | |
| 37 iq_sender_.reset(new IqSender(signal_strategy_)); | |
| 38 | |
| 39 signal_strategy_->AddListener(this); | 30 signal_strategy_->AddListener(this); |
| 40 } | 31 } |
| 41 | 32 |
| 33 JingleSessionManager::~JingleSessionManager() { | |
| 34 DCHECK(sessions_.empty()); | |
| 35 signal_strategy_->RemoveListener(this); | |
| 36 } | |
| 37 | |
| 38 void JingleSessionManager::AcceptIncoming( | |
| 39 const IncomingSessionCallback& incoming_session_callback) { | |
| 40 incoming_session_callback_ = incoming_session_callback; | |
|
Jamie
2015/12/15 00:32:01
DCHECK(incoming_session_callback_.is_null())? Or i
Sergey Ulanov
2015/12/16 23:17:39
Yeah, I don't think there are any issues with this
| |
| 41 | |
| 42 } | |
| 43 | |
| 42 void JingleSessionManager::set_protocol_config( | 44 void JingleSessionManager::set_protocol_config( |
| 43 scoped_ptr<CandidateSessionConfig> config) { | 45 scoped_ptr<CandidateSessionConfig> config) { |
| 44 protocol_config_ = config.Pass(); | 46 protocol_config_ = config.Pass(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 scoped_ptr<Session> JingleSessionManager::Connect( | 49 scoped_ptr<Session> JingleSessionManager::Connect( |
| 48 const std::string& host_jid, | 50 const std::string& host_jid, |
| 49 scoped_ptr<Authenticator> authenticator) { | 51 scoped_ptr<Authenticator> authenticator) { |
| 50 scoped_ptr<JingleSession> session(new JingleSession(this)); | 52 scoped_ptr<JingleSession> session(new JingleSession(this)); |
| 51 session->StartConnection(host_jid, authenticator.Pass()); | 53 session->StartConnection(host_jid, authenticator.Pass()); |
| 52 sessions_[session->session_id_] = session.get(); | 54 sessions_[session->session_id_] = session.get(); |
| 53 return session.Pass(); | 55 return session.Pass(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void JingleSessionManager::Close() { | |
| 57 DCHECK(CalledOnValidThread()); | |
| 58 | |
| 59 // Close() can be called only after all sessions are destroyed. | |
| 60 DCHECK(sessions_.empty()); | |
| 61 | |
| 62 listener_ = nullptr; | |
| 63 | |
| 64 if (signal_strategy_) { | |
| 65 signal_strategy_->RemoveListener(this); | |
| 66 signal_strategy_ = nullptr; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void JingleSessionManager::set_authenticator_factory( | 58 void JingleSessionManager::set_authenticator_factory( |
| 71 scoped_ptr<AuthenticatorFactory> authenticator_factory) { | 59 scoped_ptr<AuthenticatorFactory> authenticator_factory) { |
| 72 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
| 73 authenticator_factory_ = authenticator_factory.Pass(); | 61 authenticator_factory_ = authenticator_factory.Pass(); |
| 74 } | 62 } |
| 75 | 63 |
| 76 void JingleSessionManager::OnSignalStrategyStateChange( | 64 void JingleSessionManager::OnSignalStrategyStateChange( |
| 77 SignalStrategy::State state) {} | 65 SignalStrategy::State state) {} |
| 78 | 66 |
| 79 bool JingleSessionManager::OnSignalStrategyIncomingStanza( | 67 bool JingleSessionManager::OnSignalStrategyIncomingStanza( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 104 sessions_[session->session_id_] = session; | 92 sessions_[session->session_id_] = session; |
| 105 | 93 |
| 106 // Destroy the session if it was rejected due to incompatible protocol. | 94 // Destroy the session if it was rejected due to incompatible protocol. |
| 107 if (session->state_ != Session::ACCEPTING) { | 95 if (session->state_ != Session::ACCEPTING) { |
| 108 delete session; | 96 delete session; |
| 109 DCHECK(sessions_.find(message.sid) == sessions_.end()); | 97 DCHECK(sessions_.find(message.sid) == sessions_.end()); |
| 110 return true; | 98 return true; |
| 111 } | 99 } |
| 112 | 100 |
| 113 IncomingSessionResponse response = SessionManager::DECLINE; | 101 IncomingSessionResponse response = SessionManager::DECLINE; |
| 114 listener_->OnIncomingSession(session, &response); | 102 if (!incoming_session_callback_.is_null()) |
| 103 incoming_session_callback_.Run(session, &response); | |
| 115 | 104 |
| 116 if (response == SessionManager::ACCEPT) { | 105 if (response == SessionManager::ACCEPT) { |
| 117 session->AcceptIncomingConnection(message); | 106 session->AcceptIncomingConnection(message); |
| 118 } else { | 107 } else { |
| 119 ErrorCode error; | 108 ErrorCode error; |
| 120 switch (response) { | 109 switch (response) { |
| 121 case OVERLOAD: | 110 case OVERLOAD: |
| 122 error = HOST_OVERLOAD; | 111 error = HOST_OVERLOAD; |
| 123 break; | 112 break; |
| 124 | 113 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 155 signal_strategy_->SendStanza( | 144 signal_strategy_->SendStanza( |
| 156 JingleMessageReply(error).ToXml(original_stanza)); | 145 JingleMessageReply(error).ToXml(original_stanza)); |
| 157 } | 146 } |
| 158 | 147 |
| 159 void JingleSessionManager::SessionDestroyed(JingleSession* session) { | 148 void JingleSessionManager::SessionDestroyed(JingleSession* session) { |
| 160 sessions_.erase(session->session_id_); | 149 sessions_.erase(session->session_id_); |
| 161 } | 150 } |
| 162 | 151 |
| 163 } // namespace protocol | 152 } // namespace protocol |
| 164 } // namespace remoting | 153 } // namespace remoting |
| OLD | NEW |