Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: remoting/protocol/jingle_session.cc

Issue 1427003009: Implement WebrtcTransport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@transport_session.h
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h" 5 #include "remoting/protocol/jingle_session.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (state_ != FAILED && state_ != CLOSED) { 270 if (state_ != FAILED && state_ != CLOSED) {
271 if (error != OK) { 271 if (error != OK) {
272 SetState(FAILED); 272 SetState(FAILED);
273 } else { 273 } else {
274 SetState(CLOSED); 274 SetState(CLOSED);
275 } 275 }
276 } 276 }
277 } 277 }
278 278
279 void JingleSession::SendMessage(const JingleMessage& message) { 279 void JingleSession::SendMessage(const JingleMessage& message) {
280 DCHECK(CalledOnValidThread());
281
280 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( 282 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq(
281 message.ToXml(), 283 message.ToXml(),
282 base::Bind(&JingleSession::OnMessageResponse, 284 base::Bind(&JingleSession::OnMessageResponse,
283 base::Unretained(this), 285 base::Unretained(this),
284 message.action)); 286 message.action));
285 287
286 int timeout = kDefaultMessageTimeout; 288 int timeout = kDefaultMessageTimeout;
287 if (message.action == JingleMessage::SESSION_INITIATE || 289 if (message.action == JingleMessage::SESSION_INITIATE ||
288 message.action == JingleMessage::SESSION_ACCEPT) { 290 message.action == JingleMessage::SESSION_ACCEPT) {
289 timeout = kSessionInitiateAndAcceptTimeout; 291 timeout = kSessionInitiateAndAcceptTimeout;
290 } 292 }
291 if (request) { 293 if (request) {
292 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); 294 request->SetTimeout(base::TimeDelta::FromSeconds(timeout));
293 pending_requests_.insert(request.release()); 295 pending_requests_.insert(request.release());
294 } else { 296 } else {
295 LOG(ERROR) << "Failed to send a " 297 LOG(ERROR) << "Failed to send a "
296 << JingleMessage::GetActionName(message.action) << " message"; 298 << JingleMessage::GetActionName(message.action) << " message";
297 } 299 }
298 } 300 }
299 301
300 void JingleSession::OnMessageResponse( 302 void JingleSession::OnMessageResponse(
301 JingleMessage::ActionType request_type, 303 JingleMessage::ActionType request_type,
302 IqRequest* request, 304 IqRequest* request,
303 const buzz::XmlElement* response) { 305 const buzz::XmlElement* response) {
306 DCHECK(CalledOnValidThread());
307
304 // Delete the request from the list of pending requests. 308 // Delete the request from the list of pending requests.
305 pending_requests_.erase(request); 309 pending_requests_.erase(request);
306 delete request; 310 delete request;
307 311
308 // Ignore all responses after session was closed. 312 // Ignore all responses after session was closed.
309 if (state_ == CLOSED || state_ == FAILED) 313 if (state_ == CLOSED || state_ == FAILED)
310 return; 314 return;
311 315
312 std::string type_str = JingleMessage::GetActionName(request_type); 316 std::string type_str = JingleMessage::GetActionName(request_type);
313 317
(...skipping 12 matching lines...) Expand all
326 330
327 // TODO(sergeyu): There may be different reasons for error 331 // TODO(sergeyu): There may be different reasons for error
328 // here. Parse the response stanza to find failure reason. 332 // here. Parse the response stanza to find failure reason.
329 Close(PEER_IS_OFFLINE); 333 Close(PEER_IS_OFFLINE);
330 } 334 }
331 } 335 }
332 } 336 }
333 337
334 void JingleSession::OnOutgoingTransportInfo( 338 void JingleSession::OnOutgoingTransportInfo(
335 scoped_ptr<XmlElement> transport_info) { 339 scoped_ptr<XmlElement> transport_info) {
340 DCHECK(CalledOnValidThread());
341
336 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); 342 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_);
337 message.transport_info = transport_info.Pass(); 343 message.transport_info = transport_info.Pass();
338 344
339 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( 345 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq(
340 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, 346 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse,
341 base::Unretained(this))); 347 base::Unretained(this)));
342 if (request) { 348 if (request) {
343 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); 349 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout));
344 transport_info_requests_.push_back(request.release()); 350 transport_info_requests_.push_back(request.release());
345 } else { 351 } else {
346 LOG(ERROR) << "Failed to send a transport-info message"; 352 LOG(ERROR) << "Failed to send a transport-info message";
347 } 353 }
348 } 354 }
349 355
350 void JingleSession::OnTransportRouteChange(const std::string& channel_name, 356 void JingleSession::OnTransportRouteChange(const std::string& channel_name,
351 const TransportRoute& route) { 357 const TransportRoute& route) {
358 DCHECK(CalledOnValidThread());
359
352 event_handler_->OnSessionRouteChange(channel_name, route); 360 event_handler_->OnSessionRouteChange(channel_name, route);
353 } 361 }
354 362
363 void JingleSession::OnTransportConnected() {
364 DCHECK(CalledOnValidThread());
365
366 // TODO(sergeyu): Add Session::State value to indicate that the transport has
367 // been connected.
368 }
369
355 void JingleSession::OnTransportError(ErrorCode error) { 370 void JingleSession::OnTransportError(ErrorCode error) {
371 DCHECK(CalledOnValidThread());
372
356 Close(error); 373 Close(error);
357 } 374 }
358 375
359 void JingleSession::OnTransportInfoResponse(IqRequest* request, 376 void JingleSession::OnTransportInfoResponse(IqRequest* request,
360 const buzz::XmlElement* response) { 377 const buzz::XmlElement* response) {
378 DCHECK(CalledOnValidThread());
361 DCHECK(!transport_info_requests_.empty()); 379 DCHECK(!transport_info_requests_.empty());
362 380
363 // Consider transport-info requests sent before this one lost and delete 381 // Consider transport-info requests sent before this one lost and delete
364 // corresponding IqRequest objects. 382 // corresponding IqRequest objects.
365 while (transport_info_requests_.front() != request) { 383 while (transport_info_requests_.front() != request) {
366 delete transport_info_requests_.front(); 384 delete transport_info_requests_.front();
367 transport_info_requests_.pop_front(); 385 transport_info_requests_.pop_front();
368 } 386 }
369 387
370 // Delete the |request| itself. 388 // Delete the |request| itself.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 631 }
614 } 632 }
615 633
616 bool JingleSession::is_session_active() { 634 bool JingleSession::is_session_active() {
617 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || 635 return state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED ||
618 state_ == AUTHENTICATING || state_ == AUTHENTICATED; 636 state_ == AUTHENTICATING || state_ == AUTHENTICATED;
619 } 637 }
620 638
621 } // namespace protocol 639 } // namespace protocol
622 } // namespace remoting 640 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698