Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: remoting/signaling/fake_signal_strategy.h

Issue 414443009: Update ProtocolPerfTest to run host and client on different threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ 5 #ifndef REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_
6 #define REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ 6 #define REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_
7 7
8 #include <list> 8 #include <list>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "remoting/signaling/iq_sender.h" 15 #include "remoting/signaling/iq_sender.h"
16 #include "remoting/signaling/signal_strategy.h" 16 #include "remoting/signaling/signal_strategy.h"
17 17
18 namespace base {
19 class SingleThreadTaskRunner;
20 } // namespace base
21
18 namespace remoting { 22 namespace remoting {
19 23
20 class FakeSignalStrategy : public SignalStrategy, 24 class FakeSignalStrategy : public SignalStrategy,
21 public base::NonThreadSafe { 25 public base::NonThreadSafe {
22 public: 26 public:
27 // Calls ConenctTo() to connect |peer1| and |peer2|. Both |peer1| and |peer2|
28 // must belong to the current thread.
23 static void Connect(FakeSignalStrategy* peer1, FakeSignalStrategy* peer2); 29 static void Connect(FakeSignalStrategy* peer1, FakeSignalStrategy* peer2);
24 30
25 FakeSignalStrategy(const std::string& jid); 31 FakeSignalStrategy(const std::string& jid);
26 virtual ~FakeSignalStrategy(); 32 virtual ~FakeSignalStrategy();
27 33
28 const std::list<buzz::XmlElement*>& received_messages() { 34 const std::list<buzz::XmlElement*>& received_messages() {
29 return received_messages_; 35 return received_messages_;
30 } 36 }
31 37
38 // Connects current FakeSignalStrategy to receive messages from |peer|.
39 void ConnectTo(FakeSignalStrategy* peer);
40
32 // SignalStrategy interface. 41 // SignalStrategy interface.
33 virtual void Connect() OVERRIDE; 42 virtual void Connect() OVERRIDE;
34 virtual void Disconnect() OVERRIDE; 43 virtual void Disconnect() OVERRIDE;
35 virtual State GetState() const OVERRIDE; 44 virtual State GetState() const OVERRIDE;
36 virtual Error GetError() const OVERRIDE; 45 virtual Error GetError() const OVERRIDE;
37 virtual std::string GetLocalJid() const OVERRIDE; 46 virtual std::string GetLocalJid() const OVERRIDE;
38 virtual void AddListener(Listener* listener) OVERRIDE; 47 virtual void AddListener(Listener* listener) OVERRIDE;
39 virtual void RemoveListener(Listener* listener) OVERRIDE; 48 virtual void RemoveListener(Listener* listener) OVERRIDE;
40 virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE; 49 virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE;
41 virtual std::string GetNextId() OVERRIDE; 50 virtual std::string GetNextId() OVERRIDE;
42 51
43 private: 52 private:
53 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> message)>
54 PeerCallback;
55
56 static void DeliverMessageOnThread(
57 scoped_refptr<base::SingleThreadTaskRunner> thread,
58 base::WeakPtr<FakeSignalStrategy> target,
59 scoped_ptr<buzz::XmlElement> stanza);
60
44 // Called by the |peer_|. Takes ownership of |stanza|. 61 // Called by the |peer_|. Takes ownership of |stanza|.
45 void OnIncomingMessage(scoped_ptr<buzz::XmlElement> stanza); 62 void OnIncomingMessage(scoped_ptr<buzz::XmlElement> stanza);
63 void SetPeerCallback(const PeerCallback& peer_callback);
46 64
47 void DeliverIncomingMessages(); 65 scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
48 66
49 std::string jid_; 67 std::string jid_;
50 FakeSignalStrategy* peer_; 68 PeerCallback peer_callback_;
51 ObserverList<Listener, true> listeners_; 69 ObserverList<Listener, true> listeners_;
52 70
53 int last_id_; 71 int last_id_;
54 72
55 // All received messages, includes thouse still in |pending_messages_|. 73 // All received messages, includes thouse still in |pending_messages_|.
56 std::list<buzz::XmlElement*> received_messages_; 74 std::list<buzz::XmlElement*> received_messages_;
57 75
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_; 76 base::WeakPtrFactory<FakeSignalStrategy> weak_factory_;
62 77
63 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy); 78 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy);
64 }; 79 };
65 80
66 } // namespace remoting 81 } // namespace remoting
67 82
68 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ 83 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/signaling/fake_signal_strategy.cc » ('j') | remoting/signaling/fake_signal_strategy.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698