summaryrefslogtreecommitdiffstats
path: root/remoting/jingle_glue/xmpp_signal_strategy.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-23 16:35:44 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-23 16:35:44 +0000
commit512ac40edc7551c76bbd9bf288afee209f6bba15 (patch)
tree1ff85ae2cf2b7d65fef41729225a62b9ecc1d1f1 /remoting/jingle_glue/xmpp_signal_strategy.cc
parent590742dc369f718055cded657f197d154639493e (diff)
downloadchromium_src-512ac40edc7551c76bbd9bf288afee209f6bba15.zip
chromium_src-512ac40edc7551c76bbd9bf288afee209f6bba15.tar.gz
chromium_src-512ac40edc7551c76bbd9bf288afee209f6bba15.tar.bz2
Refactoring around SignalStrategy interface.
- Added AddListener/RemoveListener in the SignalStrategy interface. - Remove dependancy on JavascriptIqRequest from JingleSignalingConnector. BUG=None TEST=Chromoting client still works Review URL: http://codereview.chromium.org/7239005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90219 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue/xmpp_signal_strategy.cc')
-rw-r--r--remoting/jingle_glue/xmpp_signal_strategy.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/remoting/jingle_glue/xmpp_signal_strategy.cc b/remoting/jingle_glue/xmpp_signal_strategy.cc
index 9f177fe..a8a8008 100644
--- a/remoting/jingle_glue/xmpp_signal_strategy.cc
+++ b/remoting/jingle_glue/xmpp_signal_strategy.cc
@@ -4,6 +4,7 @@
#include "remoting/jingle_glue/xmpp_signal_strategy.h"
+#include "base/logging.h"
#include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h"
#include "remoting/jingle_glue/jingle_thread.h"
#include "remoting/jingle_glue/xmpp_iq_request.h"
@@ -21,6 +22,7 @@ XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread,
const std::string& auth_token,
const std::string& auth_token_service)
: thread_(jingle_thread),
+ listener_(NULL),
username_(username),
auth_token_(auth_token),
auth_token_service_(auth_token_service),
@@ -29,6 +31,10 @@ XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread,
}
XmppSignalStrategy::~XmppSignalStrategy() {
+ if (xmpp_client_)
+ xmpp_client_->engine()->RemoveStanzaHandler(this);
+
+ DCHECK(listener_ == NULL);
}
void XmppSignalStrategy::Init(StatusObserver* observer) {
@@ -51,9 +57,21 @@ void XmppSignalStrategy::Init(StatusObserver* observer) {
xmpp_client_->Connect(settings, "", socket, CreatePreXmppAuth(settings));
xmpp_client_->SignalStateChange.connect(
this, &XmppSignalStrategy::OnConnectionStateChanged);
+ xmpp_client_->engine()->AddStanzaHandler(this, buzz::XmppEngine::HL_PEEK);
xmpp_client_->Start();
}
+void XmppSignalStrategy::SetListener(Listener* listener) {
+ // Don't overwrite an listener without explicitly going
+ // through "NULL" first.
+ DCHECK(listener_ == NULL || listener == NULL);
+ listener_ = listener;
+}
+
+void XmppSignalStrategy::SendStanza(buzz::XmlElement* stanza) {
+ xmpp_client_->SendStanza(stanza);
+}
+
void XmppSignalStrategy::StartSession(
cricket::SessionManager* session_manager) {
cricket::SessionManagerTask* receiver =
@@ -64,6 +82,7 @@ void XmppSignalStrategy::StartSession(
void XmppSignalStrategy::EndSession() {
if (xmpp_client_) {
+ xmpp_client_->engine()->RemoveStanzaHandler(this);
xmpp_client_->Disconnect();
// Client is deleted by TaskRunner.
xmpp_client_ = NULL;
@@ -74,6 +93,11 @@ IqRequest* XmppSignalStrategy::CreateIqRequest() {
return new XmppIqRequest(thread_->message_loop(), xmpp_client_);
}
+bool XmppSignalStrategy::HandleStanza(const buzz::XmlElement* stanza) {
+ listener_->OnIncomingStanza(stanza);
+ return false;
+}
+
void XmppSignalStrategy::OnConnectionStateChanged(
buzz::XmppEngine::State state) {
switch (state) {
@@ -99,6 +123,7 @@ void XmppSignalStrategy::OnConnectionStateChanged(
}
}
+// static
buzz::PreXmppAuth* XmppSignalStrategy::CreatePreXmppAuth(
const buzz::XmppClientSettings& settings) {
buzz::Jid jid(settings.user(), settings.host(), buzz::STR_EMPTY);