summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/chromoting_host.cc4
-rw-r--r--remoting/host/chromoting_host_context.cc15
-rw-r--r--remoting/host/chromoting_host_context.h21
-rw-r--r--remoting/host/chromoting_host_unittest.cc5
-rw-r--r--remoting/host/host_plugin.cc20
-rw-r--r--remoting/host/simple_host_process.cc6
6 files changed, 63 insertions, 8 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 36a1b45..ace4f71 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -547,8 +547,8 @@ void ChromotingHost::ProcessPreAuthentication(
void ChromotingHost::ShowDisconnectWindow(bool show,
const std::string& username) {
- if (context_->ui_message_loop() != MessageLoop::current()) {
- context_->ui_message_loop()->PostTask(
+ if (!context_->IsUIThread()) {
+ context_->PostToUIThread(
FROM_HERE,
NewRunnableMethod(this, &ChromotingHost::ShowDisconnectWindow,
show, username));
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index b1d9837..bc3601e 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -56,4 +56,19 @@ MessageLoop* ChromotingHostContext::ui_message_loop() {
return ui_thread_.message_loop();
}
+void ChromotingHostContext::SetUITaskPostFunction(const base::Callback<void(
+ const tracked_objects::Location& from_here, Task* task)>& poster) {
+ ui_poster_ = poster;
+ ui_main_thread_id_ = base::PlatformThread::CurrentId();
+}
+
+void ChromotingHostContext::PostToUIThread(
+ const tracked_objects::Location& from_here, Task* task) {
+ ui_poster_.Run(from_here, task);
+}
+
+bool ChromotingHostContext::IsUIThread() const {
+ return ui_main_thread_id_ == base::PlatformThread::CurrentId();
+}
+
} // namespace remoting
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 609da46..4efcb3d 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -7,10 +7,18 @@
#include <string>
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
+#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "remoting/jingle_glue/jingle_thread.h"
+class Task;
+
+namespace tracked_objects {
+class Location;
+}
+
namespace remoting {
// A class that manages threads and running context for the chromoting host
@@ -35,6 +43,13 @@ class ChromotingHostContext {
virtual MessageLoop* network_message_loop();
virtual MessageLoop* ui_message_loop();
+ // Must be called from the main GUI thread.
+ void SetUITaskPostFunction(const base::Callback<void(
+ const tracked_objects::Location& from_here, Task* task)>& poster);
+
+ void PostToUIThread(const tracked_objects::Location& from_here, Task* task);
+ bool IsUIThread() const;
+
private:
FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop);
@@ -51,6 +66,12 @@ class ChromotingHostContext {
// This is NOT a Chrome-style UI thread.
base::Thread ui_thread_;
+ base::Callback<void(const tracked_objects::Location& from_here, Task* task)>
+ ui_poster_;
+ // This IS the main Chrome GUI thread that |ui_poster_| will post to.
+ base::PlatformThreadId ui_main_thread_id_;
+
+
DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
};
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
index bcaaf02..9f1e2e5 100644
--- a/remoting/host/chromoting_host_unittest.cc
+++ b/remoting/host/chromoting_host_unittest.cc
@@ -86,6 +86,11 @@ class ChromotingHostTest : public testing::Test {
EXPECT_CALL(context_, ui_message_loop())
.Times(AnyNumber());
+ context_.SetUITaskPostFunction(base::Bind(
+ static_cast<void(MessageLoop::*)(
+ const tracked_objects::Location&, Task*)>(&MessageLoop::PostTask),
+ base::Unretained(&message_loop_)));
+
Capturer* capturer = new CapturerFake();
event_executor_ = new MockEventExecutor();
curtain_ = new MockCurtain();
diff --git a/remoting/host/host_plugin.cc b/remoting/host/host_plugin.cc
index fd8ea75c..11b621e 100644
--- a/remoting/host/host_plugin.cc
+++ b/remoting/host/host_plugin.cc
@@ -140,6 +140,8 @@ class HostNPScriptObject {
on_state_changed_func_(NULL),
np_thread_id_(base::PlatformThread::CurrentId()) {
LOG(INFO) << "HostNPScriptObject";
+ host_context_.SetUITaskPostFunction(base::Bind(
+ &HostNPScriptObject::PostTaskToNPThread, base::Unretained(this)));
}
~HostNPScriptObject() {
@@ -364,7 +366,8 @@ class HostNPScriptObject {
NPVariant* result);
// Posts a task on the main NP thread.
- void PostTaskToNPThread(Task* task);
+ void PostTaskToNPThread(const tracked_objects::Location& from_here,
+ Task* task);
// Utility function for PostTaskToNPThread.
static void NPTaskSpringboard(void* task);
@@ -524,10 +527,10 @@ void HostNPScriptObject::OnHostShutdown() {
}
void HostNPScriptObject::OnStateChanged(State state) {
- if (base::PlatformThread::CurrentId() != np_thread_id_) {
- PostTaskToNPThread(NewRunnableMethod(this,
- &HostNPScriptObject::OnStateChanged,
- state));
+ if (!host_context_.IsUIThread()) {
+ host_context_.PostToUIThread(
+ FROM_HERE,
+ NewRunnableMethod(this, &HostNPScriptObject::OnStateChanged, state));
return;
}
state_ = state;
@@ -559,7 +562,12 @@ bool HostNPScriptObject::CallJSFunction(NPObject* func,
return is_good;
}
-void HostNPScriptObject::PostTaskToNPThread(Task* task) {
+void HostNPScriptObject::PostTaskToNPThread(
+ const tracked_objects::Location& from_here, Task* task) {
+ // The NPAPI functions cannot make use of |from_here|, but this method is
+ // passed as a callback to ChromotingHostContext, so it needs to have the
+ // appropriate signature.
+
// Can be called from any thread.
g_npnetscape_funcs->pluginthreadasynccall(plugin_,
&NPTaskSpringboard,
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index fc2029c..d62d49b 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -27,6 +27,7 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/mac/scoped_nsautorelease_pool.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/test/mock_chrome_application_mac.h"
#include "base/threading/thread.h"
@@ -120,6 +121,11 @@ class SimpleHost {
MessageLoop message_loop(MessageLoop::TYPE_UI);
remoting::ChromotingHostContext context;
+ // static_cast needed to resolve overloaded PostTask member-function.
+ context.SetUITaskPostFunction(base::Bind(
+ static_cast<void(MessageLoop::*)(
+ const tracked_objects::Location&, Task*)>(&MessageLoop::PostTask),
+ base::Unretained(&message_loop)));
context.Start();
base::Thread file_io_thread("FileIO");