Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_PEPPER_XMPP_PROXY_H_ | 5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ |
| 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ | 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "remoting/jingle_glue/xmpp_proxy.h" | 11 #include "remoting/jingle_glue/xmpp_proxy.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class MessageLoopProxy; | 14 class SingleThreadTaskRunner; |
| 15 } // namespace base | 15 } // namespace base |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 | 18 |
| 19 class PepperXmppProxy : public XmppProxy { | 19 class PepperXmppProxy : public XmppProxy { |
| 20 public: | 20 public: |
| 21 typedef base::Callback<void(const std::string&)> SendIqCallback; | 21 typedef base::Callback<void(const std::string&)> SendIqCallback; |
| 22 | 22 |
| 23 PepperXmppProxy( | 23 PepperXmppProxy( |
| 24 const SendIqCallback& send_iq_callback, | 24 const SendIqCallback& send_iq_callback, |
| 25 base::MessageLoopProxy* plugin_message_loop, | 25 base::SingleThreadTaskRunner* plugin_task_runner, |
| 26 base::MessageLoopProxy* callback_message_loop); | 26 base::SingleThreadTaskRunner* callback_task_runner); |
|
Wez
2012/05/26 00:18:40
nit: scoped_refptr<>?
Wez
2012/05/26 00:18:40
nit: Clarify the roles of the two TaskRunners.
Sergey Ulanov
2012/05/30 01:07:07
Will fix in a separate CL.
Sergey Ulanov
2012/05/30 01:07:07
Done.
| |
| 27 | 27 |
| 28 // Registered the callback class with this object. | 28 // Registered the callback class with this object. |
| 29 // | 29 // |
| 30 // - This method has subtle thread semantics! - | 30 // - This method has subtle thread semantics! - |
| 31 // | 31 // |
| 32 // It must be called on the callback thread itself. The weak pointer also | 32 // It must be called on the callback thread itself. The weak pointer also |
| 33 // must be constructed on the callback thread. That means, you cannot just | 33 // must be constructed on the callback thread. That means, you cannot just |
| 34 // create a WeakPtr on, say the pepper thread, and then pass execution of | 34 // create a WeakPtr on, say the pepper thread, and then pass execution of |
| 35 // this function callback with the weak pointer bound as a parameter. That | 35 // this function callback with the weak pointer bound as a parameter. That |
| 36 // will fail because the WeakPtr will have been created on the wrong thread. | 36 // will fail because the WeakPtr will have been created on the wrong thread. |
| 37 virtual void AttachCallback( | 37 virtual void AttachCallback( |
| 38 base::WeakPtr<ResponseCallback> callback) OVERRIDE; | 38 base::WeakPtr<ResponseCallback> callback) OVERRIDE; |
| 39 virtual void DetachCallback() OVERRIDE; | 39 virtual void DetachCallback() OVERRIDE; |
| 40 | 40 |
| 41 virtual void SendIq(const std::string& request_xml) OVERRIDE; | 41 virtual void SendIq(const std::string& request_xml) OVERRIDE; |
| 42 virtual void OnIq(const std::string& response_xml); | 42 virtual void OnIq(const std::string& response_xml); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 virtual ~PepperXmppProxy(); | 45 virtual ~PepperXmppProxy(); |
| 46 | 46 |
| 47 SendIqCallback send_iq_callback_; | 47 SendIqCallback send_iq_callback_; |
| 48 | 48 |
| 49 scoped_refptr<base::MessageLoopProxy> plugin_message_loop_; | 49 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; |
| 50 scoped_refptr<base::MessageLoopProxy> callback_message_loop_; | 50 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_; |
| 51 | 51 |
| 52 // Must only be access on callback_message_loop_. | 52 // Must only be access on callback_message_loop_. |
| 53 base::WeakPtr<ResponseCallback> callback_; | 53 base::WeakPtr<ResponseCallback> callback_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(PepperXmppProxy); | 55 DISALLOW_COPY_AND_ASSIGN(PepperXmppProxy); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } // namespace remoting | 58 } // namespace remoting |
| 59 | 59 |
| 60 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ | 60 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_ |
| OLD | NEW |