1 // Copyright (c) 2012 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 #ifndef REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
6 #define REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_
12 #include "base/observer_list.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "remoting/jingle_glue/iq_sender.h"
16 #include "remoting/jingle_glue/signal_strategy.h"
20 class FakeSignalStrategy
: public SignalStrategy
,
21 public base::NonThreadSafe
{
23 static void Connect(FakeSignalStrategy
* peer1
, FakeSignalStrategy
* peer2
);
25 FakeSignalStrategy(const std::string
& jid
);
26 virtual ~FakeSignalStrategy();
28 const std::list
<buzz::XmlElement
*>& received_messages() {
29 return received_messages_
;
32 // SignalStrategy interface.
33 virtual void Connect() OVERRIDE
;
34 virtual void Disconnect() OVERRIDE
;
35 virtual State
GetState() const OVERRIDE
;
36 virtual Error
GetError() const OVERRIDE
;
37 virtual std::string
GetLocalJid() const OVERRIDE
;
38 virtual void AddListener(Listener
* listener
) OVERRIDE
;
39 virtual void RemoveListener(Listener
* listener
) OVERRIDE
;
40 virtual bool SendStanza(scoped_ptr
<buzz::XmlElement
> stanza
) OVERRIDE
;
41 virtual std::string
GetNextId() OVERRIDE
;
44 // Called by the |peer_|. Takes ownership of |stanza|.
45 void OnIncomingMessage(scoped_ptr
<buzz::XmlElement
> stanza
);
47 void DeliverIncomingMessages();
50 FakeSignalStrategy
* peer_
;
51 ObserverList
<Listener
, true> listeners_
;
55 // All received messages, includes thouse still in |pending_messages_|.
56 std::list
<buzz::XmlElement
*> received_messages_
;
58 // Queue of messages that have yet to be delivered to observers.
59 std::queue
<buzz::XmlElement
*> pending_messages_
;
61 base::WeakPtrFactory
<FakeSignalStrategy
> weak_factory_
;
63 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy
);
66 } // namespace remoting
68 #endif // REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_