OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
5 | 6 |
6 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" |
7 #include "remoting/client/plugin/chromoting_scriptable_object.h" | 9 #include "remoting/client/plugin/chromoting_scriptable_object.h" |
8 #include "remoting/client/plugin/pepper_util.h" | 10 #include "remoting/client/plugin/pepper_util.h" |
9 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | |
10 | 11 |
11 namespace remoting { | 12 namespace remoting { |
12 | 13 |
13 PepperXmppProxy::PepperXmppProxy( | 14 PepperXmppProxy::PepperXmppProxy( |
14 base::WeakPtr<ChromotingScriptableObject> scriptable_object, | 15 base::WeakPtr<ChromotingScriptableObject> scriptable_object, |
15 MessageLoop* callback_message_loop) | 16 base::MessageLoopProxy* callback_message_loop) |
16 : scriptable_object_(scriptable_object), | 17 : scriptable_object_(scriptable_object), |
17 callback_message_loop_(callback_message_loop) { | 18 callback_message_loop_(callback_message_loop) { |
18 CHECK(CurrentlyOnPluginThread()); | 19 CHECK(CurrentlyOnPluginThread()); |
19 } | 20 } |
20 | 21 |
21 PepperXmppProxy::~PepperXmppProxy() { | 22 PepperXmppProxy::~PepperXmppProxy() { |
22 } | 23 } |
23 | 24 |
24 void PepperXmppProxy::AttachCallback(base::WeakPtr<ResponseCallback> callback) { | 25 void PepperXmppProxy::AttachCallback(base::WeakPtr<ResponseCallback> callback) { |
25 CHECK_EQ(callback_message_loop_, MessageLoop::current()); | 26 DCHECK(callback_message_loop_->BelongsToCurrentThread()); |
26 callback_ = callback; | 27 callback_ = callback; |
27 } | 28 } |
28 | 29 |
29 void PepperXmppProxy::DetachCallback() { | 30 void PepperXmppProxy::DetachCallback() { |
30 callback_.reset(); | 31 callback_.reset(); |
31 } | 32 } |
32 | 33 |
33 void PepperXmppProxy::SendIq(const std::string& request_xml) { | 34 void PepperXmppProxy::SendIq(const std::string& request_xml) { |
34 if (!CurrentlyOnPluginThread()) { | 35 if (!CurrentlyOnPluginThread()) { |
35 RunTaskOnPluginThread(NewRunnableMethod(this, | 36 RunTaskOnPluginThread(NewRunnableMethod(this, |
36 &PepperXmppProxy::SendIq, | 37 &PepperXmppProxy::SendIq, |
37 request_xml)); | 38 request_xml)); |
38 return; | 39 return; |
39 } | 40 } |
40 | 41 |
41 if (scriptable_object_) { | 42 if (scriptable_object_) { |
42 scriptable_object_->SendIq(request_xml); | 43 scriptable_object_->SendIq(request_xml); |
43 } | 44 } |
44 } | 45 } |
45 | 46 |
46 void PepperXmppProxy::OnIq(const std::string& response_xml) { | 47 void PepperXmppProxy::OnIq(const std::string& response_xml) { |
47 if (MessageLoop::current() != callback_message_loop_) { | 48 if (!callback_message_loop_->BelongsToCurrentThread()) { |
48 callback_message_loop_->PostTask( | 49 callback_message_loop_->PostTask( |
49 FROM_HERE,NewRunnableMethod(this, | 50 FROM_HERE,NewRunnableMethod(this, |
50 &PepperXmppProxy::OnIq, | 51 &PepperXmppProxy::OnIq, |
51 response_xml)); | 52 response_xml)); |
52 return; | 53 return; |
53 } | 54 } |
54 | 55 |
55 if (callback_) { | 56 if (callback_) { |
56 callback_->OnIq(response_xml); | 57 callback_->OnIq(response_xml); |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 } // namespace remoting | 61 } // namespace remoting |
OLD | NEW |