1 // Copyright 2014 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_SIGNALING_FAKE_SIGNAL_STRATEGY_H_
6 #define REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "remoting/signaling/iq_sender.h"
16 #include "remoting/signaling/signal_strategy.h"
19 class SingleThreadTaskRunner
;
24 class FakeSignalStrategy
: public SignalStrategy
,
25 public base::NonThreadSafe
{
27 // Calls ConenctTo() to connect |peer1| and |peer2|. Both |peer1| and |peer2|
28 // must belong to the current thread.
29 static void Connect(FakeSignalStrategy
* peer1
, FakeSignalStrategy
* peer2
);
31 FakeSignalStrategy(const std::string
& jid
);
32 ~FakeSignalStrategy() override
;
34 const std::list
<buzz::XmlElement
*>& received_messages() {
35 return received_messages_
;
38 void set_send_delay(base::TimeDelta delay
) {
42 // Connects current FakeSignalStrategy to receive messages from |peer|.
43 void ConnectTo(FakeSignalStrategy
* peer
);
45 // SignalStrategy interface.
46 void Connect() override
;
47 void Disconnect() override
;
48 State
GetState() const override
;
49 Error
GetError() const override
;
50 std::string
GetLocalJid() const override
;
51 void AddListener(Listener
* listener
) override
;
52 void RemoveListener(Listener
* listener
) override
;
53 bool SendStanza(scoped_ptr
<buzz::XmlElement
> stanza
) override
;
54 std::string
GetNextId() override
;
57 typedef base::Callback
<void(scoped_ptr
<buzz::XmlElement
> message
)>
60 static void DeliverMessageOnThread(
61 scoped_refptr
<base::SingleThreadTaskRunner
> thread
,
62 base::WeakPtr
<FakeSignalStrategy
> target
,
63 scoped_ptr
<buzz::XmlElement
> stanza
);
65 // Called by the |peer_|. Takes ownership of |stanza|.
66 void OnIncomingMessage(scoped_ptr
<buzz::XmlElement
> stanza
);
67 void SetPeerCallback(const PeerCallback
& peer_callback
);
69 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_
;
72 PeerCallback peer_callback_
;
73 ObserverList
<Listener
, true> listeners_
;
77 base::TimeDelta send_delay_
;
79 // All received messages, includes thouse still in |pending_messages_|.
80 std::list
<buzz::XmlElement
*> received_messages_
;
82 base::WeakPtrFactory
<FakeSignalStrategy
> weak_factory_
;
84 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy
);
87 } // namespace remoting
89 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_