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
3 // found in the LICENSE file.
5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "remoting/jingle_glue/xmpp_proxy.h"
14 class SingleThreadTaskRunner
;
19 class PepperXmppProxy
: public XmppProxy
{
21 typedef base::Callback
<void(const std::string
&)> SendIqCallback
;
23 // |plugin_task_runner| is the thread on which |send_iq_callback| is
24 // called. Normally the callback will call JavaScript, so this has
25 // to be the task runner that corresponds to the plugin
26 // thread. |callback_task_runner| is used to call the callback
27 // registered with AttachCallback().
29 const SendIqCallback
& send_iq_callback
,
30 base::SingleThreadTaskRunner
* plugin_task_runner
,
31 base::SingleThreadTaskRunner
* callback_task_runner
);
33 // Registered the callback class with this object.
35 // - This method has subtle thread semantics! -
37 // It must be called on the callback thread itself. The weak pointer also
38 // must be constructed on the callback thread. That means, you cannot just
39 // create a WeakPtr on, say the pepper thread, and then pass execution of
40 // this function callback with the weak pointer bound as a parameter. That
41 // will fail because the WeakPtr will have been created on the wrong thread.
42 virtual void AttachCallback(
43 base::WeakPtr
<ResponseCallback
> callback
) OVERRIDE
;
44 virtual void DetachCallback() OVERRIDE
;
46 virtual void SendIq(const std::string
& request_xml
) OVERRIDE
;
47 virtual void OnIq(const std::string
& response_xml
);
50 virtual ~PepperXmppProxy();
52 SendIqCallback send_iq_callback_
;
54 scoped_refptr
<base::SingleThreadTaskRunner
> plugin_task_runner_
;
55 scoped_refptr
<base::SingleThreadTaskRunner
> callback_task_runner_
;
57 // Must only be access on callback_message_loop_.
58 base::WeakPtr
<ResponseCallback
> callback_
;
60 DISALLOW_COPY_AND_ASSIGN(PepperXmppProxy
);
63 } // namespace remoting
65 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_