diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-15 19:05:57 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-15 19:05:57 +0000 |
commit | f91ac539016dec3faca1c47f7a27bec56f6fdf79 (patch) | |
tree | 6594c928db19687db1ac46acbe7c56f4da900a4b /remoting/host | |
parent | 49ba482a3a248c7cd4556b49ed601cda1e82aa9f (diff) | |
download | chromium_src-f91ac539016dec3faca1c47f7a27bec56f6fdf79.zip chromium_src-f91ac539016dec3faca1c47f7a27bec56f6fdf79.tar.gz chromium_src-f91ac539016dec3faca1c47f7a27bec56f6fdf79.tar.bz2 |
Run DisconnectWindow::Show/Hide on correct thread.
This is to ensure that the DisconnectWindow UI actions are carried out on the
proper thread for making platform-native GUI API calls (for example, GTK on
Linux).
BUG=None
TEST=Manual
Review URL: http://codereview.chromium.org/7144010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/chromoting_host.cc | 4 | ||||
-rw-r--r-- | remoting/host/chromoting_host_context.cc | 15 | ||||
-rw-r--r-- | remoting/host/chromoting_host_context.h | 21 | ||||
-rw-r--r-- | remoting/host/host_plugin.cc | 20 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 6 |
5 files changed, 58 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/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"); |