OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signaling/iq_sender.h" | 5 #include "remoting/signaling/iq_sender.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 IqSender::~IqSender() { | 43 IqSender::~IqSender() { |
44 signal_strategy_->RemoveListener(this); | 44 signal_strategy_->RemoveListener(this); |
45 } | 45 } |
46 | 46 |
47 std::unique_ptr<IqRequest> IqSender::SendIq( | 47 std::unique_ptr<IqRequest> IqSender::SendIq( |
48 std::unique_ptr<buzz::XmlElement> stanza, | 48 std::unique_ptr<buzz::XmlElement> stanza, |
49 const ReplyCallback& callback) { | 49 const ReplyCallback& callback) { |
50 std::string addressee = stanza->Attr(buzz::QN_TO); | 50 std::string addressee = stanza->Attr(buzz::QN_TO); |
51 std::string id = signal_strategy_->GetNextId(); | 51 std::string id = stanza->Attr(buzz::QN_ID); |
52 stanza->AddAttr(buzz::QN_ID, id); | 52 if (id.empty()) { |
| 53 id = signal_strategy_->GetNextId(); |
| 54 stanza->AddAttr(buzz::QN_ID, id); |
| 55 } |
53 if (!signal_strategy_->SendStanza(std::move(stanza))) { | 56 if (!signal_strategy_->SendStanza(std::move(stanza))) { |
54 return nullptr; | 57 return nullptr; |
55 } | 58 } |
56 DCHECK(requests_.find(id) == requests_.end()); | 59 DCHECK(requests_.find(id) == requests_.end()); |
57 std::unique_ptr<IqRequest> request(new IqRequest(this, callback, addressee)); | 60 std::unique_ptr<IqRequest> request(new IqRequest(this, callback, addressee)); |
58 if (!callback.is_null()) | 61 if (!callback.is_null()) |
59 requests_[id] = request.get(); | 62 requests_[id] = request.get(); |
60 return request; | 63 return request; |
61 } | 64 } |
62 | 65 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 base::ThreadTaskRunnerHandle::Get()->PostTask( | 162 base::ThreadTaskRunnerHandle::Get()->PostTask( |
160 FROM_HERE, base::Bind(&IqRequest::DeliverResponse, AsWeakPtr(), | 163 FROM_HERE, base::Bind(&IqRequest::DeliverResponse, AsWeakPtr(), |
161 base::Passed(&stanza_copy))); | 164 base::Passed(&stanza_copy))); |
162 } | 165 } |
163 | 166 |
164 void IqRequest::DeliverResponse(std::unique_ptr<buzz::XmlElement> stanza) { | 167 void IqRequest::DeliverResponse(std::unique_ptr<buzz::XmlElement> stanza) { |
165 CallCallback(stanza.get()); | 168 CallCallback(stanza.get()); |
166 } | 169 } |
167 | 170 |
168 } // namespace remoting | 171 } // namespace remoting |
OLD | NEW |