| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 8 #include "base/location.h" | 9 #include "base/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "remoting/signaling/signal_strategy.h" | 16 #include "remoting/signaling/signal_strategy.h" |
| 16 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 17 #include "third_party/webrtc/libjingle/xmpp/constants.h" | 18 #include "third_party/webrtc/libjingle/xmpp/constants.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 IqRequest::~IqRequest() { | 132 IqRequest::~IqRequest() { |
| 132 sender_->RemoveRequest(this); | 133 sender_->RemoveRequest(this); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void IqRequest::SetTimeout(base::TimeDelta timeout) { | 136 void IqRequest::SetTimeout(base::TimeDelta timeout) { |
| 136 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 137 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 137 FROM_HERE, base::Bind(&IqRequest::OnTimeout, AsWeakPtr()), timeout); | 138 FROM_HERE, base::Bind(&IqRequest::OnTimeout, AsWeakPtr()), timeout); |
| 138 } | 139 } |
| 139 | 140 |
| 140 void IqRequest::CallCallback(const buzz::XmlElement* stanza) { | 141 void IqRequest::CallCallback(const buzz::XmlElement* stanza) { |
| 141 if (!callback_.is_null()) { | 142 if (!callback_.is_null()) |
| 142 IqSender::ReplyCallback callback(callback_); | 143 base::ResetAndReturn(&callback_).Run(this, stanza); |
| 143 callback_.Reset(); | |
| 144 callback.Run(this, stanza); | |
| 145 } | |
| 146 } | 144 } |
| 147 | 145 |
| 148 void IqRequest::OnTimeout() { | 146 void IqRequest::OnTimeout() { |
| 149 CallCallback(nullptr); | 147 CallCallback(nullptr); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void IqRequest::OnResponse(const buzz::XmlElement* stanza) { | 150 void IqRequest::OnResponse(const buzz::XmlElement* stanza) { |
| 153 // It's unsafe to delete signal strategy here, and the callback may | 151 // It's unsafe to delete signal strategy here, and the callback may |
| 154 // want to do that, so we post task to invoke the callback later. | 152 // want to do that, so we post task to invoke the callback later. |
| 155 scoped_ptr<buzz::XmlElement> stanza_copy(new buzz::XmlElement(*stanza)); | 153 scoped_ptr<buzz::XmlElement> stanza_copy(new buzz::XmlElement(*stanza)); |
| 156 base::ThreadTaskRunnerHandle::Get()->PostTask( | 154 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 157 FROM_HERE, base::Bind(&IqRequest::DeliverResponse, AsWeakPtr(), | 155 FROM_HERE, base::Bind(&IqRequest::DeliverResponse, AsWeakPtr(), |
| 158 base::Passed(&stanza_copy))); | 156 base::Passed(&stanza_copy))); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void IqRequest::DeliverResponse(scoped_ptr<buzz::XmlElement> stanza) { | 159 void IqRequest::DeliverResponse(scoped_ptr<buzz::XmlElement> stanza) { |
| 162 CallCallback(stanza.get()); | 160 CallCallback(stanza.get()); |
| 163 } | 161 } |
| 164 | 162 |
| 165 } // namespace remoting | 163 } // namespace remoting |
| OLD | NEW |