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 SignalStrategy* signal_strategy) | 25 SignalStrategy* signal_strategy) |
26 : transport_factory_(transport_factory.Pass()), | 26 : transport_factory_(std::move(transport_factory)), |
27 signal_strategy_(signal_strategy), | 27 signal_strategy_(signal_strategy), |
28 protocol_config_(CandidateSessionConfig::CreateDefault()), | 28 protocol_config_(CandidateSessionConfig::CreateDefault()), |
29 iq_sender_(new IqSender(signal_strategy_)) { | 29 iq_sender_(new IqSender(signal_strategy_)) { |
30 signal_strategy_->AddListener(this); | 30 signal_strategy_->AddListener(this); |
31 } | 31 } |
32 | 32 |
33 JingleSessionManager::~JingleSessionManager() { | 33 JingleSessionManager::~JingleSessionManager() { |
34 DCHECK(sessions_.empty()); | 34 DCHECK(sessions_.empty()); |
35 signal_strategy_->RemoveListener(this); | 35 signal_strategy_->RemoveListener(this); |
36 } | 36 } |
37 | 37 |
38 void JingleSessionManager::AcceptIncoming( | 38 void JingleSessionManager::AcceptIncoming( |
39 const IncomingSessionCallback& incoming_session_callback) { | 39 const IncomingSessionCallback& incoming_session_callback) { |
40 incoming_session_callback_ = incoming_session_callback; | 40 incoming_session_callback_ = incoming_session_callback; |
41 | 41 |
42 } | 42 } |
43 | 43 |
44 void JingleSessionManager::set_protocol_config( | 44 void JingleSessionManager::set_protocol_config( |
45 scoped_ptr<CandidateSessionConfig> config) { | 45 scoped_ptr<CandidateSessionConfig> config) { |
46 protocol_config_ = config.Pass(); | 46 protocol_config_ = std::move(config); |
47 } | 47 } |
48 | 48 |
49 scoped_ptr<Session> JingleSessionManager::Connect( | 49 scoped_ptr<Session> JingleSessionManager::Connect( |
50 const std::string& host_jid, | 50 const std::string& host_jid, |
51 scoped_ptr<Authenticator> authenticator) { | 51 scoped_ptr<Authenticator> authenticator) { |
52 scoped_ptr<JingleSession> session(new JingleSession(this)); | 52 scoped_ptr<JingleSession> session(new JingleSession(this)); |
53 session->StartConnection(host_jid, authenticator.Pass()); | 53 session->StartConnection(host_jid, std::move(authenticator)); |
54 sessions_[session->session_id_] = session.get(); | 54 sessions_[session->session_id_] = session.get(); |
55 return session.Pass(); | 55 return std::move(session); |
56 } | 56 } |
57 | 57 |
58 void JingleSessionManager::set_authenticator_factory( | 58 void JingleSessionManager::set_authenticator_factory( |
59 scoped_ptr<AuthenticatorFactory> authenticator_factory) { | 59 scoped_ptr<AuthenticatorFactory> authenticator_factory) { |
60 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
61 authenticator_factory_ = authenticator_factory.Pass(); | 61 authenticator_factory_ = std::move(authenticator_factory); |
62 } | 62 } |
63 | 63 |
64 void JingleSessionManager::OnSignalStrategyStateChange( | 64 void JingleSessionManager::OnSignalStrategyStateChange( |
65 SignalStrategy::State state) {} | 65 SignalStrategy::State state) {} |
66 | 66 |
67 bool JingleSessionManager::OnSignalStrategyIncomingStanza( | 67 bool JingleSessionManager::OnSignalStrategyIncomingStanza( |
68 const buzz::XmlElement* stanza) { | 68 const buzz::XmlElement* stanza) { |
69 if (!JingleMessage::IsJingleMessage(stanza)) | 69 if (!JingleMessage::IsJingleMessage(stanza)) |
70 return false; | 70 return false; |
71 | 71 |
72 JingleMessage message; | 72 JingleMessage message; |
73 std::string error; | 73 std::string error; |
74 if (!message.ParseXml(stanza, &error)) { | 74 if (!message.ParseXml(stanza, &error)) { |
75 SendReply(stanza, JingleMessageReply::BAD_REQUEST); | 75 SendReply(stanza, JingleMessageReply::BAD_REQUEST); |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 if (message.action == JingleMessage::SESSION_INITIATE) { | 79 if (message.action == JingleMessage::SESSION_INITIATE) { |
80 // Description must be present in session-initiate messages. | 80 // Description must be present in session-initiate messages. |
81 DCHECK(message.description.get()); | 81 DCHECK(message.description.get()); |
82 | 82 |
83 SendReply(stanza, JingleMessageReply::NONE); | 83 SendReply(stanza, JingleMessageReply::NONE); |
84 | 84 |
85 scoped_ptr<Authenticator> authenticator = | 85 scoped_ptr<Authenticator> authenticator = |
86 authenticator_factory_->CreateAuthenticator( | 86 authenticator_factory_->CreateAuthenticator( |
87 signal_strategy_->GetLocalJid(), message.from, | 87 signal_strategy_->GetLocalJid(), message.from, |
88 message.description->authenticator_message()); | 88 message.description->authenticator_message()); |
89 | 89 |
90 JingleSession* session = new JingleSession(this); | 90 JingleSession* session = new JingleSession(this); |
91 session->InitializeIncomingConnection(message, authenticator.Pass()); | 91 session->InitializeIncomingConnection(message, std::move(authenticator)); |
92 sessions_[session->session_id_] = session; | 92 sessions_[session->session_id_] = session; |
93 | 93 |
94 // Destroy the session if it was rejected due to incompatible protocol. | 94 // Destroy the session if it was rejected due to incompatible protocol. |
95 if (session->state_ != Session::ACCEPTING) { | 95 if (session->state_ != Session::ACCEPTING) { |
96 delete session; | 96 delete session; |
97 DCHECK(sessions_.find(message.sid) == sessions_.end()); | 97 DCHECK(sessions_.find(message.sid) == sessions_.end()); |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 IncomingSessionResponse response = SessionManager::DECLINE; | 101 IncomingSessionResponse response = SessionManager::DECLINE; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 signal_strategy_->SendStanza( | 144 signal_strategy_->SendStanza( |
145 JingleMessageReply(error).ToXml(original_stanza)); | 145 JingleMessageReply(error).ToXml(original_stanza)); |
146 } | 146 } |
147 | 147 |
148 void JingleSessionManager::SessionDestroyed(JingleSession* session) { | 148 void JingleSessionManager::SessionDestroyed(JingleSession* session) { |
149 sessions_.erase(session->session_id_); | 149 sessions_.erase(session->session_id_); |
150 } | 150 } |
151 | 151 |
152 } // namespace protocol | 152 } // namespace protocol |
153 } // namespace remoting | 153 } // namespace remoting |
OLD | NEW |