OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ | 5 #ifndef REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ |
6 #define REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ | 6 #define REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list_threadsafe.h" |
11 #include "remoting/signaling/signal_strategy.h" | 11 #include "remoting/signaling/signal_strategy.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class SingleThreadTaskRunner; | 14 class SingleThreadTaskRunner; |
15 } // namespace base | 15 } // namespace base |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 | 18 |
19 // A signaling strategy class that delegates IQ sending and receiving. | |
20 // | |
21 // Notes on thread safety: | |
22 // 1. This object can be created on any thread. | |
23 // 2. |OnIncomingMessage| and |send_iq_callback| will always be called in | |
Sergey Ulanov
2016/10/05 21:49:07
s/|OnIncomingMessage|/OnIncomingMessage()/
Sergey Ulanov
2016/10/05 21:49:07
Also please note that |send_iq_callback| may be ca
kelvinp
2016/10/06 00:43:05
Done.
kelvinp
2016/10/06 00:43:05
Done.
| |
24 // |delegate_task_runner|. | |
25 // 3. The caller should invoke all methods on the |client_task_runner|. | |
26 // 4. All listeners will be called on |client_task_runner| as well. | |
27 // 5. The destructor should always be called on the |client_task_runner|. | |
19 class DelegatingSignalStrategy : public SignalStrategy { | 28 class DelegatingSignalStrategy : public SignalStrategy { |
20 public: | 29 public: |
21 typedef base::Callback<void(const std::string&)> SendIqCallback; | 30 typedef base::Callback<void(const std::string&)> SendIqCallback; |
22 | 31 |
23 DelegatingSignalStrategy(std::string local_jid, | 32 DelegatingSignalStrategy( |
24 const SendIqCallback& send_iq_callback); | 33 std::string local_jid, |
34 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner, | |
Sergey Ulanov
2016/10/05 21:49:07
This class is always created on delegate_task_runn
kelvinp
2016/10/06 00:43:06
Done.
| |
35 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner, | |
36 const SendIqCallback& send_iq_callback); | |
25 ~DelegatingSignalStrategy() override; | 37 ~DelegatingSignalStrategy() override; |
26 | 38 |
27 void OnIncomingMessage(const std::string& message); | 39 void OnIncomingMessage(const std::string& message); |
28 | 40 |
29 // SignalStrategy interface. | 41 // SignalStrategy interface. |
30 void Connect() override; | 42 void Connect() override; |
31 void Disconnect() override; | 43 void Disconnect() override; |
32 State GetState() const override; | 44 State GetState() const override; |
33 Error GetError() const override; | 45 Error GetError() const override; |
34 std::string GetLocalJid() const override; | 46 std::string GetLocalJid() const override; |
35 void AddListener(Listener* listener) override; | 47 void AddListener(Listener* listener) override; |
36 void RemoveListener(Listener* listener) override; | 48 void RemoveListener(Listener* listener) override; |
37 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; | 49 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; |
38 std::string GetNextId() override; | 50 std::string GetNextId() override; |
39 | 51 |
40 private: | 52 private: |
41 std::string local_jid_; | 53 std::string local_jid_; |
54 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; | |
55 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; | |
56 | |
42 SendIqCallback send_iq_callback_; | 57 SendIqCallback send_iq_callback_; |
43 | |
44 base::ObserverList<Listener> listeners_; | 58 base::ObserverList<Listener> listeners_; |
45 | 59 |
46 DISALLOW_COPY_AND_ASSIGN(DelegatingSignalStrategy); | 60 DISALLOW_COPY_AND_ASSIGN(DelegatingSignalStrategy); |
47 }; | 61 }; |
48 | 62 |
49 } // namespace remoting | 63 } // namespace remoting |
50 | 64 |
51 #endif // REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ | 65 #endif // REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ |
OLD | NEW |