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.h" | 5 #include "remoting/protocol/jingle_session.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 JingleSession::JingleSession(JingleSessionManager* session_manager) | 68 JingleSession::JingleSession(JingleSessionManager* session_manager) |
69 : session_manager_(session_manager), | 69 : session_manager_(session_manager), |
70 event_handler_(nullptr), | 70 event_handler_(nullptr), |
71 state_(INITIALIZING), | 71 state_(INITIALIZING), |
72 error_(OK), | 72 error_(OK), |
73 weak_factory_(this) { | 73 weak_factory_(this) { |
74 } | 74 } |
75 | 75 |
76 JingleSession::~JingleSession() { | 76 JingleSession::~JingleSession() { |
77 base::STLDeleteContainerPointers(pending_requests_.begin(), | |
78 pending_requests_.end()); | |
79 base::STLDeleteContainerPointers(transport_info_requests_.begin(), | |
80 transport_info_requests_.end()); | |
81 | |
82 session_manager_->SessionDestroyed(this); | 77 session_manager_->SessionDestroyed(this); |
83 } | 78 } |
84 | 79 |
85 void JingleSession::SetEventHandler(Session::EventHandler* event_handler) { | 80 void JingleSession::SetEventHandler(Session::EventHandler* event_handler) { |
86 DCHECK(thread_checker_.CalledOnValidThread()); | 81 DCHECK(thread_checker_.CalledOnValidThread()); |
87 DCHECK(event_handler); | 82 DCHECK(event_handler); |
88 event_handler_ = event_handler; | 83 event_handler_ = event_handler; |
89 } | 84 } |
90 | 85 |
91 ErrorCode JingleSession::error() { | 86 ErrorCode JingleSession::error() { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 218 |
224 JingleMessage message(peer_address_, JingleMessage::TRANSPORT_INFO, | 219 JingleMessage message(peer_address_, JingleMessage::TRANSPORT_INFO, |
225 session_id_); | 220 session_id_); |
226 message.transport_info = std::move(transport_info); | 221 message.transport_info = std::move(transport_info); |
227 | 222 |
228 std::unique_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( | 223 std::unique_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( |
229 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, | 224 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, |
230 base::Unretained(this))); | 225 base::Unretained(this))); |
231 if (request) { | 226 if (request) { |
232 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); | 227 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); |
233 transport_info_requests_.push_back(request.release()); | 228 transport_info_requests_.push_back(std::move(request)); |
234 } else { | 229 } else { |
235 LOG(ERROR) << "Failed to send a transport-info message"; | 230 LOG(ERROR) << "Failed to send a transport-info message"; |
236 } | 231 } |
237 } | 232 } |
238 | 233 |
239 void JingleSession::Close(protocol::ErrorCode error) { | 234 void JingleSession::Close(protocol::ErrorCode error) { |
240 DCHECK(thread_checker_.CalledOnValidThread()); | 235 DCHECK(thread_checker_.CalledOnValidThread()); |
241 | 236 |
242 if (is_session_active()) { | 237 if (is_session_active()) { |
243 // Send session-terminate message with the appropriate error code. | 238 // Send session-terminate message with the appropriate error code. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 message.ToXml(), base::Bind(&JingleSession::OnMessageResponse, | 287 message.ToXml(), base::Bind(&JingleSession::OnMessageResponse, |
293 base::Unretained(this), message.action)); | 288 base::Unretained(this), message.action)); |
294 | 289 |
295 int timeout = kDefaultMessageTimeout; | 290 int timeout = kDefaultMessageTimeout; |
296 if (message.action == JingleMessage::SESSION_INITIATE || | 291 if (message.action == JingleMessage::SESSION_INITIATE || |
297 message.action == JingleMessage::SESSION_ACCEPT) { | 292 message.action == JingleMessage::SESSION_ACCEPT) { |
298 timeout = kSessionInitiateAndAcceptTimeout; | 293 timeout = kSessionInitiateAndAcceptTimeout; |
299 } | 294 } |
300 if (request) { | 295 if (request) { |
301 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); | 296 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); |
302 pending_requests_.insert(request.release()); | 297 pending_requests_.insert(std::move(request)); |
303 } else { | 298 } else { |
304 LOG(ERROR) << "Failed to send a " | 299 LOG(ERROR) << "Failed to send a " |
305 << JingleMessage::GetActionName(message.action) << " message"; | 300 << JingleMessage::GetActionName(message.action) << " message"; |
306 } | 301 } |
307 } | 302 } |
308 | 303 |
309 void JingleSession::OnMessageResponse( | 304 void JingleSession::OnMessageResponse( |
310 JingleMessage::ActionType request_type, | 305 JingleMessage::ActionType request_type, |
311 IqRequest* request, | 306 IqRequest* request, |
312 const buzz::XmlElement* response) { | 307 const buzz::XmlElement* response) { |
313 DCHECK(thread_checker_.CalledOnValidThread()); | 308 DCHECK(thread_checker_.CalledOnValidThread()); |
314 | 309 |
315 // Delete the request from the list of pending requests. | 310 // Delete the request from the list of pending requests. |
316 pending_requests_.erase(request); | 311 pending_requests_.erase( |
317 delete request; | 312 std::find_if(pending_requests_.begin(), pending_requests_.end(), |
| 313 [request](const std::unique_ptr<IqRequest>& ptr) { |
| 314 return ptr.get() == request; |
| 315 })); |
318 | 316 |
319 // Ignore all responses after session was closed. | 317 // Ignore all responses after session was closed. |
320 if (state_ == CLOSED || state_ == FAILED) | 318 if (state_ == CLOSED || state_ == FAILED) |
321 return; | 319 return; |
322 | 320 |
323 std::string type_str = JingleMessage::GetActionName(request_type); | 321 std::string type_str = JingleMessage::GetActionName(request_type); |
324 | 322 |
325 // |response| will be nullptr if the request timed out. | 323 // |response| will be nullptr if the request timed out. |
326 if (!response) { | 324 if (!response) { |
327 LOG(ERROR) << type_str << " request timed out."; | 325 LOG(ERROR) << type_str << " request timed out."; |
(...skipping 14 matching lines...) Expand all Loading... |
342 } | 340 } |
343 } | 341 } |
344 | 342 |
345 void JingleSession::OnTransportInfoResponse(IqRequest* request, | 343 void JingleSession::OnTransportInfoResponse(IqRequest* request, |
346 const buzz::XmlElement* response) { | 344 const buzz::XmlElement* response) { |
347 DCHECK(thread_checker_.CalledOnValidThread()); | 345 DCHECK(thread_checker_.CalledOnValidThread()); |
348 DCHECK(!transport_info_requests_.empty()); | 346 DCHECK(!transport_info_requests_.empty()); |
349 | 347 |
350 // Consider transport-info requests sent before this one lost and delete | 348 // Consider transport-info requests sent before this one lost and delete |
351 // corresponding IqRequest objects. | 349 // corresponding IqRequest objects. |
352 while (transport_info_requests_.front() != request) { | 350 while (transport_info_requests_.front().get() != request) { |
353 delete transport_info_requests_.front(); | |
354 transport_info_requests_.pop_front(); | 351 transport_info_requests_.pop_front(); |
355 } | 352 } |
356 | 353 |
357 // Delete the |request| itself. | 354 // Delete the |request| itself. |
358 DCHECK_EQ(request, transport_info_requests_.front()); | 355 DCHECK_EQ(request, transport_info_requests_.front().get()); |
359 delete request; | |
360 transport_info_requests_.pop_front(); | 356 transport_info_requests_.pop_front(); |
361 | 357 |
362 // Ignore transport-info timeouts. | 358 // Ignore transport-info timeouts. |
363 if (!response) { | 359 if (!response) { |
364 LOG(ERROR) << "transport-info request has timed out."; | 360 LOG(ERROR) << "transport-info request has timed out."; |
365 return; | 361 return; |
366 } | 362 } |
367 | 363 |
368 const std::string& type = response->Attr(buzz::QName(std::string(), "type")); | 364 const std::string& type = response->Attr(buzz::QName(std::string(), "type")); |
369 if (type != "result") { | 365 if (type != "result") { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 } | 604 } |
609 } | 605 } |
610 | 606 |
611 bool JingleSession::is_session_active() { | 607 bool JingleSession::is_session_active() { |
612 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || | 608 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || |
613 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 609 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
614 } | 610 } |
615 | 611 |
616 } // namespace protocol | 612 } // namespace protocol |
617 } // namespace remoting | 613 } // namespace remoting |
OLD | NEW |