| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_ | |
| 6 #define REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <queue> | |
| 10 #include <string> | |
| 11 | |
| 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" | |
| 17 | |
| 18 namespace remoting { | |
| 19 | |
| 20 class FakeSignalStrategy : public SignalStrategy, | |
| 21 public base::NonThreadSafe { | |
| 22 public: | |
| 23 static void Connect(FakeSignalStrategy* peer1, FakeSignalStrategy* peer2); | |
| 24 | |
| 25 FakeSignalStrategy(const std::string& jid); | |
| 26 virtual ~FakeSignalStrategy(); | |
| 27 | |
| 28 const std::list<buzz::XmlElement*>& received_messages() { | |
| 29 return received_messages_; | |
| 30 } | |
| 31 | |
| 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; | |
| 42 | |
| 43 private: | |
| 44 // Called by the |peer_|. Takes ownership of |stanza|. | |
| 45 void OnIncomingMessage(scoped_ptr<buzz::XmlElement> stanza); | |
| 46 | |
| 47 void DeliverIncomingMessages(); | |
| 48 | |
| 49 std::string jid_; | |
| 50 FakeSignalStrategy* peer_; | |
| 51 ObserverList<Listener, true> listeners_; | |
| 52 | |
| 53 int last_id_; | |
| 54 | |
| 55 // All received messages, includes thouse still in |pending_messages_|. | |
| 56 std::list<buzz::XmlElement*> received_messages_; | |
| 57 | |
| 58 // Queue of messages that have yet to be delivered to observers. | |
| 59 std::queue<buzz::XmlElement*> pending_messages_; | |
| 60 | |
| 61 base::WeakPtrFactory<FakeSignalStrategy> weak_factory_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy); | |
| 64 }; | |
| 65 | |
| 66 } // namespace remoting | |
| 67 | |
| 68 #endif // REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_ | |
| OLD | NEW |