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 <memory> | |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "remoting/base/constants.h" | 19 #include "remoting/base/constants.h" |
19 #include "remoting/protocol/authenticator.h" | 20 #include "remoting/protocol/authenticator.h" |
20 #include "remoting/protocol/content_description.h" | 21 #include "remoting/protocol/content_description.h" |
21 #include "remoting/protocol/jingle_messages.h" | 22 #include "remoting/protocol/jingle_messages.h" |
22 #include "remoting/protocol/jingle_session_manager.h" | 23 #include "remoting/protocol/jingle_session_manager.h" |
23 #include "remoting/protocol/session_config.h" | 24 #include "remoting/protocol/session_config.h" |
25 #include "remoting/protocol/session_plugin.h" | |
24 #include "remoting/protocol/transport.h" | 26 #include "remoting/protocol/transport.h" |
25 #include "remoting/signaling/iq_sender.h" | 27 #include "remoting/signaling/iq_sender.h" |
26 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 28 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
27 #include "third_party/webrtc/libjingle/xmpp/constants.h" | 29 #include "third_party/webrtc/libjingle/xmpp/constants.h" |
28 #include "third_party/webrtc/p2p/base/candidate.h" | 30 #include "third_party/webrtc/p2p/base/candidate.h" |
29 | 31 |
30 using buzz::XmlElement; | 32 using buzz::XmlElement; |
31 | 33 |
32 namespace remoting { | 34 namespace remoting { |
33 namespace protocol { | 35 namespace protocol { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 << " because no compatible configuration has been found."; | 244 << " because no compatible configuration has been found."; |
243 Close(INCOMPATIBLE_PROTOCOL); | 245 Close(INCOMPATIBLE_PROTOCOL); |
244 return; | 246 return; |
245 } | 247 } |
246 } | 248 } |
247 | 249 |
248 void JingleSession::AcceptIncomingConnection( | 250 void JingleSession::AcceptIncomingConnection( |
249 const JingleMessage& initiate_message) { | 251 const JingleMessage& initiate_message) { |
250 DCHECK(config_); | 252 DCHECK(config_); |
251 | 253 |
254 ExecutePluginsOnIncomingMessage(initiate_message); | |
252 // Process the first authentication message. | 255 // Process the first authentication message. |
253 const buzz::XmlElement* first_auth_message = | 256 const buzz::XmlElement* first_auth_message = |
254 initiate_message.description->authenticator_message(); | 257 initiate_message.description->authenticator_message(); |
255 | 258 |
256 if (!first_auth_message) { | 259 if (!first_auth_message) { |
257 Close(INCOMPATIBLE_PROTOCOL); | 260 Close(INCOMPATIBLE_PROTOCOL); |
258 return; | 261 return; |
259 } | 262 } |
260 | 263 |
261 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); | 264 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 } | 318 } |
316 | 319 |
317 void JingleSession::SendTransportInfo( | 320 void JingleSession::SendTransportInfo( |
318 std::unique_ptr<buzz::XmlElement> transport_info) { | 321 std::unique_ptr<buzz::XmlElement> transport_info) { |
319 DCHECK(thread_checker_.CalledOnValidThread()); | 322 DCHECK(thread_checker_.CalledOnValidThread()); |
320 DCHECK_EQ(state_, AUTHENTICATED); | 323 DCHECK_EQ(state_, AUTHENTICATED); |
321 | 324 |
322 std::unique_ptr<JingleMessage> message(new JingleMessage( | 325 std::unique_ptr<JingleMessage> message(new JingleMessage( |
323 peer_address_, JingleMessage::TRANSPORT_INFO, session_id_)); | 326 peer_address_, JingleMessage::TRANSPORT_INFO, session_id_)); |
324 message->transport_info = std::move(transport_info); | 327 message->transport_info = std::move(transport_info); |
328 ExecutePluginsOnOutgoingMessage(message.get()); | |
325 | 329 |
326 std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); | 330 std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); |
327 stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); | 331 stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); |
328 | 332 |
329 auto request = session_manager_->iq_sender()->SendIq( | 333 auto request = session_manager_->iq_sender()->SendIq( |
330 std::move(stanza), base::Bind(&JingleSession::OnTransportInfoResponse, | 334 std::move(stanza), base::Bind(&JingleSession::OnTransportInfoResponse, |
331 base::Unretained(this))); | 335 base::Unretained(this))); |
332 if (request) { | 336 if (request) { |
333 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); | 337 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); |
334 transport_info_requests_.push_back(std::move(request)); | 338 transport_info_requests_.push_back(std::move(request)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 383 |
380 if (state_ != FAILED && state_ != CLOSED) { | 384 if (state_ != FAILED && state_ != CLOSED) { |
381 if (error != OK) { | 385 if (error != OK) { |
382 SetState(FAILED); | 386 SetState(FAILED); |
383 } else { | 387 } else { |
384 SetState(CLOSED); | 388 SetState(CLOSED); |
385 } | 389 } |
386 } | 390 } |
387 } | 391 } |
388 | 392 |
393 void JingleSession::Attach(std::unique_ptr<SessionPlugin> plugin) { | |
394 DCHECK(plugin); | |
395 plugins_.push_back(std::move(plugin)); | |
396 } | |
397 | |
389 void JingleSession::SendMessage(std::unique_ptr<JingleMessage> message) { | 398 void JingleSession::SendMessage(std::unique_ptr<JingleMessage> message) { |
390 DCHECK(thread_checker_.CalledOnValidThread()); | 399 DCHECK(thread_checker_.CalledOnValidThread()); |
391 | 400 |
401 ExecutePluginsOnOutgoingMessage(message.get()); | |
392 std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); | 402 std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); |
393 stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); | 403 stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); |
394 | 404 |
395 auto request = session_manager_->iq_sender()->SendIq( | 405 auto request = session_manager_->iq_sender()->SendIq( |
396 std::move(stanza), base::Bind(&JingleSession::OnMessageResponse, | 406 std::move(stanza), base::Bind(&JingleSession::OnMessageResponse, |
397 base::Unretained(this), message->action)); | 407 base::Unretained(this), message->action)); |
398 | 408 |
399 int timeout = kDefaultMessageTimeout; | 409 int timeout = kDefaultMessageTimeout; |
400 if (message->action == JingleMessage::SESSION_INITIATE || | 410 if (message->action == JingleMessage::SESSION_INITIATE || |
401 message->action == JingleMessage::SESSION_ACCEPT) { | 411 message->action == JingleMessage::SESSION_ACCEPT) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 if (type != "result") { | 485 if (type != "result") { |
476 LOG(ERROR) << "Received error in response to transport-info message: \"" | 486 LOG(ERROR) << "Received error in response to transport-info message: \"" |
477 << response->Str() << "\". Terminating the session."; | 487 << response->Str() << "\". Terminating the session."; |
478 Close(PEER_IS_OFFLINE); | 488 Close(PEER_IS_OFFLINE); |
479 } | 489 } |
480 } | 490 } |
481 | 491 |
482 void JingleSession::OnIncomingMessage(const std::string& id, | 492 void JingleSession::OnIncomingMessage(const std::string& id, |
483 std::unique_ptr<JingleMessage> message, | 493 std::unique_ptr<JingleMessage> message, |
484 const ReplyCallback& reply_callback) { | 494 const ReplyCallback& reply_callback) { |
495 DCHECK(message); | |
Sergey Ulanov
2016/12/21 01:38:34
Don't really need this. unique_ptr<>::operator* ca
Hzj_jie
2016/12/22 00:27:10
Done.
| |
496 ExecutePluginsOnIncomingMessage(*message); | |
485 std::vector<PendingMessage> ordered = message_queue_->OnIncomingMessage( | 497 std::vector<PendingMessage> ordered = message_queue_->OnIncomingMessage( |
486 id, PendingMessage{std::move(message), reply_callback}); | 498 id, PendingMessage{std::move(message), reply_callback}); |
487 base::WeakPtr<JingleSession> self = weak_factory_.GetWeakPtr(); | 499 base::WeakPtr<JingleSession> self = weak_factory_.GetWeakPtr(); |
488 for (auto& message : ordered) { | 500 for (auto& message : ordered) { |
489 ProcessIncomingMessage(std::move(message.message), message.reply_callback); | 501 ProcessIncomingMessage(std::move(message.message), message.reply_callback); |
490 if (!self) | 502 if (!self) |
491 return; | 503 return; |
492 } | 504 } |
493 } | 505 } |
494 | 506 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 if (event_handler_) | 752 if (event_handler_) |
741 event_handler_->OnSessionStateChange(new_state); | 753 event_handler_->OnSessionStateChange(new_state); |
742 } | 754 } |
743 } | 755 } |
744 | 756 |
745 bool JingleSession::is_session_active() { | 757 bool JingleSession::is_session_active() { |
746 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || | 758 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || |
747 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 759 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
748 } | 760 } |
749 | 761 |
762 void JingleSession::ExecutePluginsOnIncomingMessage( | |
Sergey Ulanov
2016/12/21 01:38:34
I don't think you really need this function. It's
Hzj_jie
2016/12/22 00:27:10
Not really, this function is called by both Accept
| |
763 const JingleMessage& message) { | |
764 for (const auto& plugin : plugins_) { | |
765 plugin->OnIncoming(state_, message.action, message.attachments.get()); | |
766 } | |
767 } | |
768 | |
769 void JingleSession::ExecutePluginsOnOutgoingMessage(JingleMessage* message) { | |
770 DCHECK(message); | |
771 for (const auto& plugin : plugins_) { | |
772 message->AttachAttachment(plugin->OnOutgoing(state_, message->action)); | |
773 } | |
774 } | |
775 | |
750 std::string JingleSession::GetNextOutgoingId() { | 776 std::string JingleSession::GetNextOutgoingId() { |
751 return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); | 777 return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); |
752 } | 778 } |
753 | 779 |
754 } // namespace protocol | 780 } // namespace protocol |
755 } // namespace remoting | 781 } // namespace remoting |
OLD | NEW |