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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/it2me_host_user_interface.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/it2me_host_user_interface.h" 5 #include "remoting/host/it2me_host_user_interface.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "remoting/host/chromoting_host.h" 8 #include "remoting/host/chromoting_host.h"
9 #include "remoting/host/chromoting_host_context.h" 9 #include "remoting/host/chromoting_host_context.h"
10 #include "remoting/host/continue_window.h" 10 #include "remoting/host/continue_window.h"
11 #include "remoting/host/disconnect_window.h" 11 #include "remoting/host/disconnect_window.h"
12 #include "remoting/host/local_input_monitor.h" 12 #include "remoting/host/local_input_monitor.h"
13 13
14 namespace { 14 namespace {
15 15
16 // Milliseconds before the continue window is shown. 16 // Milliseconds before the continue window is shown.
17 static const int kContinueWindowShowTimeoutMs = 10 * 60 * 1000; 17 static const int kContinueWindowShowTimeoutMs = 10 * 60 * 1000;
18 18
19 // Milliseconds before the continue window is automatically dismissed and 19 // Milliseconds before the continue window is automatically dismissed and
20 // the connection is closed. 20 // the connection is closed.
21 static const int kContinueWindowHideTimeoutMs = 60 * 1000; 21 static const int kContinueWindowHideTimeoutMs = 60 * 1000;
22 22
23 } // namespace 23 } // namespace
24 24
25 namespace remoting { 25 namespace remoting {
26 26
27 class It2MeHostUserInterface::TimerTask {
28 public:
29 TimerTask(base::MessageLoopProxy* message_loop,
30 const base::Closure& task,
31 int delay_ms)
32 : thread_proxy_(message_loop) {
33 thread_proxy_.PostDelayedTask(FROM_HERE, task, delay_ms);
34 }
35
36 private:
37 ScopedThreadProxy thread_proxy_;
38 };
39
40
41 It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context) 27 It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context)
42 : HostUserInterface(context) { 28 : HostUserInterface(context),
29 ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) {
43 } 30 }
44 31
45 It2MeHostUserInterface::~It2MeHostUserInterface() { 32 It2MeHostUserInterface::~It2MeHostUserInterface() {
46 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 33 DCHECK(ui_message_loop()->BelongsToCurrentThread());
47 34
48 ShowContinueWindow(false); 35 ShowContinueWindow(false);
49 StartContinueWindowTimer(false);
50 } 36 }
51 37
52 void It2MeHostUserInterface::Start(ChromotingHost* host, 38 void It2MeHostUserInterface::Start(ChromotingHost* host,
53 const base::Closure& disconnect_callback) { 39 const base::Closure& disconnect_callback) {
54 DCHECK(network_message_loop()->BelongsToCurrentThread()); 40 DCHECK(network_message_loop()->BelongsToCurrentThread());
55 41
56 HostUserInterface::Start(host, disconnect_callback); 42 HostUserInterface::Start(host, disconnect_callback);
57 continue_window_ = ContinueWindow::Create(); 43 continue_window_ = ContinueWindow::Create();
58 } 44 }
59 45
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 disconnect_window.Pass(), 82 disconnect_window.Pass(),
97 local_input_monitor.Pass()); 83 local_input_monitor.Pass());
98 continue_window_ = continue_window.Pass(); 84 continue_window_ = continue_window.Pass();
99 } 85 }
100 86
101 void It2MeHostUserInterface::ContinueSession(bool continue_session) { 87 void It2MeHostUserInterface::ContinueSession(bool continue_session) {
102 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 88 DCHECK(ui_message_loop()->BelongsToCurrentThread());
103 89
104 if (continue_session) { 90 if (continue_session) {
105 get_host()->PauseSession(false); 91 get_host()->PauseSession(false);
106 timer_task_.reset();
107 StartContinueWindowTimer(true); 92 StartContinueWindowTimer(true);
108 } else { 93 } else {
109 DisconnectSession(); 94 DisconnectSession();
110 } 95 }
111 } 96 }
112 97
113 void It2MeHostUserInterface::OnContinueWindowTimer() { 98 void It2MeHostUserInterface::OnContinueWindowTimer() {
114 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 99 DCHECK(ui_message_loop()->BelongsToCurrentThread());
115 100
116 get_host()->PauseSession(true); 101 get_host()->PauseSession(true);
117 ShowContinueWindow(true); 102 ShowContinueWindow(true);
118 103
119 timer_task_.reset(new TimerTask( 104 // Cancel any pending timer and post one to hide the continue window.
120 ui_message_loop(), 105 timer_weak_factory_.InvalidateWeakPtrs();
106 ui_message_loop()->PostDelayedTask(
107 FROM_HERE,
121 base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer, 108 base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer,
122 base::Unretained(this)), 109 timer_weak_factory_.GetWeakPtr()),
123 kContinueWindowHideTimeoutMs)); 110 kContinueWindowHideTimeoutMs);
124 } 111 }
125 112
126 void It2MeHostUserInterface::OnShutdownHostTimer() { 113 void It2MeHostUserInterface::OnShutdownHostTimer() {
127 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 114 DCHECK(ui_message_loop()->BelongsToCurrentThread());
128 115
129 ShowContinueWindow(false); 116 ShowContinueWindow(false);
130 DisconnectSession(); 117 DisconnectSession();
131 } 118 }
132 119
133 void It2MeHostUserInterface::ShowContinueWindow(bool show) { 120 void It2MeHostUserInterface::ShowContinueWindow(bool show) {
134 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 121 DCHECK(ui_message_loop()->BelongsToCurrentThread());
135 122
136 if (show) { 123 if (show) {
137 continue_window_->Show(get_host(), base::Bind( 124 continue_window_->Show(get_host(), base::Bind(
138 &It2MeHostUserInterface::ContinueSession, base::Unretained(this))); 125 &It2MeHostUserInterface::ContinueSession, base::Unretained(this)));
139 } else { 126 } else {
140 continue_window_->Hide(); 127 continue_window_->Hide();
141 } 128 }
142 } 129 }
143 130
144 void It2MeHostUserInterface::StartContinueWindowTimer(bool start) { 131 void It2MeHostUserInterface::StartContinueWindowTimer(bool start) {
145 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 132 DCHECK(ui_message_loop()->BelongsToCurrentThread());
146 133
134 // Abandon previous timer events by invalidating their weak pointer to us.
135 timer_weak_factory_.InvalidateWeakPtrs();
147 if (start) { 136 if (start) {
148 timer_task_.reset(new TimerTask( 137 ui_message_loop()->PostDelayedTask(
149 ui_message_loop(), 138 FROM_HERE,
150 base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer, 139 base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer,
151 base::Unretained(this)), 140 timer_weak_factory_.GetWeakPtr()),
152 kContinueWindowShowTimeoutMs)); 141 kContinueWindowShowTimeoutMs);
153 } else {
154 timer_task_.reset();
155 } 142 }
156 } 143 }
157 144
158 } // namespace remoting 145 } // namespace remoting
OLDNEW
« 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