• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "remoting/client/plugin/delegating_signal_strategy.h"
6 
7 #include "base/strings/string_number_conversions.h"
8 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
9 
10 namespace remoting {
11 
DelegatingSignalStrategy(std::string local_jid,const SendIqCallback & send_iq_callback)12 DelegatingSignalStrategy::DelegatingSignalStrategy(
13     std::string local_jid,
14     const SendIqCallback& send_iq_callback)
15     : local_jid_(local_jid),
16       send_iq_callback_(send_iq_callback),
17       last_id_(0) {
18 }
19 
~DelegatingSignalStrategy()20 DelegatingSignalStrategy::~DelegatingSignalStrategy() {
21 }
22 
OnIncomingMessage(const std::string & message)23 void DelegatingSignalStrategy::OnIncomingMessage(const std::string& message) {
24  scoped_ptr<buzz::XmlElement> stanza(buzz::XmlElement::ForStr(message));
25   if (!stanza.get()) {
26     LOG(WARNING) << "Malformed XMPP stanza received: " << message;
27     return;
28   }
29 
30   ObserverListBase<Listener>::Iterator it(listeners_);
31   Listener* listener;
32   while ((listener = it.GetNext()) != NULL) {
33     if (listener->OnSignalStrategyIncomingStanza(stanza.get()))
34       break;
35   }
36 }
37 
Connect()38 void DelegatingSignalStrategy::Connect() {
39 }
40 
Disconnect()41 void DelegatingSignalStrategy::Disconnect() {
42 }
43 
GetState() const44 SignalStrategy::State DelegatingSignalStrategy::GetState() const {
45   return CONNECTED;
46 }
47 
GetError() const48 SignalStrategy::Error DelegatingSignalStrategy::GetError() const {
49   return OK;
50 }
51 
GetLocalJid() const52 std::string DelegatingSignalStrategy::GetLocalJid() const {
53   return local_jid_;
54 }
55 
AddListener(Listener * listener)56 void DelegatingSignalStrategy::AddListener(Listener* listener) {
57   listeners_.AddObserver(listener);
58 }
59 
RemoveListener(Listener * listener)60 void DelegatingSignalStrategy::RemoveListener(Listener* listener) {
61   listeners_.RemoveObserver(listener);
62 }
63 
SendStanza(scoped_ptr<buzz::XmlElement> stanza)64 bool DelegatingSignalStrategy::SendStanza(scoped_ptr<buzz::XmlElement> stanza) {
65   send_iq_callback_.Run(stanza->Str());
66   return true;
67 }
68 
GetNextId()69 std::string DelegatingSignalStrategy::GetNextId() {
70   ++last_id_;
71   return base::IntToString(last_id_);
72 }
73 
74 }  // namespace remoting
75