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

Unified Diff: remoting/protocol/jingle_session.cc

Issue 2586403003: [Chromoting] Add SessionPlugin in JingleSession (Closed)
Patch Set: Resolve review comments Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/jingle_session.cc
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc
index f421b025e6716af41571af663bc24fefa1568f53..746a4e2cb032d12f6d72acaf9ae29dc019c7cf95 100644
--- a/remoting/protocol/jingle_session.cc
+++ b/remoting/protocol/jingle_session.cc
@@ -7,6 +7,7 @@
#include <stdint.h>
#include <limits>
+#include <memory>
#include <utility>
#include "base/bind.h"
@@ -21,6 +22,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"
@@ -249,6 +251,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 +325,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 +390,15 @@ void JingleSession::Close(protocol::ErrorCode error) {
}
}
+void JingleSession::Attach(std::unique_ptr<SessionPlugin> plugin) {
+ DCHECK(plugin);
+ plugins_.push_back(std::move(plugin));
+}
+
void JingleSession::SendMessage(std::unique_ptr<JingleMessage> message) {
DCHECK(thread_checker_.CalledOnValidThread());
+ ExecutePluginsOnOutgoingMessage(message.get());
std::unique_ptr<buzz::XmlElement> stanza = message->ToXml();
stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId());
@@ -482,6 +492,8 @@ void JingleSession::OnTransportInfoResponse(IqRequest* request,
void JingleSession::OnIncomingMessage(const std::string& id,
std::unique_ptr<JingleMessage> message,
const ReplyCallback& reply_callback) {
+ 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.
+ 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 +759,20 @@ bool JingleSession::is_session_active() {
state_ == AUTHENTICATING || state_ == AUTHENTICATED;
}
+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
+ const JingleMessage& message) {
+ for (const auto& plugin : plugins_) {
+ plugin->OnIncoming(state_, message.action, message.attachments.get());
+ }
+}
+
+void JingleSession::ExecutePluginsOnOutgoingMessage(JingleMessage* message) {
+ DCHECK(message);
+ for (const auto& plugin : plugins_) {
+ message->AttachAttachment(plugin->OnOutgoing(state_, message->action));
+ }
+}
+
std::string JingleSession::GetNextOutgoingId() {
return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_);
}

Powered by Google App Engine
This is Rietveld 408576698