summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-21 04:14:03 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-21 04:14:03 +0000
commitbf974e15691b9a0477b776faafe426eeed271685 (patch)
tree5e29cdae3da6b699992012555a6b6a4d4988f0fa /remoting
parent0b5364316686f5c99e708ae2801eef13d0cddbcb (diff)
downloadchromium_src-bf974e15691b9a0477b776faafe426eeed271685.zip
chromium_src-bf974e15691b9a0477b776faafe426eeed271685.tar.gz
chromium_src-bf974e15691b9a0477b776faafe426eeed271685.tar.bz2
Always show continue window.
Problem was that the timer function was checking Time::Now() to verify whether it should run or not. On some systems the task may be called several milliseconds before the target time, which means that Time::Now() would return time before |continue_timer_target_time_| and the window wouldn't show. BUG=100729 TEST=Continue windows shows every time. Review URL: http://codereview.chromium.org/8366011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106672 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/desktop_environment.cc72
-rw-r--r--remoting/host/desktop_environment.h12
2 files changed, 39 insertions, 45 deletions
diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc
index 3f1bf89..d891fe6 100644
--- a/remoting/host/desktop_environment.cc
+++ b/remoting/host/desktop_environment.cc
@@ -24,6 +24,19 @@ static const int kContinueWindowHideTimeoutMs = 60 * 1000;
namespace remoting {
+class DesktopEnvironment::TimerTask {
+ public:
+ TimerTask(base::MessageLoopProxy* message_loop,
+ const base::Closure& task,
+ int delay_ms)
+ : thread_proxy_(message_loop) {
+ thread_proxy_.PostDelayedTask(FROM_HERE, task, delay_ms);
+ }
+
+ private:
+ ScopedThreadProxy thread_proxy_;
+};
+
// static
DesktopEnvironment* DesktopEnvironment::Create(ChromotingHostContext* context) {
scoped_ptr<Capturer> capturer(Capturer::Create());
@@ -67,7 +80,6 @@ DesktopEnvironment::DesktopEnvironment(ChromotingHostContext* context,
continue_window_(continue_window),
local_input_monitor_(local_input_monitor),
is_monitoring_local_inputs_(false),
- continue_timer_state_(INACTIVE),
ui_thread_proxy_(context->ui_message_loop()) {
}
@@ -119,7 +131,7 @@ void DesktopEnvironment::ProcessOnLastDisconnect() {
void DesktopEnvironment::ProcessOnPause(bool pause) {
if (!pause) {
- continue_timer_state_ = INACTIVE;
+ timer_task_.reset();
StartContinueWindowTimer(true);
}
}
@@ -161,50 +173,36 @@ void DesktopEnvironment::ShowContinueWindow(bool show) {
void DesktopEnvironment::StartContinueWindowTimer(bool start) {
DCHECK(context_->ui_message_loop()->BelongsToCurrentThread());
- if (start && continue_timer_state_ == INACTIVE) {
- continue_timer_target_time_ = base::Time::Now() +
- base::TimeDelta::FromMilliseconds(kContinueWindowShowTimeoutMs);
- ui_thread_proxy_.PostDelayedTask(
- FROM_HERE, base::Bind(&DesktopEnvironment::ContinueWindowTimerFunc,
- base::Unretained(this)),
- kContinueWindowShowTimeoutMs);
- continue_timer_state_ = SHOW_DIALOG;
+ if (start) {
+ timer_task_.reset(new TimerTask(
+ context_->ui_message_loop(),
+ base::Bind(&DesktopEnvironment::OnContinueWindowTimer,
+ base::Unretained(this)),
+ kContinueWindowShowTimeoutMs));
} else if (!start) {
- continue_timer_state_ = INACTIVE;
+ timer_task_.reset();
}
}
-void DesktopEnvironment::ContinueWindowTimerFunc() {
+void DesktopEnvironment::OnContinueWindowTimer() {
DCHECK(context_->ui_message_loop()->BelongsToCurrentThread());
- // 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);
- switch (continue_timer_state_) {
- case INACTIVE:
- // This function will still be called, even if the timeout was cancelled.
- return;
- case SHOW_DIALOG:
- host_->PauseSession(true);
- ShowContinueWindow(true);
- continue_timer_target_time_ = base::Time::Now() +
- base::TimeDelta::FromMilliseconds(kContinueWindowHideTimeoutMs);
- ui_thread_proxy_.PostDelayedTask(
- FROM_HERE, base::Bind(&DesktopEnvironment::ContinueWindowTimerFunc,
- base::Unretained(this)),
- kContinueWindowHideTimeoutMs);
- continue_timer_state_ = SHUTDOWN_HOST;
- break;
- case SHUTDOWN_HOST:
- continue_timer_state_ = INACTIVE;
- ShowContinueWindow(false);
- host_->Shutdown(NULL);
- break;
- }
+ timer_task_.reset(new TimerTask(
+ context_->ui_message_loop(),
+ base::Bind(&DesktopEnvironment::OnShutdownHostTimer,
+ base::Unretained(this)),
+ kContinueWindowHideTimeoutMs));
}
+void DesktopEnvironment::OnShutdownHostTimer() {
+ DCHECK(context_->ui_message_loop()->BelongsToCurrentThread());
+
+ ShowContinueWindow(false);
+ host_->Shutdown(NULL);
+}
} // namespace remoting
diff --git a/remoting/host/desktop_environment.h b/remoting/host/desktop_environment.h
index e0ed196..31335f5 100644
--- a/remoting/host/desktop_environment.h
+++ b/remoting/host/desktop_environment.h
@@ -58,11 +58,7 @@ class DesktopEnvironment {
void OnPause(bool pause);
private:
- enum ContinueTimerState {
- INACTIVE, // The timer is not running or has been cancelled.
- SHOW_DIALOG, // Show the continue dialog when the timer expires.
- SHUTDOWN_HOST // Shutdown the Chromoting host when the timer expires.
- };
+ class TimerTask;
void ProcessOnConnect(const std::string& username);
void ProcessOnLastDisconnect();
@@ -79,7 +75,8 @@ class DesktopEnvironment {
void StartContinueWindowTimer(bool start);
- void ContinueWindowTimerFunc();
+ void OnContinueWindowTimer();
+ void OnShutdownHostTimer();
// The host that owns this DesktopEnvironment.
ChromotingHost* host_;
@@ -111,8 +108,7 @@ class DesktopEnvironment {
bool is_monitoring_local_inputs_;
// Timer controlling the "continue session" dialog.
- ContinueTimerState continue_timer_state_;
- base::Time continue_timer_target_time_;
+ scoped_ptr<TimerTask> timer_task_;
ScopedThreadProxy ui_thread_proxy_;