forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
sergeyu@chromium.org
committed
Jun 28, 2011
1 parent
0573d85
commit f7ea987
Showing
3 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters