| 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/jingle_glue/iq_sender.h" | 5 #include "remoting/jingle_glue/iq_sender.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "remoting/jingle_glue/signal_strategy.h" | 15 #include "remoting/jingle_glue/signal_strategy.h" |
| 15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 16 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 17 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 scoped_ptr<buzz::XmlElement> IqSender::MakeIqStanza( | 22 scoped_ptr<buzz::XmlElement> IqSender::MakeIqStanza( |
| 22 const std::string& type, | 23 const std::string& type, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 : sender_(sender), | 139 : sender_(sender), |
| 139 callback_(callback), | 140 callback_(callback), |
| 140 addressee_(addressee) { | 141 addressee_(addressee) { |
| 141 } | 142 } |
| 142 | 143 |
| 143 IqRequest::~IqRequest() { | 144 IqRequest::~IqRequest() { |
| 144 sender_->RemoveRequest(this); | 145 sender_->RemoveRequest(this); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void IqRequest::SetTimeout(base::TimeDelta timeout) { | 148 void IqRequest::SetTimeout(base::TimeDelta timeout) { |
| 148 base::MessageLoopProxy::current()->PostDelayedTask( | 149 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 149 FROM_HERE, base::Bind(&IqRequest::OnTimeout, AsWeakPtr()), | 150 FROM_HERE, base::Bind(&IqRequest::OnTimeout, AsWeakPtr()), timeout); |
| 150 timeout); | |
| 151 } | 151 } |
| 152 | 152 |
| 153 void IqRequest::CallCallback(const buzz::XmlElement* stanza) { | 153 void IqRequest::CallCallback(const buzz::XmlElement* stanza) { |
| 154 if (!callback_.is_null()) { | 154 if (!callback_.is_null()) { |
| 155 IqSender::ReplyCallback callback(callback_); | 155 IqSender::ReplyCallback callback(callback_); |
| 156 callback_.Reset(); | 156 callback_.Reset(); |
| 157 callback.Run(this, stanza); | 157 callback.Run(this, stanza); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 void IqRequest::OnTimeout() { | 161 void IqRequest::OnTimeout() { |
| 162 CallCallback(NULL); | 162 CallCallback(NULL); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void IqRequest::OnResponse(const buzz::XmlElement* stanza) { | 165 void IqRequest::OnResponse(const buzz::XmlElement* stanza) { |
| 166 // It's unsafe to delete signal strategy here, and the callback may | 166 // It's unsafe to delete signal strategy here, and the callback may |
| 167 // want to do that, so we post task to invoke the callback later. | 167 // want to do that, so we post task to invoke the callback later. |
| 168 scoped_ptr<buzz::XmlElement> stanza_copy(new buzz::XmlElement(*stanza)); | 168 scoped_ptr<buzz::XmlElement> stanza_copy(new buzz::XmlElement(*stanza)); |
| 169 base::MessageLoopProxy::current()->PostTask( | 169 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 170 FROM_HERE, base::Bind(&IqRequest::DeliverResponse, AsWeakPtr(), | 170 FROM_HERE, base::Bind(&IqRequest::DeliverResponse, AsWeakPtr(), |
| 171 base::Passed(&stanza_copy))); | 171 base::Passed(&stanza_copy))); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void IqRequest::DeliverResponse(scoped_ptr<buzz::XmlElement> stanza) { | 174 void IqRequest::DeliverResponse(scoped_ptr<buzz::XmlElement> stanza) { |
| 175 CallCallback(stanza.get()); | 175 CallCallback(stanza.get()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace remoting | 178 } // namespace remoting |
| OLD | NEW |