Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1132)

Unified Diff: remoting/host/it2me_host_user_interface.cc

Issue 10440107: Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use correct TaskRunner reference, and copy instance reference in lock. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/it2me_host_user_interface.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/it2me_host_user_interface.cc
diff --git a/remoting/host/it2me_host_user_interface.cc b/remoting/host/it2me_host_user_interface.cc
index c39f6d366d748c848fc9ca029d9d63df7edf4616..1b2f392598d9abdc5e1a7639821f2c6fb19e5285 100644
--- a/remoting/host/it2me_host_user_interface.cc
+++ b/remoting/host/it2me_host_user_interface.cc
@@ -24,29 +24,15 @@ static const int kContinueWindowHideTimeoutMs = 60 * 1000;
namespace remoting {
-class It2MeHostUserInterface::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_;
-};
-
-
It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context)
- : HostUserInterface(context) {
+ : HostUserInterface(context),
+ ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) {
}
It2MeHostUserInterface::~It2MeHostUserInterface() {
DCHECK(ui_message_loop()->BelongsToCurrentThread());
ShowContinueWindow(false);
- StartContinueWindowTimer(false);
}
void It2MeHostUserInterface::Start(ChromotingHost* host,
@@ -103,7 +89,6 @@ void It2MeHostUserInterface::ContinueSession(bool continue_session) {
if (continue_session) {
get_host()->PauseSession(false);
- timer_task_.reset();
StartContinueWindowTimer(true);
} else {
DisconnectSession();
@@ -116,11 +101,13 @@ void It2MeHostUserInterface::OnContinueWindowTimer() {
get_host()->PauseSession(true);
ShowContinueWindow(true);
- timer_task_.reset(new TimerTask(
- ui_message_loop(),
+ // Cancel any pending timer and post one to hide the continue window.
+ timer_weak_factory_.InvalidateWeakPtrs();
+ ui_message_loop()->PostDelayedTask(
+ FROM_HERE,
base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer,
- base::Unretained(this)),
- kContinueWindowHideTimeoutMs));
+ timer_weak_factory_.GetWeakPtr()),
+ kContinueWindowHideTimeoutMs);
}
void It2MeHostUserInterface::OnShutdownHostTimer() {
@@ -144,14 +131,14 @@ void It2MeHostUserInterface::ShowContinueWindow(bool show) {
void It2MeHostUserInterface::StartContinueWindowTimer(bool start) {
DCHECK(ui_message_loop()->BelongsToCurrentThread());
+ // Abandon previous timer events by invalidating their weak pointer to us.
+ timer_weak_factory_.InvalidateWeakPtrs();
if (start) {
- timer_task_.reset(new TimerTask(
- ui_message_loop(),
+ ui_message_loop()->PostDelayedTask(
+ FROM_HERE,
base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer,
- base::Unretained(this)),
- kContinueWindowShowTimeoutMs));
- } else {
- timer_task_.reset();
+ timer_weak_factory_.GetWeakPtr()),
+ kContinueWindowShowTimeoutMs);
}
}
« no previous file with comments | « remoting/host/it2me_host_user_interface.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698