Chromium Code Reviews| 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/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list_threadsafe.h" | 11 #include "base/observer_list_threadsafe.h" |
| 12 #include "remoting/signaling/signal_strategy.h" | 12 #include "remoting/signaling/signal_strategy.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class SingleThreadTaskRunner; | 15 class SingleThreadTaskRunner; |
| 16 } // namespace base | 16 } // namespace base |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 // A signaling strategy class that delegates IQ sending and receiving. | 20 // A signaling strategy class that delegates IQ sending and receiving. |
| 21 // | 21 // |
| 22 // Notes on thread safety: | 22 // Notes on thread safety: |
| 23 // 1. This object can be created on any thread. | 23 // 1. This object can be created on any thread. |
| 24 // 2. OnIncomingMessage() must be called on the same thread on which this object | 24 // 2. |send_iq_callback| will always be called on the thread that it is created. |
| 25 // is created. | |
| 26 // 3. |send_iq_callback| will always be called on the thread that it is created. | |
| 27 // Note that |send_iq_callback| may be called after this object is destroyed. | 25 // Note that |send_iq_callback| may be called after this object is destroyed. |
| 28 // 4. The caller should invoke all methods on the SignalStrategy interface on | 26 // 3. The caller should invoke all methods on the SignalStrategy interface on |
| 29 // the |client_task_runner|. | 27 // the |client_task_runner|. |
| 30 // 5. All listeners will be called on |client_task_runner| as well. | 28 // 4. All listeners will be called on |client_task_runner| as well. |
| 31 // 6. The destructor should always be called on the |client_task_runner|. | 29 // 5. The destructor should always be called on the |client_task_runner|. |
| 30 // 6. As a result of (5), use MakeIncomingMessageCallback() to obtain a callback | |
| 31 // when passing incoming signaling messages from the delegate. | |
| 32 class DelegatingSignalStrategy : public SignalStrategy { | 32 class DelegatingSignalStrategy : public SignalStrategy { |
| 33 public: | 33 public: |
| 34 typedef base::Callback<void(const std::string&)> SendIqCallback; | 34 typedef base::Callback<void(const std::string&)> IqCallback; |
|
Sergey Ulanov
2017/03/14 19:20:59
Please use base::RepeatingCallback instead of base
kelvinp
2017/03/15 21:56:46
Done.
| |
| 35 | 35 |
| 36 DelegatingSignalStrategy( | 36 DelegatingSignalStrategy( |
| 37 std::string local_jid, | 37 std::string local_jid, |
| 38 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner, | 38 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner, |
| 39 const SendIqCallback& send_iq_callback); | 39 const IqCallback& send_iq_callback); |
| 40 ~DelegatingSignalStrategy() override; | 40 ~DelegatingSignalStrategy() override; |
| 41 | 41 |
| 42 void OnIncomingMessage(const std::string& message); | 42 IqCallback MakeIncomingMessageCallback(); |
|
Sergey Ulanov
2017/03/14 19:20:59
s/Make/Get/
(potentially this function could just
| |
| 43 | 43 |
| 44 // SignalStrategy interface. | 44 // SignalStrategy interface. |
| 45 void Connect() override; | 45 void Connect() override; |
| 46 void Disconnect() override; | 46 void Disconnect() override; |
| 47 State GetState() const override; | 47 State GetState() const override; |
| 48 Error GetError() const override; | 48 Error GetError() const override; |
| 49 std::string GetLocalJid() const override; | 49 std::string GetLocalJid() const override; |
| 50 void AddListener(Listener* listener) override; | 50 void AddListener(Listener* listener) override; |
| 51 void RemoveListener(Listener* listener) override; | 51 void RemoveListener(Listener* listener) override; |
| 52 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; | 52 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; |
| 53 std::string GetNextId() override; | 53 std::string GetNextId() override; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 static void OnIncomingMessageFromDelegate( | |
| 57 base::WeakPtr<DelegatingSignalStrategy> weak_ptr, | |
| 58 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner, | |
| 59 const std::string& message); | |
| 60 | |
| 61 void OnIncomingMessage(const std::string& message); | |
| 62 | |
| 56 std::string local_jid_; | 63 std::string local_jid_; |
| 57 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; | 64 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; |
| 58 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; | 65 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; |
| 59 | 66 |
| 60 SendIqCallback send_iq_callback_; | 67 IqCallback send_iq_callback_; |
| 61 base::ObserverList<Listener> listeners_; | 68 base::ObserverList<Listener> listeners_; |
| 62 | 69 |
| 63 base::WeakPtrFactory<DelegatingSignalStrategy> weak_factory_; | 70 base::WeakPtrFactory<DelegatingSignalStrategy> weak_factory_; |
| 64 | 71 |
| 65 DISALLOW_COPY_AND_ASSIGN(DelegatingSignalStrategy); | 72 DISALLOW_COPY_AND_ASSIGN(DelegatingSignalStrategy); |
| 66 }; | 73 }; |
| 67 | 74 |
| 68 } // namespace remoting | 75 } // namespace remoting |
| 69 | 76 |
| 70 #endif // REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ | 77 #endif // REMOTING_CLIENT_PLUGIN_DELEGATING_SIGNAL_STRATEGY_H_ |
| OLD | NEW |