1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/client/plugin/delegating_signal_strategy.h"
7 #include "base/rand_util.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
13 DelegatingSignalStrategy::DelegatingSignalStrategy(
14 std::string local_jid
,
15 const SendIqCallback
& send_iq_callback
)
16 : local_jid_(local_jid
),
17 send_iq_callback_(send_iq_callback
) {
20 DelegatingSignalStrategy::~DelegatingSignalStrategy() {
23 void DelegatingSignalStrategy::OnIncomingMessage(const std::string
& message
) {
24 scoped_ptr
<buzz::XmlElement
> stanza(buzz::XmlElement::ForStr(message
));
26 LOG(WARNING
) << "Malformed XMPP stanza received: " << message
;
30 base::ObserverListBase
<Listener
>::Iterator
it(&listeners_
);
32 while ((listener
= it
.GetNext()) != nullptr) {
33 if (listener
->OnSignalStrategyIncomingStanza(stanza
.get()))
38 void DelegatingSignalStrategy::Connect() {
41 void DelegatingSignalStrategy::Disconnect() {
44 SignalStrategy::State
DelegatingSignalStrategy::GetState() const {
48 SignalStrategy::Error
DelegatingSignalStrategy::GetError() const {
52 std::string
DelegatingSignalStrategy::GetLocalJid() const {
56 void DelegatingSignalStrategy::AddListener(Listener
* listener
) {
57 listeners_
.AddObserver(listener
);
60 void DelegatingSignalStrategy::RemoveListener(Listener
* listener
) {
61 listeners_
.RemoveObserver(listener
);
64 bool DelegatingSignalStrategy::SendStanza(scoped_ptr
<buzz::XmlElement
> stanza
) {
65 send_iq_callback_
.Run(stanza
->Str());
69 std::string
DelegatingSignalStrategy::GetNextId() {
70 return base::Uint64ToString(base::RandUint64());
73 } // namespace remoting