summaryrefslogtreecommitdiffstats
path: root/remoting/host/it2me_host_user_interface.cc
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 17:40:08 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 17:40:08 +0000
commitdd71eeb64f572b16552ed730676455fef635283e (patch)
treea7216339a5963260abc1a2d0cb5c6a4d35682b71 /remoting/host/it2me_host_user_interface.cc
parent01bf789e284b82c1163b1378e9ec73bedd19bad7 (diff)
downloadchromium_src-dd71eeb64f572b16552ed730676455fef635283e.zip
chromium_src-dd71eeb64f572b16552ed730676455fef635283e.tar.gz
chromium_src-dd71eeb64f572b16552ed730676455fef635283e.tar.bz2
Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs.
This affects the following classes: * ChromotingClient * ChromotingInstance * HostUserInterface * It2MeHostUserInterface The MessageLoopProxy/WeakPtr combination requires that the WeakPtr is created on the thread referred to by the proxy; code in which that is hard to arrange usually has subtle race-conditions. This is a re-land of CL 1045404, replacing some CR_DEFINE_STATIC_LOCAL() instances with base::LazyInstance to avoid adding global initializers or finalizers. TEST=Existing unit-tests, and manual testing. Review URL: https://chromiumcodereview.appspot.com/10440107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141028 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/it2me_host_user_interface.cc')
-rw-r--r--remoting/host/it2me_host_user_interface.cc41
1 files changed, 14 insertions, 27 deletions
diff --git a/remoting/host/it2me_host_user_interface.cc b/remoting/host/it2me_host_user_interface.cc
index c39f6d3..1b2f392 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);
}
}