Chromium Code Reviews| 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 <memory> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 class JingleSession::OrderedMessageQueue { | 108 class JingleSession::OrderedMessageQueue { |
| 109 public: | 109 public: |
| 110 OrderedMessageQueue() {} | 110 OrderedMessageQueue() {} |
| 111 ~OrderedMessageQueue() {} | 111 ~OrderedMessageQueue() {} |
| 112 | 112 |
| 113 // Returns the list of messages ordered by their sequential IDs. | 113 // Returns the list of messages ordered by their sequential IDs. |
| 114 std::vector<PendingMessage> OnIncomingMessage( | 114 std::vector<PendingMessage> OnIncomingMessage( |
| 115 const std::string& id, | 115 const std::string& id, |
| 116 PendingMessage&& pending_message); | 116 PendingMessage&& pending_message); |
| 117 | 117 |
| 118 // Sets the initial ID of the session initiate message. | |
| 119 void setInitialId(const std::string& id); | |
|
Sergey Ulanov
2017/07/05 18:00:14
SetInitialiId() please
kelvinp
2017/07/05 22:29:40
Done.
| |
| 120 | |
| 118 private: | 121 private: |
| 119 // Implements an ordered list by using map with the |sequence_id| as the key, | 122 // Implements an ordered list by using map with the |sequence_id| as the key, |
| 120 // so that |queue_| is always sorted by |sequence_id|. | 123 // so that |queue_| is always sorted by |sequence_id|. |
| 121 std::map<int, PendingMessage> queue_; | 124 std::map<int, PendingMessage> queue_; |
| 122 | 125 |
| 123 int next_incoming_ = kAny; | 126 int next_incoming_ = kAny; |
| 124 | 127 |
| 125 DISALLOW_COPY_AND_ASSIGN(OrderedMessageQueue); | 128 DISALLOW_COPY_AND_ASSIGN(OrderedMessageQueue); |
| 126 }; | 129 }; |
| 127 | 130 |
| 131 void JingleSession::OrderedMessageQueue::setInitialId(const std::string& id) { | |
|
Sergey Ulanov
2017/07/05 18:00:14
Put this after OnIncomingMessage() so the order ma
kelvinp
2017/07/05 22:29:41
Done.
| |
| 132 int current = GetSequentialId(id); | |
| 133 if (current != kInvalid) | |
| 134 next_incoming_ = current + 1; | |
| 135 } | |
| 136 | |
| 128 std::vector<JingleSession::PendingMessage> | 137 std::vector<JingleSession::PendingMessage> |
| 129 JingleSession::OrderedMessageQueue::OnIncomingMessage( | 138 JingleSession::OrderedMessageQueue::OnIncomingMessage( |
| 130 const std::string& id, | 139 const std::string& id, |
| 131 JingleSession::PendingMessage&& message) { | 140 JingleSession::PendingMessage&& message) { |
| 132 std::vector<JingleSession::PendingMessage> result; | 141 std::vector<JingleSession::PendingMessage> result; |
| 133 int current = GetSequentialId(id); | 142 int current = GetSequentialId(id); |
| 134 // If there is no sequencing order encoded in the id, just return the | 143 // If there is no sequencing order encoded in the id, just return the |
| 135 // message. | 144 // message. |
| 136 if (current == kInvalid) { | 145 if (current == kInvalid) { |
| 137 result.push_back(std::move(message)); | 146 result.push_back(std::move(message)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 // Delay sending session-initiate message to ensure SessionPlugin can be | 226 // Delay sending session-initiate message to ensure SessionPlugin can be |
| 218 // attached before the message. | 227 // attached before the message. |
| 219 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 228 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 220 base::Bind(&JingleSession::SendSessionInitiateMessage, | 229 base::Bind(&JingleSession::SendSessionInitiateMessage, |
| 221 weak_factory_.GetWeakPtr())); | 230 weak_factory_.GetWeakPtr())); |
| 222 | 231 |
| 223 SetState(CONNECTING); | 232 SetState(CONNECTING); |
| 224 } | 233 } |
| 225 | 234 |
| 226 void JingleSession::InitializeIncomingConnection( | 235 void JingleSession::InitializeIncomingConnection( |
| 236 const std::string& id, | |
|
Sergey Ulanov
2017/07/05 18:00:14
call it message_id.
kelvinp
2017/07/05 22:29:40
Done.
| |
| 227 const JingleMessage& initiate_message, | 237 const JingleMessage& initiate_message, |
| 228 std::unique_ptr<Authenticator> authenticator) { | 238 std::unique_ptr<Authenticator> authenticator) { |
| 229 DCHECK(thread_checker_.CalledOnValidThread()); | 239 DCHECK(thread_checker_.CalledOnValidThread()); |
| 230 DCHECK(initiate_message.description.get()); | 240 DCHECK(initiate_message.description.get()); |
| 231 DCHECK(authenticator.get()); | 241 DCHECK(authenticator.get()); |
| 232 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); | 242 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); |
| 233 | 243 |
| 234 peer_address_ = initiate_message.from; | 244 peer_address_ = initiate_message.from; |
| 235 authenticator_ = std::move(authenticator); | 245 authenticator_ = std::move(authenticator); |
| 236 session_id_ = initiate_message.sid; | 246 session_id_ = initiate_message.sid; |
| 247 message_queue_->setInitialId(id); | |
| 237 | 248 |
| 238 SetState(ACCEPTING); | 249 SetState(ACCEPTING); |
| 239 | 250 |
| 240 config_ = | 251 config_ = |
| 241 SessionConfig::SelectCommon(initiate_message.description->config(), | 252 SessionConfig::SelectCommon(initiate_message.description->config(), |
| 242 session_manager_->protocol_config_.get()); | 253 session_manager_->protocol_config_.get()); |
| 243 if (!config_) { | 254 if (!config_) { |
| 244 LOG(WARNING) << "Rejecting connection from " << peer_address_.id() | 255 LOG(WARNING) << "Rejecting connection from " << peer_address_.id() |
| 245 << " because no compatible configuration has been found."; | 256 << " because no compatible configuration has been found."; |
| 246 Close(INCOMPATIBLE_PROTOCOL); | 257 Close(INCOMPATIBLE_PROTOCOL); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 authenticator_->GetNextMessage())); | 811 authenticator_->GetNextMessage())); |
| 801 SendMessage(std::move(message)); | 812 SendMessage(std::move(message)); |
| 802 } | 813 } |
| 803 | 814 |
| 804 std::string JingleSession::GetNextOutgoingId() { | 815 std::string JingleSession::GetNextOutgoingId() { |
| 805 return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); | 816 return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); |
| 806 } | 817 } |
| 807 | 818 |
| 808 } // namespace protocol | 819 } // namespace protocol |
| 809 } // namespace remoting | 820 } // namespace remoting |
| OLD | NEW |