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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "remoting/protocol/authenticator.h" | 10 #include "remoting/protocol/authenticator.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 DCHECK(sessions_.empty()); | 33 DCHECK(sessions_.empty()); |
34 signal_strategy_->RemoveListener(this); | 34 signal_strategy_->RemoveListener(this); |
35 } | 35 } |
36 | 36 |
37 void JingleSessionManager::AcceptIncoming( | 37 void JingleSessionManager::AcceptIncoming( |
38 const IncomingSessionCallback& incoming_session_callback) { | 38 const IncomingSessionCallback& incoming_session_callback) { |
39 incoming_session_callback_ = incoming_session_callback; | 39 incoming_session_callback_ = incoming_session_callback; |
40 } | 40 } |
41 | 41 |
42 void JingleSessionManager::set_protocol_config( | 42 void JingleSessionManager::set_protocol_config( |
43 scoped_ptr<CandidateSessionConfig> config) { | 43 std::unique_ptr<CandidateSessionConfig> config) { |
44 protocol_config_ = std::move(config); | 44 protocol_config_ = std::move(config); |
45 } | 45 } |
46 | 46 |
47 scoped_ptr<Session> JingleSessionManager::Connect( | 47 std::unique_ptr<Session> JingleSessionManager::Connect( |
48 const std::string& host_jid, | 48 const std::string& host_jid, |
49 scoped_ptr<Authenticator> authenticator) { | 49 std::unique_ptr<Authenticator> authenticator) { |
50 scoped_ptr<JingleSession> session(new JingleSession(this)); | 50 std::unique_ptr<JingleSession> session(new JingleSession(this)); |
51 session->StartConnection(host_jid, std::move(authenticator)); | 51 session->StartConnection(host_jid, std::move(authenticator)); |
52 sessions_[session->session_id_] = session.get(); | 52 sessions_[session->session_id_] = session.get(); |
53 return std::move(session); | 53 return std::move(session); |
54 } | 54 } |
55 | 55 |
56 void JingleSessionManager::set_authenticator_factory( | 56 void JingleSessionManager::set_authenticator_factory( |
57 scoped_ptr<AuthenticatorFactory> authenticator_factory) { | 57 std::unique_ptr<AuthenticatorFactory> authenticator_factory) { |
58 DCHECK(CalledOnValidThread()); | 58 DCHECK(CalledOnValidThread()); |
59 authenticator_factory_ = std::move(authenticator_factory); | 59 authenticator_factory_ = std::move(authenticator_factory); |
60 } | 60 } |
61 | 61 |
62 void JingleSessionManager::OnSignalStrategyStateChange( | 62 void JingleSessionManager::OnSignalStrategyStateChange( |
63 SignalStrategy::State state) {} | 63 SignalStrategy::State state) {} |
64 | 64 |
65 bool JingleSessionManager::OnSignalStrategyIncomingStanza( | 65 bool JingleSessionManager::OnSignalStrategyIncomingStanza( |
66 const buzz::XmlElement* stanza) { | 66 const buzz::XmlElement* stanza) { |
67 if (!JingleMessage::IsJingleMessage(stanza)) | 67 if (!JingleMessage::IsJingleMessage(stanza)) |
68 return false; | 68 return false; |
69 | 69 |
70 JingleMessage message; | 70 JingleMessage message; |
71 std::string error; | 71 std::string error; |
72 if (!message.ParseXml(stanza, &error)) { | 72 if (!message.ParseXml(stanza, &error)) { |
73 SendReply(stanza, JingleMessageReply::BAD_REQUEST); | 73 SendReply(stanza, JingleMessageReply::BAD_REQUEST); |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 if (message.action == JingleMessage::SESSION_INITIATE) { | 77 if (message.action == JingleMessage::SESSION_INITIATE) { |
78 // Description must be present in session-initiate messages. | 78 // Description must be present in session-initiate messages. |
79 DCHECK(message.description.get()); | 79 DCHECK(message.description.get()); |
80 | 80 |
81 SendReply(stanza, JingleMessageReply::NONE); | 81 SendReply(stanza, JingleMessageReply::NONE); |
82 | 82 |
83 scoped_ptr<Authenticator> authenticator = | 83 std::unique_ptr<Authenticator> authenticator = |
84 authenticator_factory_->CreateAuthenticator( | 84 authenticator_factory_->CreateAuthenticator( |
85 signal_strategy_->GetLocalJid(), message.from); | 85 signal_strategy_->GetLocalJid(), message.from); |
86 | 86 |
87 JingleSession* session = new JingleSession(this); | 87 JingleSession* session = new JingleSession(this); |
88 session->InitializeIncomingConnection(message, std::move(authenticator)); | 88 session->InitializeIncomingConnection(message, std::move(authenticator)); |
89 sessions_[session->session_id_] = session; | 89 sessions_[session->session_id_] = session; |
90 | 90 |
91 // Destroy the session if it was rejected due to incompatible protocol. | 91 // Destroy the session if it was rejected due to incompatible protocol. |
92 if (session->state_ != Session::ACCEPTING) { | 92 if (session->state_ != Session::ACCEPTING) { |
93 delete session; | 93 delete session; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 signal_strategy_->SendStanza( | 141 signal_strategy_->SendStanza( |
142 JingleMessageReply(error).ToXml(original_stanza)); | 142 JingleMessageReply(error).ToXml(original_stanza)); |
143 } | 143 } |
144 | 144 |
145 void JingleSessionManager::SessionDestroyed(JingleSession* session) { | 145 void JingleSessionManager::SessionDestroyed(JingleSession* session) { |
146 sessions_.erase(session->session_id_); | 146 sessions_.erase(session->session_id_); |
147 } | 147 } |
148 | 148 |
149 } // namespace protocol | 149 } // namespace protocol |
150 } // namespace remoting | 150 } // namespace remoting |
OLD | NEW |