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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 } | 115 } |
116 | 116 |
117 void JingleSessionManager::set_authenticator_factory( | 117 void JingleSessionManager::set_authenticator_factory( |
118 scoped_ptr<AuthenticatorFactory> authenticator_factory) { | 118 scoped_ptr<AuthenticatorFactory> authenticator_factory) { |
119 DCHECK(CalledOnValidThread()); | 119 DCHECK(CalledOnValidThread()); |
120 DCHECK(authenticator_factory.get()); | 120 DCHECK(authenticator_factory.get()); |
121 DCHECK(!authenticator_factory_.get()); | 121 DCHECK(!authenticator_factory_.get()); |
122 authenticator_factory_ = authenticator_factory.Pass(); | 122 authenticator_factory_ = authenticator_factory.Pass(); |
123 } | 123 } |
124 | 124 |
125 Session* JingleSessionManager::Connect( | 125 scoped_ptr<Session> JingleSessionManager::Connect( |
126 const std::string& host_jid, | 126 const std::string& host_jid, |
127 Authenticator* authenticator, | 127 scoped_ptr<Authenticator> authenticator, |
128 CandidateSessionConfig* candidate_config, | 128 scoped_ptr<CandidateSessionConfig> config, |
129 const Session::StateChangeCallback& state_change_callback) { | 129 const Session::StateChangeCallback& state_change_callback) { |
130 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
131 | 131 |
132 cricket::Session* cricket_session = cricket_session_manager_->CreateSession( | 132 cricket::Session* cricket_session = cricket_session_manager_->CreateSession( |
133 signal_strategy_->GetLocalJid(), kChromotingXmlNamespace); | 133 signal_strategy_->GetLocalJid(), kChromotingXmlNamespace); |
134 cricket_session->set_remote_name(host_jid); | 134 cricket_session->set_remote_name(host_jid); |
135 | 135 |
136 JingleSession* jingle_session = | 136 scoped_ptr<JingleSession> jingle_session( |
137 new JingleSession(this, cricket_session, authenticator); | 137 new JingleSession(this, cricket_session, authenticator.Pass())); |
138 jingle_session->set_candidate_config(candidate_config); | 138 jingle_session->set_candidate_config(config.Pass()); |
139 jingle_session->SetStateChangeCallback(state_change_callback); | 139 jingle_session->SetStateChangeCallback(state_change_callback); |
140 sessions_.push_back(jingle_session); | 140 sessions_.push_back(jingle_session.get()); |
141 | 141 |
142 jingle_session->SendSessionInitiate(); | 142 jingle_session->SendSessionInitiate(); |
143 | 143 |
144 return jingle_session; | 144 return scoped_ptr<Session>(jingle_session.Pass()); |
Wez
2012/01/19 23:23:41
This doesn't seem too painful; at least it works!
Sergey Ulanov
2012/01/19 23:50:26
Yeah, I'm also considering adding PassAs<>(), with
Wez
2012/01/19 23:56:57
That's a good idea. :)
| |
145 } | 145 } |
146 | 146 |
147 void JingleSessionManager::OnSessionCreate( | 147 void JingleSessionManager::OnSessionCreate( |
148 cricket::Session* cricket_session, bool incoming) { | 148 cricket::Session* cricket_session, bool incoming) { |
149 DCHECK(CalledOnValidThread()); | 149 DCHECK(CalledOnValidThread()); |
150 | 150 |
151 // Allow local connections. | 151 // Allow local connections. |
152 cricket_session->set_allow_local_ips(true); | 152 cricket_session->set_allow_local_ips(true); |
153 | 153 |
154 if (incoming) { | 154 if (incoming) { |
155 JingleSession* jingle_session = | 155 JingleSession* jingle_session = |
156 new JingleSession(this, cricket_session, NULL); | 156 new JingleSession(this, cricket_session, scoped_ptr<Authenticator>()); |
157 sessions_.push_back(jingle_session); | 157 sessions_.push_back(jingle_session); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 void JingleSessionManager::OnSessionDestroy(cricket::Session* cricket_session) { | 161 void JingleSessionManager::OnSessionDestroy(cricket::Session* cricket_session) { |
162 DCHECK(CalledOnValidThread()); | 162 DCHECK(CalledOnValidThread()); |
163 | 163 |
164 std::list<JingleSession*>::iterator it; | 164 std::list<JingleSession*>::iterator it; |
165 for (it = sessions_.begin(); it != sessions_.end(); ++it) { | 165 for (it = sessions_.begin(); it != sessions_.end(); ++it) { |
166 if ((*it)->HasSession(cricket_session)) { | 166 if ((*it)->HasSession(cricket_session)) { |
(...skipping 24 matching lines...) Expand all Loading... | |
191 | 191 |
192 // Reject connection if we are closed. | 192 // Reject connection if we are closed. |
193 if (closed_) | 193 if (closed_) |
194 return SessionManager::DECLINE; | 194 return SessionManager::DECLINE; |
195 | 195 |
196 IncomingSessionResponse response = SessionManager::DECLINE; | 196 IncomingSessionResponse response = SessionManager::DECLINE; |
197 listener_->OnIncomingSession(jingle_session, &response); | 197 listener_->OnIncomingSession(jingle_session, &response); |
198 return response; | 198 return response; |
199 } | 199 } |
200 | 200 |
201 Authenticator* JingleSessionManager::CreateAuthenticator( | 201 scoped_ptr<Authenticator> JingleSessionManager::CreateAuthenticator( |
202 const std::string& jid, const buzz::XmlElement* auth_message) { | 202 const std::string& jid, const buzz::XmlElement* auth_message) { |
203 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
204 | 204 |
205 if (!authenticator_factory_.get()) | 205 if (!authenticator_factory_.get()) |
206 return NULL; | 206 return scoped_ptr<Authenticator>(NULL); |
207 return authenticator_factory_->CreateAuthenticator(jid, auth_message); | 207 return authenticator_factory_->CreateAuthenticator(jid, auth_message); |
208 } | 208 } |
209 | 209 |
210 void JingleSessionManager::SessionDestroyed(JingleSession* jingle_session) { | 210 void JingleSessionManager::SessionDestroyed(JingleSession* jingle_session) { |
211 std::list<JingleSession*>::iterator it = | 211 std::list<JingleSession*>::iterator it = |
212 std::find(sessions_.begin(), sessions_.end(), jingle_session); | 212 std::find(sessions_.begin(), sessions_.end(), jingle_session); |
213 CHECK(it != sessions_.end()); | 213 CHECK(it != sessions_.end()); |
214 cricket::Session* cricket_session = jingle_session->ReleaseSession(); | 214 cricket::Session* cricket_session = jingle_session->ReleaseSession(); |
215 cricket_session_manager_->DestroySession(cricket_session); | 215 cricket_session_manager_->DestroySession(cricket_session); |
216 sessions_.erase(it); | 216 sessions_.erase(it); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 cricket::WriteError* error) { | 261 cricket::WriteError* error) { |
262 const ContentDescription* desc = | 262 const ContentDescription* desc = |
263 static_cast<const ContentDescription*>(content); | 263 static_cast<const ContentDescription*>(content); |
264 | 264 |
265 *elem = desc->ToXml(); | 265 *elem = desc->ToXml(); |
266 return true; | 266 return true; |
267 } | 267 } |
268 | 268 |
269 } // namespace protocol | 269 } // namespace protocol |
270 } // namespace remoting | 270 } // namespace remoting |
OLD | NEW |