OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/javascript_iq_request.h" | 5 #include "remoting/jingle_glue/javascript_iq_request.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "remoting/jingle_glue/signal_strategy.h" | 9 #include "remoting/jingle_glue/signal_strategy.h" |
10 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 10 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 VLOG(1) << "Dropping IQ packet with no request id: " << stanza->Str(); | 50 VLOG(1) << "Dropping IQ packet with no request id: " << stanza->Str(); |
51 } else { | 51 } else { |
52 // TODO(ajwong): We should look at the logic inside libjingle's | 52 // TODO(ajwong): We should look at the logic inside libjingle's |
53 // XmppTask::MatchResponseIq() and make sure we're fully in sync. | 53 // XmppTask::MatchResponseIq() and make sure we're fully in sync. |
54 // They check more fields and conditions than us. | 54 // They check more fields and conditions than us. |
55 | 55 |
56 // TODO(ajwong): This logic is weird. We add to the register in | 56 // TODO(ajwong): This logic is weird. We add to the register in |
57 // JavascriptIqRequest::SendIq(), but remove in | 57 // JavascriptIqRequest::SendIq(), but remove in |
58 // JavascriptIqRegistry::OnIq(). We should try to keep the | 58 // JavascriptIqRegistry::OnIq(). We should try to keep the |
59 // registration/deregistration in one spot. | 59 // registration/deregistration in one spot. |
60 if (it->second->callback_.get()) { | 60 if (it->second->callback_.is_null()) { |
61 it->second->callback_->Run(stanza); | 61 it->second->callback_.Run(stanza); |
| 62 it->second->callback_.Reset(); |
62 } else { | 63 } else { |
63 VLOG(1) << "No callback, so dropping: " << stanza->Str(); | 64 VLOG(1) << "No callback, so dropping: " << stanza->Str(); |
64 } | 65 } |
65 requests_.erase(it); | 66 requests_.erase(it); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 void JavascriptIqRegistry::RegisterRequest( | 70 void JavascriptIqRegistry::RegisterRequest( |
70 JavascriptIqRequest* request, const std::string& id) { | 71 JavascriptIqRequest* request, const std::string& id) { |
71 DCHECK(requests_.find(id) == requests_.end()); | 72 DCHECK(requests_.find(id) == requests_.end()); |
(...skipping 11 matching lines...) Expand all Loading... |
83 } | 84 } |
84 | 85 |
85 void JavascriptIqRequest::SendIq(const std::string& type, | 86 void JavascriptIqRequest::SendIq(const std::string& type, |
86 const std::string& addressee, | 87 const std::string& addressee, |
87 buzz::XmlElement* iq_body) { | 88 buzz::XmlElement* iq_body) { |
88 std::string id = signal_strategy_->GetNextId(); | 89 std::string id = signal_strategy_->GetNextId(); |
89 registry_->RegisterRequest(this, id); | 90 registry_->RegisterRequest(this, id); |
90 signal_strategy_->SendStanza(MakeIqStanza(type, addressee, iq_body, id)); | 91 signal_strategy_->SendStanza(MakeIqStanza(type, addressee, iq_body, id)); |
91 } | 92 } |
92 | 93 |
93 void JavascriptIqRequest::set_callback(ReplyCallback* callback) { | 94 void JavascriptIqRequest::set_callback(const ReplyCallback& callback) { |
94 callback_.reset(callback); | 95 callback_ = callback; |
95 } | 96 } |
96 | 97 |
97 } // namespace remoting | 98 } // namespace remoting |
OLD | NEW |