OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/host/it2me_host_user_interface.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "remoting/host/chromoting_host.h" | |
9 #include "remoting/host/chromoting_host_context.h" | |
10 #include "remoting/host/continue_window.h" | |
11 #include "remoting/host/disconnect_window.h" | |
12 #include "remoting/host/local_input_monitor.h" | |
13 | |
14 namespace remoting { | |
15 | |
16 class It2MeHostUserInterface::TimerTask { | |
17 public: | |
18 TimerTask(base::MessageLoopProxy* message_loop, | |
19 const base::Closure& task, | |
20 int delay_ms) | |
21 : thread_proxy_(message_loop) { | |
22 thread_proxy_.PostDelayedTask(FROM_HERE, task, delay_ms); | |
23 } | |
24 | |
25 private: | |
26 ScopedThreadProxy thread_proxy_; | |
27 }; | |
28 | |
29 | |
30 It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHost* host, | |
31 ChromotingHostContext* context) | |
Sergey Ulanov
2011/11/30 21:24:37
nit: align this with (
Lambros
2011/11/30 22:09:41
Done.
| |
32 : host_(host), | |
33 context_(context), | |
34 is_monitoring_local_inputs_(false), | |
35 ui_thread_proxy_(context->ui_message_loop()) { | |
36 } | |
37 | |
38 It2MeHostUserInterface::~It2MeHostUserInterface() { | |
39 } | |
40 | |
41 void It2MeHostUserInterface::Init() { | |
42 InitFrom(DisconnectWindow::Create(), | |
43 ContinueWindow::Create(), | |
44 LocalInputMonitor::Create()); | |
45 } | |
46 | |
47 void It2MeHostUserInterface::InitFrom(DisconnectWindow* disconnect_window, | |
48 ContinueWindow* continue_window, | |
Sergey Ulanov
2011/11/30 21:24:37
same here
Lambros
2011/11/30 22:09:41
Done.
| |
49 LocalInputMonitor* monitor) { | |
50 disconnect_window_.reset(disconnect_window); | |
51 continue_window_.reset(continue_window); | |
52 local_input_monitor_.reset(monitor); | |
53 } | |
54 | |
55 void It2MeHostUserInterface::OnSignallingConnected( | |
56 SignalStrategy* signal_strategy, const std::string& full_jid) { | |
57 } | |
58 | |
59 void It2MeHostUserInterface::OnSignallingDisconnected() { | |
60 } | |
61 | |
62 void It2MeHostUserInterface::OnClientAuthenticated(const std::string& jid) { | |
63 // There should not be more than one concurrent authenticated connection. | |
64 DCHECK(authenticated_jid_.empty()); | |
65 authenticated_jid_ = jid; | |
66 | |
67 std::string username = jid.substr(0, jid.find('/')); | |
68 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
69 &It2MeHostUserInterface::ProcessOnConnect, base::Unretained(this), | |
70 username)); | |
71 } | |
72 | |
73 void It2MeHostUserInterface::OnClientDisconnected(const std::string& jid) { | |
74 if (jid == authenticated_jid_) { | |
75 authenticated_jid_.clear(); | |
76 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
77 &It2MeHostUserInterface::ProcessOnLastDisconnect, | |
78 base::Unretained(this))); | |
79 } | |
80 } | |
81 | |
82 void It2MeHostUserInterface::OnAccessDenied() { | |
83 } | |
84 | |
85 void It2MeHostUserInterface::OnShutdown() { | |
86 } | |
87 | |
88 void It2MeHostUserInterface::Shutdown() { | |
89 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
90 | |
91 MonitorLocalInputs(false); | |
92 ShowDisconnectWindow(false, std::string()); | |
93 ShowContinueWindow(false); | |
94 StartContinueWindowTimer(false); | |
95 | |
96 ui_thread_proxy_.Detach(); | |
97 } | |
98 | |
99 void It2MeHostUserInterface::OnConnect(const std::string& username) { | |
100 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
101 &It2MeHostUserInterface::ProcessOnConnect, base::Unretained(this), | |
102 username)); | |
103 } | |
104 | |
105 void It2MeHostUserInterface::OnLastDisconnect() { | |
106 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
107 &It2MeHostUserInterface::ProcessOnLastDisconnect, | |
108 base::Unretained(this))); | |
109 } | |
110 | |
111 void It2MeHostUserInterface::ProcessOnConnect(const std::string& username) { | |
112 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
113 | |
114 MonitorLocalInputs(true); | |
115 ShowDisconnectWindow(true, username); | |
116 StartContinueWindowTimer(true); | |
117 } | |
118 | |
119 void It2MeHostUserInterface::ProcessOnLastDisconnect() { | |
120 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
121 | |
122 MonitorLocalInputs(false); | |
123 ShowDisconnectWindow(false, std::string()); | |
124 ShowContinueWindow(false); | |
125 StartContinueWindowTimer(false); | |
126 } | |
127 | |
128 void It2MeHostUserInterface::MonitorLocalInputs(bool enable) { | |
129 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
130 | |
131 if (enable == is_monitoring_local_inputs_) | |
132 return; | |
133 if (enable) { | |
134 local_input_monitor_->Start(host_); | |
135 } else { | |
136 local_input_monitor_->Stop(); | |
137 } | |
138 is_monitoring_local_inputs_ = enable; | |
139 } | |
140 | |
141 void It2MeHostUserInterface::ShowDisconnectWindow(bool show, | |
142 const std::string& username) { | |
143 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
144 | |
145 if (show) { | |
146 disconnect_window_->Show(host_, username); | |
147 } else { | |
148 disconnect_window_->Hide(); | |
149 } | |
150 } | |
151 | |
152 void It2MeHostUserInterface::ShowContinueWindow(bool show) { | |
153 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
154 | |
155 if (show) { | |
156 continue_window_->Show(host_, base::Bind( | |
157 &It2MeHostUserInterface::ContinueSession, base::Unretained(this))); | |
158 } else { | |
159 continue_window_->Hide(); | |
160 } | |
161 } | |
162 | |
163 void It2MeHostUserInterface::ContinueSession(bool continue_session) { | |
164 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
165 | |
166 if (continue_session) { | |
167 host_->PauseSession(false); | |
168 timer_task_.reset(); | |
169 StartContinueWindowTimer(true); | |
170 } else { | |
171 host_->Shutdown(base::Closure()); | |
172 } | |
173 } | |
174 | |
175 void It2MeHostUserInterface::StartContinueWindowTimer(bool start) { | |
176 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
177 | |
178 if (start) { | |
179 timer_task_.reset(new TimerTask( | |
180 context_->ui_message_loop(), | |
181 base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer, | |
182 base::Unretained(this)), | |
183 kContinueWindowShowTimeoutMs)); | |
184 } else { | |
185 timer_task_.reset(); | |
186 } | |
187 } | |
188 | |
189 void It2MeHostUserInterface::OnContinueWindowTimer() { | |
190 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
191 | |
192 host_->PauseSession(true); | |
193 ShowContinueWindow(true); | |
194 | |
195 timer_task_.reset(new TimerTask( | |
196 context_->ui_message_loop(), | |
197 base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer, | |
198 base::Unretained(this)), | |
199 kContinueWindowHideTimeoutMs)); | |
200 } | |
201 | |
202 void It2MeHostUserInterface::OnShutdownHostTimer() { | |
203 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
204 | |
205 ShowContinueWindow(false); | |
206 host_->Shutdown(base::Closure()); | |
207 } | |
208 | |
209 } // namespace remoting | |
OLD | NEW |