OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/desktop_environment.h" | 5 #include "remoting/host/desktop_environment.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "remoting/host/capturer.h" | 9 #include "remoting/host/capturer.h" |
10 #include "remoting/host/chromoting_host.h" | 10 #include "remoting/host/chromoting_host.h" |
11 #include "remoting/host/chromoting_host_context.h" | 11 #include "remoting/host/chromoting_host_context.h" |
12 #include "remoting/host/continue_window.h" | 12 #include "remoting/host/continue_window.h" |
13 #include "remoting/host/curtain.h" | 13 #include "remoting/host/curtain.h" |
14 #include "remoting/host/disconnect_window.h" | 14 #include "remoting/host/disconnect_window.h" |
15 #include "remoting/host/event_executor.h" | 15 #include "remoting/host/event_executor.h" |
16 #include "remoting/host/local_input_monitor.h" | 16 #include "remoting/host/local_input_monitor.h" |
17 | 17 |
18 static const int kContinueWindowTimeoutMs = 10 * 60 * 1000; | 18 // Milliseconds before the continue window is shown. |
19 static const int kContinueWindowShowTimeoutMs = 10 * 1000; | |
Sergey Ulanov
2011/08/24 01:56:45
Revert this change
Jamie
2011/08/24 17:42:03
Done.
| |
20 | |
21 // Milliseconds before the continue window is automatically dismissed and | |
22 // the connection is closed. | |
23 static const int kContinueWindowHideTimeoutMs = 5 * 1000; | |
Sergey Ulanov
2011/08/24 01:56:45
Should be 60 * 1000 instead of 5 seconds
Jamie
2011/08/24 17:42:03
Done.
| |
19 | 24 |
20 namespace remoting { | 25 namespace remoting { |
21 | 26 |
22 // UIThreadProxy proxies DesktopEnvironment method calls to the UI | 27 // UIThreadProxy proxies DesktopEnvironment method calls to the UI |
23 // thread. This is neccessary so that DesktopEnvironment can be | 28 // thread. This is neccessary so that DesktopEnvironment can be |
24 // deleted synchronously even while there are pending tasks on the | 29 // deleted synchronously even while there are pending tasks on the |
25 // message queue. | 30 // message queue. |
26 // | 31 // |
27 // TODO(sergeyu): Merge this code with remoting::TaskThreadProxy. The | 32 // TODO(sergeyu): Merge this code with remoting::TaskThreadProxy. The |
28 // problem solved by this class is very simular to the one solved by | 33 // problem solved by this class is very simular to the one solved by |
29 // ScopedRunnableMethodFactory. The main difference is that this class | 34 // ScopedRunnableMethodFactory. The main difference is that this class |
30 // is thread-safe. Change the interface to make it look more like | 35 // is thread-safe. Change the interface to make it look more like |
31 // ScopedRunnableMethodFactory and rename it to avoid confusion with | 36 // ScopedRunnableMethodFactory and rename it to avoid confusion with |
32 // MessageLoopProxy. | 37 // MessageLoopProxy. |
33 class UIThreadProxy : public base::RefCountedThreadSafe<UIThreadProxy> { | 38 class UIThreadProxy : public base::RefCountedThreadSafe<UIThreadProxy> { |
34 public: | 39 public: |
35 UIThreadProxy(base::MessageLoopProxy* message_loop) | 40 explicit UIThreadProxy(base::MessageLoopProxy* message_loop) |
36 : message_loop_(message_loop) { | 41 : message_loop_(message_loop) { |
37 } | 42 } |
38 | 43 |
39 // TODO(sergeyu): Rename this method. | 44 // TODO(sergeyu): Rename this method. |
40 void Detach() { | 45 void Detach() { |
41 DCHECK(message_loop_->BelongsToCurrentThread()); | 46 DCHECK(message_loop_->BelongsToCurrentThread()); |
42 message_loop_ = NULL; | 47 message_loop_ = NULL; |
43 } | 48 } |
44 | 49 |
45 void CallOnUIThread(const tracked_objects::Location& from_here, | 50 void CallOnUIThread(const tracked_objects::Location& from_here, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 LocalInputMonitor* local_input_monitor) | 117 LocalInputMonitor* local_input_monitor) |
113 : host_(NULL), | 118 : host_(NULL), |
114 context_(context), | 119 context_(context), |
115 capturer_(capturer), | 120 capturer_(capturer), |
116 event_executor_(event_executor), | 121 event_executor_(event_executor), |
117 curtain_(curtain), | 122 curtain_(curtain), |
118 disconnect_window_(disconnect_window), | 123 disconnect_window_(disconnect_window), |
119 continue_window_(continue_window), | 124 continue_window_(continue_window), |
120 local_input_monitor_(local_input_monitor), | 125 local_input_monitor_(local_input_monitor), |
121 is_monitoring_local_inputs_(false), | 126 is_monitoring_local_inputs_(false), |
122 continue_timer_started_(false), | 127 continue_timer_state_(INACTIVE), |
123 proxy_(new UIThreadProxy(context->ui_message_loop())) { | 128 proxy_(new UIThreadProxy(context->ui_message_loop())) { |
124 } | 129 } |
125 | 130 |
126 DesktopEnvironment::~DesktopEnvironment() { | 131 DesktopEnvironment::~DesktopEnvironment() { |
127 } | 132 } |
128 | 133 |
129 void DesktopEnvironment::Shutdown() { | 134 void DesktopEnvironment::Shutdown() { |
130 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | 135 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
131 | 136 |
132 MonitorLocalInputs(false); | 137 MonitorLocalInputs(false); |
(...skipping 30 matching lines...) Expand all Loading... | |
163 void DesktopEnvironment::ProcessOnLastDisconnect() { | 168 void DesktopEnvironment::ProcessOnLastDisconnect() { |
164 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | 169 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
165 | 170 |
166 MonitorLocalInputs(false); | 171 MonitorLocalInputs(false); |
167 ShowDisconnectWindow(false, std::string()); | 172 ShowDisconnectWindow(false, std::string()); |
168 ShowContinueWindow(false); | 173 ShowContinueWindow(false); |
169 StartContinueWindowTimer(false); | 174 StartContinueWindowTimer(false); |
170 } | 175 } |
171 | 176 |
172 void DesktopEnvironment::ProcessOnPause(bool pause) { | 177 void DesktopEnvironment::ProcessOnPause(bool pause) { |
173 StartContinueWindowTimer(!pause); | 178 if (!pause) { |
179 continue_timer_state_ = INACTIVE; | |
180 StartContinueWindowTimer(true); | |
181 } | |
174 } | 182 } |
175 | 183 |
176 void DesktopEnvironment::MonitorLocalInputs(bool enable) { | 184 void DesktopEnvironment::MonitorLocalInputs(bool enable) { |
177 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | 185 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
178 | 186 |
179 if (enable == is_monitoring_local_inputs_) | 187 if (enable == is_monitoring_local_inputs_) |
180 return; | 188 return; |
181 if (enable) { | 189 if (enable) { |
182 local_input_monitor_->Start(host_); | 190 local_input_monitor_->Start(host_); |
183 } else { | 191 } else { |
(...skipping 19 matching lines...) Expand all Loading... | |
203 if (show) { | 211 if (show) { |
204 continue_window_->Show(host_); | 212 continue_window_->Show(host_); |
205 } else { | 213 } else { |
206 continue_window_->Hide(); | 214 continue_window_->Hide(); |
207 } | 215 } |
208 } | 216 } |
209 | 217 |
210 void DesktopEnvironment::StartContinueWindowTimer(bool start) { | 218 void DesktopEnvironment::StartContinueWindowTimer(bool start) { |
211 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | 219 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
212 | 220 |
213 if (start && !continue_timer_started_) { | 221 if (start && continue_timer_state_ == INACTIVE) { |
214 continue_timer_target_time_ = base::Time::Now() + | 222 continue_timer_target_time_ = base::Time::Now() + |
215 base::TimeDelta::FromMilliseconds(kContinueWindowTimeoutMs); | 223 base::TimeDelta::FromMilliseconds(kContinueWindowShowTimeoutMs); |
216 proxy_->CallOnUIThreadDelayed( | 224 proxy_->CallOnUIThreadDelayed( |
217 FROM_HERE, base::Bind(&DesktopEnvironment::ContinueWindowTimerFunc, | 225 FROM_HERE, base::Bind(&DesktopEnvironment::ContinueWindowTimerFunc, |
218 base::Unretained(this)), | 226 base::Unretained(this)), |
219 kContinueWindowTimeoutMs); | 227 kContinueWindowShowTimeoutMs); |
220 } | 228 } |
221 | 229 |
222 continue_timer_started_ = start; | 230 continue_timer_state_ = start ? SHOW_DIALOG : INACTIVE; |
Sergey Ulanov
2011/08/24 01:56:45
What if this function is called with when continue
Jamie
2011/08/24 17:42:03
Done.
| |
223 } | 231 } |
224 | 232 |
225 void DesktopEnvironment::ContinueWindowTimerFunc() { | 233 void DesktopEnvironment::ContinueWindowTimerFunc() { |
226 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | 234 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
227 | 235 |
228 // This function may be called prematurely if timer was stopped and | 236 // This function may be called prematurely if timer was stopped and |
229 // then started again. In that case we just ignore this call. | 237 // then started again. In that case we just ignore this call. |
230 if (continue_timer_target_time_ > base::Time::Now()) | 238 if (continue_timer_state_ == INACTIVE || |
239 continue_timer_target_time_ > base::Time::Now()) | |
231 return; | 240 return; |
232 | 241 |
233 continue_timer_started_ = false; | 242 if (continue_timer_state_ == SHOW_DIALOG) { |
234 host_->PauseSession(true); | 243 host_->PauseSession(true); |
235 ShowContinueWindow(true); | 244 ShowContinueWindow(true); |
245 continue_timer_target_time_ = base::Time::Now() + | |
246 base::TimeDelta::FromMilliseconds(kContinueWindowHideTimeoutMs); | |
247 proxy_->CallOnUIThreadDelayed( | |
248 FROM_HERE, base::Bind(&DesktopEnvironment::ContinueWindowTimerFunc, | |
249 base::Unretained(this)), | |
250 kContinueWindowHideTimeoutMs); | |
251 continue_timer_state_ = HIDE_DIALOG; | |
252 } else { | |
253 continue_timer_state_ = INACTIVE; | |
254 ShowContinueWindow(false); | |
255 host_->Shutdown(NULL); | |
Sergey Ulanov
2011/08/24 01:56:45
I don't like the idea of calling Shutdown() from h
| |
256 } | |
236 } | 257 } |
237 | 258 |
238 | 259 |
239 } // namespace remoting | 260 } // namespace remoting |
OLD | NEW |