WKWebView: fixup empty URL in didStartProvisionalNavigation only on iOS9
[chromium-blink-merge.git] / remoting / signaling / fake_signal_strategy.h
blobd0fb99add582d12c75ece1bdec2df3e97592802d
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 ~FakeSignalStrategy() override;
34 const std::list<buzz::XmlElement*>& received_messages() {
35 return received_messages_;
38 void set_send_delay(base::TimeDelta delay) {
39 send_delay_ = delay;
42 // Connects current FakeSignalStrategy to receive messages from |peer|.
43 void ConnectTo(FakeSignalStrategy* peer);
45 void SetLocalJid(const std::string& jid);
47 // SignalStrategy interface.
48 void Connect() override;
49 void Disconnect() override;
50 State GetState() const override;
51 Error GetError() const override;
52 std::string GetLocalJid() const override;
53 void AddListener(Listener* listener) override;
54 void RemoveListener(Listener* listener) override;
55 bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) override;
56 std::string GetNextId() override;
58 private:
59 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> message)>
60 PeerCallback;
62 static void DeliverMessageOnThread(
63 scoped_refptr<base::SingleThreadTaskRunner> thread,
64 base::WeakPtr<FakeSignalStrategy> target,
65 scoped_ptr<buzz::XmlElement> stanza);
67 // Called by the |peer_|. Takes ownership of |stanza|.
68 void OnIncomingMessage(scoped_ptr<buzz::XmlElement> stanza);
69 void SetPeerCallback(const PeerCallback& peer_callback);
71 scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
73 std::string jid_;
74 PeerCallback peer_callback_;
75 base::ObserverList<Listener, true> listeners_;
77 int last_id_;
79 base::TimeDelta send_delay_;
81 // All received messages, includes thouse still in |pending_messages_|.
82 std::list<buzz::XmlElement*> received_messages_;
84 base::WeakPtrFactory<FakeSignalStrategy> weak_factory_;
86 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy);
89 } // namespace remoting
91 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_