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/memory/weak_ptr.h" |
11 #include "base/observer_list_threadsafe.h" | |
11 #include "remoting/signaling/signal_strategy.h" | 12 #include "remoting/signaling/signal_strategy.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 class SingleThreadTaskRunner; | 15 class SingleThreadTaskRunner; |
15 } // namespace base | 16 } // namespace base |
16 | 17 |
17 namespace remoting { | 18 namespace remoting { |
18 | 19 |
20 // A signaling strategy class that delegates IQ sending and receiving. | |
21 // | |
22 // Notes on thread safety: | |
23 // 1. This object can be created on any thread. | |
24 // 2. OnIncomingMessage() and |send_iq_callback| will always be called on the | |
Sergey Ulanov
2016/10/06 18:28:57
Suggest separating this statement into two. |send_
kelvinp
2016/10/06 20:30:28
Done.
| |
25 // thread that it is created on. Note that |send_iq_callback| may be called | |
26 // after the instance is destroyed. | |
27 // 3. The caller should invoke all methods on the |client_task_runner|. | |
Sergey Ulanov
2016/10/06 18:28:57
Maybe rephrase this as "SignalStrategy interface m
kelvinp
2016/10/06 20:30:28
Done.
| |
28 // 4. All listeners will be called on |client_task_runner| as well. | |
29 // 5. The destructor should always be called on the |client_task_runner|. | |
19 class DelegatingSignalStrategy : public SignalStrategy { | 30 class DelegatingSignalStrategy : public SignalStrategy { |
20 public: | 31 public: |
21 typedef base::Callback<void(const std::string&)> SendIqCallback; | 32 typedef base::Callback<void(const std::string&)> SendIqCallback; |
22 | 33 |
23 DelegatingSignalStrategy(std::string local_jid, | 34 DelegatingSignalStrategy( |
24 const SendIqCallback& send_iq_callback); | 35 std::string local_jid, |
36 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner, | |
37 const SendIqCallback& send_iq_callback); | |
25 ~DelegatingSignalStrategy() override; | 38 ~DelegatingSignalStrategy() override; |
26 | 39 |
27 void OnIncomingMessage(const std::string& message); | 40 void OnIncomingMessage(const std::string& message); |
28 | 41 |
29 // SignalStrategy interface. | 42 // SignalStrategy interface. |
30 void Connect() override; | 43 void Connect() override; |
31 void Disconnect() override; | 44 void Disconnect() override; |
32 State GetState() const override; | 45 State GetState() const override; |
33 Error GetError() const override; | 46 Error GetError() const override; |
34 std::string GetLocalJid() const override; | 47 std::string GetLocalJid() const override; |
35 void AddListener(Listener* listener) override; | 48 void AddListener(Listener* listener) override; |
36 void RemoveListener(Listener* listener) override; | 49 void RemoveListener(Listener* listener) override; |
37 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; | 50 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; |
38 std::string GetNextId() override; | 51 std::string GetNextId() override; |
39 | 52 |
40 private: | 53 private: |
41 std::string local_jid_; | 54 std::string local_jid_; |
55 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; | |
56 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; | |
57 | |
42 SendIqCallback send_iq_callback_; | 58 SendIqCallback send_iq_callback_; |
59 base::ObserverList<Listener> listeners_; | |
43 | 60 |
44 base::ObserverList<Listener> listeners_; | 61 base::WeakPtrFactory<DelegatingSignalStrategy> weak_factory_; |
45 | 62 |
46 DISALLOW_COPY_AND_ASSIGN(DelegatingSignalStrategy); | 63 DISALLOW_COPY_AND_ASSIGN(DelegatingSignalStrategy); |
47 }; | 64 }; |
48 | 65 |
49 } // namespace remoting | 66 } // namespace remoting |
50 | 67 |
51 #endif // REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ | 68 #endif // REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ |
OLD | NEW |