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/fake_signal_strategy.h" | 5 #include "remoting/jingle_glue/fake_signal_strategy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | |
alexeypa (please no reviews)
2012/07/27 15:43:50
nit: Does base/location.h is really needed here?
Sergey Ulanov
2012/07/27 18:49:48
Yes, it defines FROM_HERE
| |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/message_loop.h" | 10 #include "base/single_thread_task_runner.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/thread_task_runner_handle.h" | |
12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
13 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 15 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
14 | 16 |
15 namespace remoting { | 17 namespace remoting { |
16 | 18 |
17 // static | 19 // static |
18 void FakeSignalStrategy::Connect(FakeSignalStrategy* peer1, | 20 void FakeSignalStrategy::Connect(FakeSignalStrategy* peer1, |
19 FakeSignalStrategy* peer2) { | 21 FakeSignalStrategy* peer2) { |
20 peer1->peer_ = peer2; | 22 peer1->peer_ = peer2; |
21 peer2->peer_ = peer1; | 23 peer2->peer_ = peer1; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 88 |
87 std::string FakeSignalStrategy::GetNextId() { | 89 std::string FakeSignalStrategy::GetNextId() { |
88 ++last_id_; | 90 ++last_id_; |
89 return base::IntToString(last_id_); | 91 return base::IntToString(last_id_); |
90 } | 92 } |
91 | 93 |
92 void FakeSignalStrategy::OnIncomingMessage( | 94 void FakeSignalStrategy::OnIncomingMessage( |
93 scoped_ptr<buzz::XmlElement> stanza) { | 95 scoped_ptr<buzz::XmlElement> stanza) { |
94 pending_messages_.push(stanza.get()); | 96 pending_messages_.push(stanza.get()); |
95 received_messages_.push_back(stanza.release()); | 97 received_messages_.push_back(stanza.release()); |
96 MessageLoop::current()->PostTask( | 98 base::ThreadTaskRunnerHandle::Get()->PostTask( |
97 FROM_HERE, base::Bind(&FakeSignalStrategy::DeliverIncomingMessages, | 99 FROM_HERE, base::Bind(&FakeSignalStrategy::DeliverIncomingMessages, |
98 weak_factory_.GetWeakPtr())); | 100 weak_factory_.GetWeakPtr())); |
99 } | 101 } |
100 | 102 |
101 void FakeSignalStrategy::DeliverIncomingMessages() { | 103 void FakeSignalStrategy::DeliverIncomingMessages() { |
102 while (!pending_messages_.empty()) { | 104 while (!pending_messages_.empty()) { |
103 buzz::XmlElement* stanza = pending_messages_.front(); | 105 buzz::XmlElement* stanza = pending_messages_.front(); |
104 const std::string& to_field = stanza->Attr(buzz::QN_TO); | 106 const std::string& to_field = stanza->Attr(buzz::QN_TO); |
105 if (to_field != jid_) { | 107 if (to_field != jid_) { |
106 LOG(WARNING) << "Dropping stanza that is addressed to " << to_field | 108 LOG(WARNING) << "Dropping stanza that is addressed to " << to_field |
107 << ". Local jid: " << jid_ | 109 << ". Local jid: " << jid_ |
108 << ". Message content: " << stanza->Str(); | 110 << ". Message content: " << stanza->Str(); |
109 return; | 111 return; |
110 } | 112 } |
111 | 113 |
112 ObserverListBase<Listener>::Iterator it(listeners_); | 114 ObserverListBase<Listener>::Iterator it(listeners_); |
113 Listener* listener; | 115 Listener* listener; |
114 while ((listener = it.GetNext()) != NULL) { | 116 while ((listener = it.GetNext()) != NULL) { |
115 if (listener->OnSignalStrategyIncomingStanza(stanza)) | 117 if (listener->OnSignalStrategyIncomingStanza(stanza)) |
116 break; | 118 break; |
117 } | 119 } |
118 | 120 |
119 pending_messages_.pop(); | 121 pending_messages_.pop(); |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 } // namespace remoting | 125 } // namespace remoting |
OLD | NEW |