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 "remoting/host/capturer.h" | 7 #include "remoting/host/capturer.h" |
8 #include "remoting/host/chromoting_host.h" | |
9 #include "remoting/host/chromoting_host_context.h" | |
8 #include "remoting/host/continue_window.h" | 10 #include "remoting/host/continue_window.h" |
9 #include "remoting/host/curtain.h" | 11 #include "remoting/host/curtain.h" |
10 #include "remoting/host/disconnect_window.h" | 12 #include "remoting/host/disconnect_window.h" |
11 #include "remoting/host/event_executor.h" | 13 #include "remoting/host/event_executor.h" |
12 #include "remoting/host/local_input_monitor.h" | 14 #include "remoting/host/local_input_monitor.h" |
13 | 15 |
16 static const int kContinueWindowTimeoutSecs = 10 * 60; | |
17 | |
14 namespace remoting { | 18 namespace remoting { |
15 | 19 |
16 DesktopEnvironment::DesktopEnvironment(Capturer* capturer, | 20 // static |
21 DesktopEnvironment* DesktopEnvironment::Create(ChromotingHostContext* context) { | |
22 Capturer* capturer = Capturer::Create(); | |
23 EventExecutor* event_executor = | |
24 EventExecutor::Create(context->desktop_message_loop(), capturer); | |
25 Curtain* curtain = Curtain::Create(); | |
26 DisconnectWindow* disconnect_window = DisconnectWindow::Create(); | |
27 ContinueWindow* continue_window = ContinueWindow::Create(); | |
28 LocalInputMonitor* local_input_monitor = LocalInputMonitor::Create(); | |
29 | |
30 return new DesktopEnvironment(context, capturer, event_executor, curtain, | |
31 disconnect_window, continue_window, | |
32 local_input_monitor); | |
33 } | |
34 | |
35 DesktopEnvironment::DesktopEnvironment(ChromotingHostContext* context, | |
36 Capturer* capturer, | |
17 EventExecutor* event_executor, | 37 EventExecutor* event_executor, |
18 Curtain* curtain, | 38 Curtain* curtain, |
19 DisconnectWindow* disconnect_window, | 39 DisconnectWindow* disconnect_window, |
20 ContinueWindow* continue_window, | 40 ContinueWindow* continue_window, |
21 LocalInputMonitor* local_input_monitor) | 41 LocalInputMonitor* local_input_monitor) |
22 : capturer_(capturer), | 42 : host_(NULL), |
43 context_(context), | |
44 capturer_(capturer), | |
23 event_executor_(event_executor), | 45 event_executor_(event_executor), |
24 curtain_(curtain), | 46 curtain_(curtain), |
25 disconnect_window_(disconnect_window), | 47 disconnect_window_(disconnect_window), |
26 continue_window_(continue_window), | 48 continue_window_(continue_window), |
27 local_input_monitor_(local_input_monitor) { | 49 local_input_monitor_(local_input_monitor), |
50 is_monitoring_local_inputs_(false) { | |
28 } | 51 } |
29 | 52 |
30 DesktopEnvironment::~DesktopEnvironment() { | 53 DesktopEnvironment::~DesktopEnvironment() { |
31 } | 54 } |
32 | 55 |
56 void DesktopEnvironment::OnConnect(const std::string& username) { | |
57 MonitorLocalInputs(true); | |
58 ShowDisconnectWindow(true, username); | |
59 StartContinueWindowTimer(true); | |
60 } | |
61 | |
62 void DesktopEnvironment::OnLastDisconnect() { | |
63 MonitorLocalInputs(false); | |
64 ShowDisconnectWindow(false, std::string()); | |
65 ShowContinueWindow(false); | |
66 StartContinueWindowTimer(false); | |
67 } | |
68 | |
69 void DesktopEnvironment::OnPause(bool pause) { | |
70 StartContinueWindowTimer(!pause); | |
71 } | |
72 | |
73 void DesktopEnvironment::MonitorLocalInputs(bool enable) { | |
74 if (enable == is_monitoring_local_inputs_) | |
75 return; | |
76 if (enable) { | |
77 local_input_monitor_->Start(host_); | |
78 } else { | |
79 local_input_monitor_->Stop(); | |
80 } | |
81 is_monitoring_local_inputs_ = enable; | |
82 } | |
83 | |
84 void DesktopEnvironment::ShowDisconnectWindow(bool show, | |
85 const std::string& username) { | |
86 if (!context_->IsUIThread()) { | |
Sergey Ulanov
2011/07/08 23:12:24
I was suggesting that we change ChromotingHost to
| |
87 context_->PostToUIThread( | |
88 FROM_HERE, | |
89 NewRunnableMethod(this, &DesktopEnvironment::ShowDisconnectWindow, | |
90 show, username)); | |
91 return; | |
92 } | |
93 | |
94 if (show) { | |
95 disconnect_window_->Show(host_, username); | |
96 } else { | |
97 disconnect_window_->Hide(); | |
98 } | |
99 } | |
100 | |
101 void DesktopEnvironment::ShowContinueWindow(bool show) { | |
102 if (!context_->IsUIThread()) { | |
103 context_->PostToUIThread( | |
104 FROM_HERE, | |
105 NewRunnableMethod(this, &DesktopEnvironment::ShowContinueWindow, show)); | |
106 return; | |
107 } | |
108 | |
109 if (show) { | |
110 continue_window_->Show(host_); | |
111 } else { | |
112 continue_window_->Hide(); | |
113 } | |
114 } | |
115 | |
116 void DesktopEnvironment::StartContinueWindowTimer(bool start) { | |
117 if (context_->main_message_loop() != MessageLoop::current()) { | |
118 context_->main_message_loop()->PostTask( | |
119 FROM_HERE, | |
120 NewRunnableMethod(this, | |
121 &DesktopEnvironment::StartContinueWindowTimer, | |
122 start)); | |
123 return; | |
124 } | |
125 if (continue_window_timer_.IsRunning() == start) | |
126 return; | |
127 if (start) { | |
128 continue_window_timer_.Start( | |
129 base::TimeDelta::FromSeconds(kContinueWindowTimeoutSecs), | |
130 this, &DesktopEnvironment::ContinueWindowTimerFunc); | |
131 } else { | |
132 continue_window_timer_.Stop(); | |
133 } | |
134 } | |
135 | |
136 void DesktopEnvironment::ContinueWindowTimerFunc() { | |
137 host_->PauseSession(true); | |
138 ShowContinueWindow(true); | |
139 } | |
140 | |
141 | |
33 } // namespace remoting | 142 } // namespace remoting |
OLD | NEW |