summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-29 21:56:37 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-29 21:56:37 +0000
commita9cf9e79c9ffc3c3fe9c87f7c0bd64a8fcdf65dc (patch)
treeba2c9650c1efc1d6904cf76ecaf50629d5aa3f01 /remoting
parent3845246ab4ba3ef17e1979ef8c70d092d8dd4985 (diff)
downloadchromium_src-a9cf9e79c9ffc3c3fe9c87f7c0bd64a8fcdf65dc.zip
chromium_src-a9cf9e79c9ffc3c3fe9c87f7c0bd64a8fcdf65dc.tar.gz
chromium_src-a9cf9e79c9ffc3c3fe9c87f7c0bd64a8fcdf65dc.tar.bz2
Don't use base::OneShotTimer on plugin main thread.
BUG=90785 TEST=plugin doesn't crash Review URL: http://codereview.chromium.org/7538002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/chromoting_host_context.cc15
-rw-r--r--remoting/host/chromoting_host_context.h8
-rw-r--r--remoting/host/desktop_environment.cc45
-rw-r--r--remoting/host/desktop_environment.h16
-rw-r--r--remoting/host/plugin/host_script_object.cc8
5 files changed, 58 insertions, 34 deletions
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index 93259dd..66276a3 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/bind.h"
#include "base/threading/thread.h"
#include "remoting/jingle_glue/jingle_thread.h"
@@ -62,11 +63,23 @@ void ChromotingHostContext::SetUITaskPostFunction(const base::Callback<void(
ui_main_thread_id_ = base::PlatformThread::CurrentId();
}
-void ChromotingHostContext::PostToUIThread(
+void ChromotingHostContext::PostTaskToUIThread(
const tracked_objects::Location& from_here, Task* task) {
ui_poster_.Run(from_here, task);
}
+void ChromotingHostContext::PostDelayedTaskToUIThread(
+ const tracked_objects::Location& from_here,
+ Task* task,
+ int delay_ms) {
+ // Post delayed task on the main thread that will post task on UI
+ // thread. It is safe to use base::Unretained() here because
+ // ChromotingHostContext owns |main_thread_|.
+ main_message_loop()->PostDelayedTask(from_here, base::Bind(
+ &ChromotingHostContext::PostTaskToUIThread, base::Unretained(this),
+ from_here, task), delay_ms);
+}
+
bool ChromotingHostContext::IsUIThread() const {
return ui_main_thread_id_ == base::PlatformThread::CurrentId();
}
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 3f54eb7..65ed6ae 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -47,7 +47,11 @@ class ChromotingHostContext {
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);
+ void PostTaskToUIThread(const tracked_objects::Location& from_here,
+ Task* task);
+ void PostDelayedTaskToUIThread(const tracked_objects::Location& from_here,
+ Task* task,
+ int delay_ms);
bool IsUIThread() const;
private:
@@ -77,6 +81,4 @@ class ChromotingHostContext {
} // namespace remoting
-DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::ChromotingHostContext);
-
#endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc
index e13ac2f..848029f 100644
--- a/remoting/host/desktop_environment.cc
+++ b/remoting/host/desktop_environment.cc
@@ -15,7 +15,7 @@
#include "remoting/host/event_executor.h"
#include "remoting/host/local_input_monitor.h"
-static const int kContinueWindowTimeoutSecs = 10 * 60;
+static const int kContinueWindowTimeoutMs = 10 * 60 * 1000;
namespace remoting {
@@ -34,13 +34,23 @@ class UIThreadProxy : public base::RefCountedThreadSafe<UIThreadProxy> {
context_ = NULL;
}
- void CallOnUIThread(const base::Closure& closure) {
+ void CallOnUIThread(const tracked_objects::Location& from_here,
+ const base::Closure& closure) {
if (context_) {
- context_->PostToUIThread(FROM_HERE, NewRunnableMethod(
+ context_->PostTaskToUIThread(from_here, NewRunnableMethod(
this, &UIThreadProxy::CallClosure, closure));
}
}
+ void CallOnUIThreadDelayed(const tracked_objects::Location& from_here,
+ const base::Closure& closure,
+ int delay_ms) {
+ if (context_) {
+ context_->PostDelayedTaskToUIThread(from_here, NewRunnableMethod(
+ this, &UIThreadProxy::CallClosure, closure), delay_ms);
+ }
+ }
+
private:
friend class base::RefCountedThreadSafe<UIThreadProxy>;
@@ -87,6 +97,7 @@ DesktopEnvironment::DesktopEnvironment(ChromotingHostContext* context,
continue_window_(continue_window),
local_input_monitor_(local_input_monitor),
is_monitoring_local_inputs_(false),
+ continue_timer_started_(false),
proxy_(new UIThreadProxy(context)) {
}
@@ -105,17 +116,17 @@ void DesktopEnvironment::Shutdown() {
}
void DesktopEnvironment::OnConnect(const std::string& username) {
- proxy_->CallOnUIThread(base::Bind(
+ proxy_->CallOnUIThread(FROM_HERE, base::Bind(
&DesktopEnvironment::ProcessOnConnect, base::Unretained(this), username));
}
void DesktopEnvironment::OnLastDisconnect() {
- proxy_->CallOnUIThread(base::Bind(
+ proxy_->CallOnUIThread(FROM_HERE, base::Bind(
&DesktopEnvironment::ProcessOnLastDisconnect, base::Unretained(this)));
}
void DesktopEnvironment::OnPause(bool pause) {
- proxy_->CallOnUIThread(base::Bind(
+ proxy_->CallOnUIThread(FROM_HERE, base::Bind(
&DesktopEnvironment::ProcessOnPause, base::Unretained(this), pause));
}
@@ -177,20 +188,26 @@ void DesktopEnvironment::ShowContinueWindow(bool show) {
void DesktopEnvironment::StartContinueWindowTimer(bool start) {
DCHECK(context_->IsUIThread());
- if (continue_window_timer_.IsRunning() == start)
- return;
- if (start) {
- continue_window_timer_.Start(
- base::TimeDelta::FromSeconds(kContinueWindowTimeoutSecs),
- this, &DesktopEnvironment::ContinueWindowTimerFunc);
- } else {
- continue_window_timer_.Stop();
+ if (start && ! continue_timer_started_) {
+ continue_timer_target_time_ = base::Time::Now() +
+ base::TimeDelta::FromMilliseconds(kContinueWindowTimeoutMs);
+ proxy_->CallOnUIThreadDelayed(
+ FROM_HERE, base::Bind(&DesktopEnvironment::ContinueWindowTimerFunc,
+ base::Unretained(this)),
+ kContinueWindowTimeoutMs);
}
+
+ continue_timer_started_ = start;
}
void DesktopEnvironment::ContinueWindowTimerFunc() {
DCHECK(context_->IsUIThread());
+ // This function may be called prematurely if timer was stopped and
+ // then started again. In that case we just ignore this call.
+ if (continue_timer_target_time_ > base::Time::Now())
+ return;
+
host_->PauseSession(true);
ShowContinueWindow(true);
}
diff --git a/remoting/host/desktop_environment.h b/remoting/host/desktop_environment.h
index 99fd33d..a08aca10 100644
--- a/remoting/host/desktop_environment.h
+++ b/remoting/host/desktop_environment.h
@@ -8,8 +8,9 @@
#include <string>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/timer.h"
+#include "base/time.h"
namespace remoting {
@@ -103,16 +104,9 @@ class DesktopEnvironment {
bool is_monitoring_local_inputs_;
- // Timer controlling the "continue session" dialog. The timer is started when
- // a connection is made or re-confirmed. On expiry, inputs to the host are
- // blocked and the dialog is shown.
- //
- // TODO(sergeyu): It is wrong that we use OneShotTimer on the UI
- // thread of the plugin. UI thread runs MessageLoop that is compiled
- // as part of chrome, but the timer compiled as part of the
- // plugin. This will crash when plugin and chrome are compiled with
- // different version of MessageLoop. See crbug.com/90785 .
- base::OneShotTimer<DesktopEnvironment> continue_window_timer_;
+ // Timer controlling the "continue session" dialog.
+ bool continue_timer_started_;
+ base::Time continue_timer_target_time_;
scoped_refptr<UIThreadProxy> proxy_;
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index d133e3c..7ff1707 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -476,7 +476,7 @@ void HostNPScriptObject::OnStateChanged(State state) {
return;
if (!host_context_.IsUIThread()) {
- host_context_.PostToUIThread(
+ host_context_.PostTaskToUIThread(
FROM_HERE,
NewRunnableMethod(this, &HostNPScriptObject::OnStateChanged, state));
return;
@@ -494,7 +494,7 @@ void HostNPScriptObject::LogDebugInfo(const std::string& message) {
return;
if (!host_context_.IsUIThread()) {
- host_context_.PostToUIThread(
+ host_context_.PostTaskToUIThread(
FROM_HERE,
NewRunnableMethod(this, &HostNPScriptObject::LogDebugInfo, message));
return;
@@ -531,9 +531,7 @@ void HostNPScriptObject::PostTaskToNPThread(
// appropriate signature.
// Can be called from any thread.
- g_npnetscape_funcs->pluginthreadasynccall(plugin_,
- &NPTaskSpringboard,
- task);
+ g_npnetscape_funcs->pluginthreadasynccall(plugin_, &NPTaskSpringboard, task);
}
// static