summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/jingle_glue/fake_signal_strategy.cc42
-rw-r--r--remoting/jingle_glue/fake_signal_strategy.h5
2 files changed, 30 insertions, 17 deletions
diff --git a/remoting/jingle_glue/fake_signal_strategy.cc b/remoting/jingle_glue/fake_signal_strategy.cc
index 98cfc42..be7c14b 100644
--- a/remoting/jingle_glue/fake_signal_strategy.cc
+++ b/remoting/jingle_glue/fake_signal_strategy.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/stl_util-inl.h"
#include "base/string_number_conversions.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
#include "third_party/libjingle/source/talk/xmpp/constants.h"
@@ -30,6 +31,10 @@ FakeSignalStrategy::FakeSignalStrategy(const std::string& jid)
}
FakeSignalStrategy::~FakeSignalStrategy() {
+ while (!pending_messages_.empty()) {
+ delete pending_messages_.front();
+ pending_messages_.pop();
+ }
}
void FakeSignalStrategy::Init(StatusObserver* observer) {
@@ -77,25 +82,30 @@ IqRequest* FakeSignalStrategy::CreateIqRequest() {
}
void FakeSignalStrategy::OnIncomingMessage(buzz::XmlElement* stanza) {
- MessageLoop::current()->PostTask(
- FROM_HERE, task_factory_.NewRunnableMethod(
- &FakeSignalStrategy::DeliverIncomingMessage, stanza));
+ pending_messages_.push(stanza);
+ MessageLoop::current()->PostTask(
+ FROM_HERE, task_factory_.NewRunnableMethod(
+ &FakeSignalStrategy::DeliverIncomingMessages));
}
-void FakeSignalStrategy::DeliverIncomingMessage(buzz::XmlElement* stanza) {
- const std::string& to_field = stanza->Attr(buzz::QN_TO);
- if (to_field != jid_) {
- LOG(WARNING) << "Dropping stanza that is addressed to " << to_field
- << ". Local jid: " << jid_
- << ". Message content: " << stanza->Str();
- return;
+void FakeSignalStrategy::DeliverIncomingMessages() {
+ while (!pending_messages_.empty()) {
+ buzz::XmlElement* stanza = pending_messages_.front();
+ const std::string& to_field = stanza->Attr(buzz::QN_TO);
+ if (to_field != jid_) {
+ LOG(WARNING) << "Dropping stanza that is addressed to " << to_field
+ << ". Local jid: " << jid_
+ << ". Message content: " << stanza->Str();
+ return;
+ }
+
+ if (listener_)
+ listener_->OnIncomingStanza(stanza);
+ iq_registry_.OnIncomingStanza(stanza);
+
+ pending_messages_.pop();
+ delete stanza;
}
-
- if (listener_)
- listener_->OnIncomingStanza(stanza);
- iq_registry_.OnIncomingStanza(stanza);
-
- delete stanza;
}
} // namespace remoting
diff --git a/remoting/jingle_glue/fake_signal_strategy.h b/remoting/jingle_glue/fake_signal_strategy.h
index 83e1ae9..553313e 100644
--- a/remoting/jingle_glue/fake_signal_strategy.h
+++ b/remoting/jingle_glue/fake_signal_strategy.h
@@ -5,6 +5,7 @@
#ifndef REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
#define REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
+#include <queue>
#include <string>
#include "base/task.h"
@@ -34,7 +35,7 @@ class FakeSignalStrategy : public SignalStrategy,
// Called by the |peer_|. Takes ownership of |stanza|.
void OnIncomingMessage(buzz::XmlElement* stanza);
- void DeliverIncomingMessage(buzz::XmlElement* stanza);
+ void DeliverIncomingMessages();
std::string jid_;
FakeSignalStrategy* peer_;
@@ -43,6 +44,8 @@ class FakeSignalStrategy : public SignalStrategy,
int last_id_;
+ std::queue<buzz::XmlElement*> pending_messages_;
+
ScopedRunnableMethodFactory<FakeSignalStrategy> task_factory_;
DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy);