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

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

Issue 2417913002: Process incoming IQs in the same order that they were sent. (Closed)
Patch Set: Reviewer's feedback Created 4 years, 2 months 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_manager.h" 5 #include "remoting/protocol/jingle_session_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "remoting/protocol/authenticator.h" 10 #include "remoting/protocol/authenticator.h"
11 #include "remoting/protocol/content_description.h" 11 #include "remoting/protocol/content_description.h"
12 #include "remoting/protocol/jingle_messages.h" 12 #include "remoting/protocol/jingle_messages.h"
13 #include "remoting/protocol/jingle_session.h" 13 #include "remoting/protocol/jingle_session.h"
14 #include "remoting/protocol/transport.h" 14 #include "remoting/protocol/transport.h"
15 #include "remoting/signaling/iq_sender.h" 15 #include "remoting/signaling/iq_sender.h"
16 #include "remoting/signaling/signal_strategy.h" 16 #include "remoting/signaling/signal_strategy.h"
17 #include "third_party/webrtc/base/socketaddress.h" 17 #include "third_party/webrtc/base/socketaddress.h"
18 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 18 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
19 #include "third_party/webrtc/libjingle/xmpp/constants.h"
19 20
20 using buzz::QName; 21 using buzz::QName;
21 22
22 namespace remoting { 23 namespace remoting {
23 namespace protocol { 24 namespace protocol {
24 25
25 JingleSessionManager::JingleSessionManager(SignalStrategy* signal_strategy) 26 JingleSessionManager::JingleSessionManager(SignalStrategy* signal_strategy)
26 : signal_strategy_(signal_strategy), 27 : signal_strategy_(signal_strategy),
27 protocol_config_(CandidateSessionConfig::CreateDefault()), 28 protocol_config_(CandidateSessionConfig::CreateDefault()),
28 iq_sender_(new IqSender(signal_strategy_)) { 29 iq_sender_(new IqSender(signal_strategy_)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 61 }
61 62
62 void JingleSessionManager::OnSignalStrategyStateChange( 63 void JingleSessionManager::OnSignalStrategyStateChange(
63 SignalStrategy::State state) {} 64 SignalStrategy::State state) {}
64 65
65 bool JingleSessionManager::OnSignalStrategyIncomingStanza( 66 bool JingleSessionManager::OnSignalStrategyIncomingStanza(
66 const buzz::XmlElement* stanza) { 67 const buzz::XmlElement* stanza) {
67 if (!JingleMessage::IsJingleMessage(stanza)) 68 if (!JingleMessage::IsJingleMessage(stanza))
68 return false; 69 return false;
69 70
71 std::unique_ptr<buzz::XmlElement> stanza_copy(new buzz::XmlElement(*stanza));
70 std::unique_ptr<JingleMessage> message(new JingleMessage()); 72 std::unique_ptr<JingleMessage> message(new JingleMessage());
71 std::string error; 73 std::string error;
72 if (!message->ParseXml(stanza, &error)) { 74 if (!message->ParseXml(stanza, &error)) {
73 SendReply(stanza, JingleMessageReply::BAD_REQUEST); 75 SendReply(std::move(stanza_copy), JingleMessageReply::BAD_REQUEST);
74 return true; 76 return true;
75 } 77 }
76 78
77 if (message->action == JingleMessage::SESSION_INITIATE) { 79 if (message->action == JingleMessage::SESSION_INITIATE) {
78 // Description must be present in session-initiate messages. 80 // Description must be present in session-initiate messages.
79 DCHECK(message->description.get()); 81 DCHECK(message->description.get());
80 82
81 SendReply(stanza, JingleMessageReply::NONE); 83 SendReply(std::move(stanza_copy), JingleMessageReply::NONE);
82 84
83 std::unique_ptr<Authenticator> authenticator = 85 std::unique_ptr<Authenticator> authenticator =
84 authenticator_factory_->CreateAuthenticator( 86 authenticator_factory_->CreateAuthenticator(
85 signal_strategy_->GetLocalJid(), message->from.id()); 87 signal_strategy_->GetLocalJid(), message->from.id());
86 88
87 JingleSession* session = new JingleSession(this); 89 JingleSession* session = new JingleSession(this);
88 session->InitializeIncomingConnection(*message, 90 session->InitializeIncomingConnection(*message,
89 std::move(authenticator)); 91 std::move(authenticator));
90 sessions_[session->session_id_] = session; 92 sessions_[session->session_id_] = session;
91 93
(...skipping 29 matching lines...) Expand all
121 session->Close(error); 123 session->Close(error);
122 delete session; 124 delete session;
123 DCHECK(sessions_.find(message->sid) == sessions_.end()); 125 DCHECK(sessions_.find(message->sid) == sessions_.end());
124 } 126 }
125 127
126 return true; 128 return true;
127 } 129 }
128 130
129 SessionsMap::iterator it = sessions_.find(message->sid); 131 SessionsMap::iterator it = sessions_.find(message->sid);
130 if (it == sessions_.end()) { 132 if (it == sessions_.end()) {
131 SendReply(stanza, JingleMessageReply::INVALID_SID); 133 SendReply(std::move(stanza_copy), JingleMessageReply::INVALID_SID);
132 return true; 134 return true;
133 } 135 }
134 136
135 it->second->OnIncomingMessage(std::move(message), base::Bind( 137 it->second->OnIncomingMessage(
136 &JingleSessionManager::SendReply, base::Unretained(this), stanza)); 138 stanza->Attr(buzz::QN_ID), std::move(message),
139 base::Bind(&JingleSessionManager::SendReply, base::Unretained(this),
140 base::Passed(std::move(stanza_copy))));
137 return true; 141 return true;
138 } 142 }
139 143
140 void JingleSessionManager::SendReply(const buzz::XmlElement* original_stanza, 144 void JingleSessionManager::SendReply(
141 JingleMessageReply::ErrorType error) { 145 std::unique_ptr<buzz::XmlElement> original_stanza,
146 JingleMessageReply::ErrorType error) {
142 signal_strategy_->SendStanza( 147 signal_strategy_->SendStanza(
143 JingleMessageReply(error).ToXml(original_stanza)); 148 JingleMessageReply(error).ToXml(original_stanza.get()));
144 } 149 }
145 150
146 void JingleSessionManager::SessionDestroyed(JingleSession* session) { 151 void JingleSessionManager::SessionDestroyed(JingleSession* session) {
147 sessions_.erase(session->session_id_); 152 sessions_.erase(session->session_id_);
148 } 153 }
149 154
150 } // namespace protocol 155 } // namespace protocol
151 } // namespace remoting 156 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698