Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / remoting / signaling / fake_signal_strategy.h
blob05c5ba5152549e43be5b58e72b99d2665c341ebe
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_
8 #include <list>
9 #include <queue>
10 #include <string>
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"
18 namespace base {
19 class SingleThreadTaskRunner;
20 } // namespace base
22 namespace remoting {
24 class FakeSignalStrategy : public SignalStrategy,
25 public base::NonThreadSafe {
26 public:
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 virtual ~FakeSignalStrategy();
34 const std::list<buzz::XmlElement*>& received_messages() {
35 return received_messages_;
38 // Connects current FakeSignalStrategy to receive messages from |peer|.
39 void ConnectTo(FakeSignalStrategy* peer);
41 // SignalStrategy interface.
42 virtual void Connect() OVERRIDE;
43 virtual void Disconnect() OVERRIDE;
44 virtual State GetState() const OVERRIDE;
45 virtual Error GetError() const OVERRIDE;
46 virtual std::string GetLocalJid() const OVERRIDE;
47 virtual void AddListener(Listener* listener) OVERRIDE;
48 virtual void RemoveListener(Listener* listener) OVERRIDE;
49 virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE;
50 virtual std::string GetNextId() OVERRIDE;
52 private:
53 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> message)>
54 PeerCallback;
56 static void DeliverMessageOnThread(
57 scoped_refptr<base::SingleThreadTaskRunner> thread,
58 base::WeakPtr<FakeSignalStrategy> target,
59 scoped_ptr<buzz::XmlElement> stanza);
61 // Called by the |peer_|. Takes ownership of |stanza|.
62 void OnIncomingMessage(scoped_ptr<buzz::XmlElement> stanza);
63 void SetPeerCallback(const PeerCallback& peer_callback);
65 scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
67 std::string jid_;
68 PeerCallback peer_callback_;
69 ObserverList<Listener, true> listeners_;
71 int last_id_;
73 // All received messages, includes thouse still in |pending_messages_|.
74 std::list<buzz::XmlElement*> received_messages_;
76 base::WeakPtrFactory<FakeSignalStrategy> weak_factory_;
78 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy);
81 } // namespace remoting
83 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_