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_observer.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 It2MeObserver::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 It2MeObserver::It2MeObserver(ChromotingHost* host, | |
31 ChromotingHostContext* context) | |
32 : host_(host), | |
33 context_(context), | |
34 is_monitoring_local_inputs_(false), | |
35 ui_thread_proxy_(context->ui_message_loop()) { | |
36 } | |
37 | |
38 It2MeObserver::~It2MeObserver() { | |
39 } | |
40 | |
41 void It2MeObserver::Init() { | |
42 InitFrom(DisconnectWindow::Create(), | |
43 ContinueWindow::Create(), | |
44 LocalInputMonitor::Create()); | |
45 } | |
46 | |
47 void It2MeObserver::InitFrom(DisconnectWindow* disconnect_window, | |
48 ContinueWindow* continue_window, | |
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 It2MeObserver::OnSignallingConnected(SignalStrategy* signal_strategy, | |
56 const std::string& full_jid) { | |
57 } | |
58 | |
59 void It2MeObserver::OnSignallingDisconnected() { | |
60 } | |
61 | |
62 void It2MeObserver::OnClientAuthenticated(const std::string& jid) { | |
63 authenticated_jid_ = jid; | |
Sergey Ulanov
2011/11/29 20:18:00
add DCHECK(authenticated_jid_.empty()) here becaus
Lambros
2011/11/30 20:47:02
Done.
| |
64 | |
65 std::string username = jid.substr(0, jid.find('/')); | |
66 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
67 &It2MeObserver::ProcessOnConnect, base::Unretained(this), username)); | |
68 } | |
69 | |
70 void It2MeObserver::OnClientDisconnected(const std::string& jid) { | |
71 if (jid == authenticated_jid_) { | |
72 authenticated_jid_.clear(); | |
73 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
74 &It2MeObserver::ProcessOnLastDisconnect, base::Unretained(this))); | |
75 } | |
76 } | |
77 | |
78 void It2MeObserver::OnAccessDenied() { | |
79 } | |
80 | |
81 void It2MeObserver::OnShutdown() { | |
82 } | |
83 | |
84 void It2MeObserver::Shutdown() { | |
85 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
86 | |
87 MonitorLocalInputs(false); | |
88 ShowDisconnectWindow(false, std::string()); | |
89 ShowContinueWindow(false); | |
90 StartContinueWindowTimer(false); | |
91 | |
92 ui_thread_proxy_.Detach(); | |
93 } | |
94 | |
95 void It2MeObserver::OnConnect(const std::string& username) { | |
96 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
97 &It2MeObserver::ProcessOnConnect, base::Unretained(this), username)); | |
98 } | |
99 | |
100 void It2MeObserver::OnLastDisconnect() { | |
101 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( | |
102 &It2MeObserver::ProcessOnLastDisconnect, base::Unretained(this))); | |
103 } | |
104 | |
105 void It2MeObserver::ProcessOnConnect(const std::string& username) { | |
106 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
107 | |
108 MonitorLocalInputs(true); | |
109 ShowDisconnectWindow(true, username); | |
110 StartContinueWindowTimer(true); | |
111 } | |
112 | |
113 void It2MeObserver::ProcessOnLastDisconnect() { | |
114 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
115 | |
116 MonitorLocalInputs(false); | |
117 ShowDisconnectWindow(false, std::string()); | |
118 ShowContinueWindow(false); | |
119 StartContinueWindowTimer(false); | |
120 } | |
121 | |
122 void It2MeObserver::MonitorLocalInputs(bool enable) { | |
123 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
124 | |
125 if (enable == is_monitoring_local_inputs_) | |
126 return; | |
127 if (enable) { | |
128 local_input_monitor_->Start(host_); | |
129 } else { | |
130 local_input_monitor_->Stop(); | |
131 } | |
132 is_monitoring_local_inputs_ = enable; | |
133 } | |
134 | |
135 void It2MeObserver::ShowDisconnectWindow(bool show, | |
136 const std::string& username) { | |
137 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
138 | |
139 if (show) { | |
140 disconnect_window_->Show(host_, username); | |
141 } else { | |
142 disconnect_window_->Hide(); | |
143 } | |
144 } | |
145 | |
146 void It2MeObserver::ShowContinueWindow(bool show) { | |
147 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
148 | |
149 if (show) { | |
150 continue_window_->Show(host_, base::Bind( | |
151 &It2MeObserver::ContinueSession, base::Unretained(this))); | |
152 } else { | |
153 continue_window_->Hide(); | |
154 } | |
155 } | |
156 | |
157 void It2MeObserver::ContinueSession(bool continue_session) { | |
158 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
159 | |
160 if (continue_session) { | |
161 host_->PauseSession(false); | |
162 timer_task_.reset(); | |
163 StartContinueWindowTimer(true); | |
164 } else { | |
165 host_->Shutdown(base::Closure()); | |
166 } | |
167 } | |
168 | |
169 void It2MeObserver::StartContinueWindowTimer(bool start) { | |
170 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
171 | |
172 if (start) { | |
173 timer_task_.reset(new TimerTask( | |
174 context_->ui_message_loop(), | |
175 base::Bind(&It2MeObserver::OnContinueWindowTimer, | |
176 base::Unretained(this)), | |
Sergey Ulanov
2011/11/29 20:18:00
nit: can this fit on the previous line?
Lambros
2011/11/30 20:47:02
Not any more :)
| |
177 kContinueWindowShowTimeoutMs)); | |
178 } else if (!start) { | |
Sergey Ulanov
2011/11/29 20:18:00
if(!start) is redundant here.
Lambros
2011/11/30 20:47:02
Done.
| |
179 timer_task_.reset(); | |
180 } | |
181 } | |
182 | |
183 void It2MeObserver::OnContinueWindowTimer() { | |
184 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
185 | |
186 host_->PauseSession(true); | |
187 ShowContinueWindow(true); | |
188 | |
189 timer_task_.reset(new TimerTask( | |
190 context_->ui_message_loop(), | |
191 base::Bind(&It2MeObserver::OnShutdownHostTimer, | |
192 base::Unretained(this)), | |
Sergey Ulanov
2011/11/29 20:18:00
nit: move to the previous line.
Lambros
2011/11/30 20:47:02
Won't fit.
| |
193 kContinueWindowHideTimeoutMs)); | |
194 } | |
195 | |
196 void It2MeObserver::OnShutdownHostTimer() { | |
197 DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); | |
198 | |
199 ShowContinueWindow(false); | |
200 host_->Shutdown(base::Closure()); | |
201 } | |
202 | |
203 } // namespace remoting | |
OLD | NEW |