summaryrefslogtreecommitdiffstats
path: root/remoting/jingle_glue
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-28 23:21:37 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-28 23:21:37 +0000
commitf7ea9873ee42b8f01466cb7f523e3e705c21a96d (patch)
treed1de8a10573aeaeba879eeed340878430c219d7e /remoting/jingle_glue
parent0573d85d1626d7a9088c607d24c1e662d7152a1c (diff)
downloadchromium_src-f7ea9873ee42b8f01466cb7f523e3e705c21a96d.zip
chromium_src-f7ea9873ee42b8f01466cb7f523e3e705c21a96d.tar.gz
chromium_src-f7ea9873ee42b8f01466cb7f523e3e705c21a96d.tar.bz2
Add FakeSignalStrategy.
The new class will be used in tests instead of SessionManagerPair. BUG=None TEST=None Review URL: http://codereview.chromium.org/7276017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90867 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r--remoting/jingle_glue/fake_signal_strategy.cc96
-rw-r--r--remoting/jingle_glue/fake_signal_strategy.h48
2 files changed, 144 insertions, 0 deletions
diff --git a/remoting/jingle_glue/fake_signal_strategy.cc b/remoting/jingle_glue/fake_signal_strategy.cc
new file mode 100644
index 0000000..57497cf
--- /dev/null
+++ b/remoting/jingle_glue/fake_signal_strategy.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/jingle_glue/fake_signal_strategy.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/message_loop.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"
+
+namespace remoting {
+
+// static
+void FakeSignalStrategy::Connect(FakeSignalStrategy* peer1,
+ FakeSignalStrategy* peer2) {
+ peer1->peer_ = peer2;
+ peer2->peer_ = peer1;
+}
+
+FakeSignalStrategy::FakeSignalStrategy(const std::string& jid)
+ : jid_(jid),
+ peer_(NULL),
+ listener_(NULL),
+ last_id_(0) {
+
+}
+
+FakeSignalStrategy::~FakeSignalStrategy() {
+}
+
+void FakeSignalStrategy::Init(StatusObserver* observer) {
+ observer->OnStateChange(StatusObserver::START);
+ observer->OnStateChange(StatusObserver::CONNECTING);
+ observer->OnJidChange(jid_);
+ observer->OnStateChange(StatusObserver::CONNECTED);
+}
+
+void FakeSignalStrategy::Close() {
+ DCHECK(CalledOnValidThread());
+ listener_ = NULL;
+}
+
+void FakeSignalStrategy::SetListener(Listener* listener) {
+ DCHECK(CalledOnValidThread());
+
+ // Don't overwrite an listener without explicitly going
+ // through "NULL" first.
+ DCHECK(listener_ == NULL || listener == NULL);
+ listener_ = listener;
+}
+
+void FakeSignalStrategy::SendStanza(buzz::XmlElement* stanza) {
+ DCHECK(CalledOnValidThread());
+
+ stanza->SetAttr(buzz::QN_FROM, jid_);
+
+ if (peer_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&FakeSignalStrategy::OnIncomingMessage,
+ base::Unretained(peer_), stanza));
+ } else {
+ delete stanza;
+ }
+}
+
+std::string FakeSignalStrategy::GetNextId() {
+ ++last_id_;
+ return base::IntToString(last_id_);
+}
+
+IqRequest* FakeSignalStrategy::CreateIqRequest() OVERRIDE {
+ DCHECK(CalledOnValidThread());
+
+ return new JavascriptIqRequest(this, &iq_registry_);
+}
+
+void FakeSignalStrategy::OnIncomingMessage(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;
+ }
+
+ 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
new file mode 100644
index 0000000..40f6ee1
--- /dev/null
+++ b/remoting/jingle_glue/fake_signal_strategy.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
+#define REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
+
+#include <string>
+
+#include "base/threading/non_thread_safe.h"
+#include "remoting/jingle_glue/javascript_iq_request.h"
+#include "remoting/jingle_glue/signal_strategy.h"
+
+namespace remoting {
+
+class FakeSignalStrategy : public SignalStrategy,
+ public base::NonThreadSafe {
+ public:
+ static void Connect(FakeSignalStrategy* peer1, FakeSignalStrategy* peer2);
+
+ FakeSignalStrategy(const std::string& jid);
+ virtual ~FakeSignalStrategy();
+
+ // SignalStrategy interface.
+ virtual void Init(StatusObserver* observer) OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual void SetListener(Listener* listener) OVERRIDE;
+ virtual void SendStanza(buzz::XmlElement* stanza) OVERRIDE;
+ virtual std::string GetNextId() OVERRIDE;
+ virtual IqRequest* CreateIqRequest() OVERRIDE;
+
+ private:
+ // Called by the |peer_|. Takes ownership of |stanza|.
+ void OnIncomingMessage(buzz::XmlElement* stanza);
+
+ std::string jid_;
+ FakeSignalStrategy* peer_;
+ Listener* listener_;
+ JavascriptIqRegistry iq_registry_;
+
+ int last_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_