Chromium Code Reviews| Index: remoting/protocol/jingle_session.cc |
| diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc |
| index f421b025e6716af41571af663bc24fefa1568f53..c0baae64c4569432d9470b2f1363d9862d294ed0 100644 |
| --- a/remoting/protocol/jingle_session.cc |
| +++ b/remoting/protocol/jingle_session.cc |
| @@ -7,9 +7,11 @@ |
| #include <stdint.h> |
| #include <limits> |
| +#include <memory> |
| #include <utility> |
| #include "base/bind.h" |
| +#include "base/callback.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string_split.h" |
| @@ -21,6 +23,7 @@ |
| #include "remoting/protocol/jingle_messages.h" |
| #include "remoting/protocol/jingle_session_manager.h" |
| #include "remoting/protocol/session_config.h" |
| +#include "remoting/protocol/session_plugin.h" |
| #include "remoting/protocol/transport.h" |
| #include "remoting/signaling/iq_sender.h" |
| #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| @@ -208,14 +211,11 @@ void JingleSession::StartConnection( |
| session_id_ = base::Uint64ToString( |
| base::RandGenerator(std::numeric_limits<uint64_t>::max())); |
| - // Send session-initiate message. |
| - std::unique_ptr<JingleMessage> message(new JingleMessage( |
| - peer_address_, JingleMessage::SESSION_INITIATE, session_id_)); |
| - message->initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| - message->description.reset(new ContentDescription( |
| - session_manager_->protocol_config_->Clone(), |
| - authenticator_->GetNextMessage())); |
| - SendMessage(std::move(message)); |
| + // Delay sending session-initiate message to ensure SessionPlugin can be |
| + // attached before the message. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + base::Bind(&JingleSession::SendSessionInitiateMessage, |
| + weak_factory_.GetWeakPtr())); |
| SetState(CONNECTING); |
| } |
| @@ -249,6 +249,7 @@ void JingleSession::AcceptIncomingConnection( |
| const JingleMessage& initiate_message) { |
| DCHECK(config_); |
| + ExecutePluginsOnIncomingMessage(initiate_message); |
| // Process the first authentication message. |
| const buzz::XmlElement* first_auth_message = |
| initiate_message.description->authenticator_message(); |
| @@ -322,6 +323,7 @@ void JingleSession::SendTransportInfo( |
| std::unique_ptr<JingleMessage> message(new JingleMessage( |
| peer_address_, JingleMessage::TRANSPORT_INFO, session_id_)); |
| message->transport_info = std::move(transport_info); |
| + ExecutePluginsOnOutgoingMessage(message.get()); |
| std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); |
| stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); |
| @@ -386,9 +388,15 @@ void JingleSession::Close(protocol::ErrorCode error) { |
| } |
| } |
| +void JingleSession::AddPlugin(SessionPlugin* plugin) { |
| + DCHECK(plugin); |
| + plugins_.push_back(plugin); |
| +} |
| + |
| void JingleSession::SendMessage(std::unique_ptr<JingleMessage> message) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + ExecutePluginsOnOutgoingMessage(message.get()); |
|
Sergey Ulanov
2016/12/27 22:05:18
When the host accepts session-initiate message fro
Hzj_jie
2016/12/27 23:21:08
I see. Thank you for the explanation. I exclude pl
|
| std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); |
| stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); |
| @@ -482,6 +490,7 @@ void JingleSession::OnTransportInfoResponse(IqRequest* request, |
| void JingleSession::OnIncomingMessage(const std::string& id, |
| std::unique_ptr<JingleMessage> message, |
| const ReplyCallback& reply_callback) { |
| + ExecutePluginsOnIncomingMessage(*message); |
| std::vector<PendingMessage> ordered = message_queue_->OnIncomingMessage( |
| id, PendingMessage{std::move(message), reply_callback}); |
| base::WeakPtr<JingleSession> self = weak_factory_.GetWeakPtr(); |
| @@ -747,6 +756,35 @@ bool JingleSession::is_session_active() { |
| state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| } |
| +void JingleSession::ExecutePluginsOnIncomingMessage( |
| + const JingleMessage& message) { |
| + if (message.attachments) { |
| + for (const auto& plugin : plugins_) { |
| + plugin->OnIncomingMessage(state_, *(message.attachments)); |
| + } |
| + } |
| +} |
| + |
| +void JingleSession::ExecutePluginsOnOutgoingMessage(JingleMessage* message) { |
| + DCHECK(message); |
| + for (const auto& plugin : plugins_) { |
| + std::unique_ptr<XmlElement> attachment = plugin->GetNextMessage(state_); |
| + if (attachment) { |
| + message->AddAttachment(std::move(attachment)); |
| + } |
| + } |
| +} |
| + |
| +void JingleSession::SendSessionInitiateMessage() { |
| + std::unique_ptr<JingleMessage> message(new JingleMessage( |
| + peer_address_, JingleMessage::SESSION_INITIATE, session_id_)); |
| + message->initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| + message->description.reset(new ContentDescription( |
| + session_manager_->protocol_config_->Clone(), |
| + authenticator_->GetNextMessage())); |
| + SendMessage(std::move(message)); |
| +} |
| + |
| std::string JingleSession::GetNextOutgoingId() { |
| return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); |
| } |