Chromium Code Reviews| Index: remoting/host/it2me_observer.cc |
| diff --git a/remoting/host/it2me_observer.cc b/remoting/host/it2me_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e0015bc3e95b4fddc84dadcf88d54a55965af88 |
| --- /dev/null |
| +++ b/remoting/host/it2me_observer.cc |
| @@ -0,0 +1,203 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/it2me_observer.h" |
| + |
| +#include "base/bind.h" |
| +#include "remoting/host/chromoting_host.h" |
| +#include "remoting/host/chromoting_host_context.h" |
| +#include "remoting/host/continue_window.h" |
| +#include "remoting/host/disconnect_window.h" |
| +#include "remoting/host/local_input_monitor.h" |
| + |
| +namespace remoting { |
| + |
| +class It2MeObserver::TimerTask { |
| + public: |
| + TimerTask(base::MessageLoopProxy* message_loop, |
| + const base::Closure& task, |
| + int delay_ms) |
| + : thread_proxy_(message_loop) { |
| + thread_proxy_.PostDelayedTask(FROM_HERE, task, delay_ms); |
| + } |
| + |
| + private: |
| + ScopedThreadProxy thread_proxy_; |
| +}; |
| + |
| + |
| +It2MeObserver::It2MeObserver(ChromotingHost* host, |
| + ChromotingHostContext* context) |
| + : host_(host), |
| + context_(context), |
| + is_monitoring_local_inputs_(false), |
| + ui_thread_proxy_(context->ui_message_loop()) { |
| +} |
| + |
| +It2MeObserver::~It2MeObserver() { |
| +} |
| + |
| +void It2MeObserver::Init() { |
| + InitFrom(DisconnectWindow::Create(), |
| + ContinueWindow::Create(), |
| + LocalInputMonitor::Create()); |
| +} |
| + |
| +void It2MeObserver::InitFrom(DisconnectWindow* disconnect_window, |
| + ContinueWindow* continue_window, |
| + LocalInputMonitor* monitor) { |
| + disconnect_window_.reset(disconnect_window); |
| + continue_window_.reset(continue_window); |
| + local_input_monitor_.reset(monitor); |
| +} |
| + |
| +void It2MeObserver::OnSignallingConnected(SignalStrategy* signal_strategy, |
| + const std::string& full_jid) { |
| +} |
| + |
| +void It2MeObserver::OnSignallingDisconnected() { |
| +} |
| + |
| +void It2MeObserver::OnClientAuthenticated(const std::string& jid) { |
| + 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.
|
| + |
| + std::string username = jid.substr(0, jid.find('/')); |
| + ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( |
| + &It2MeObserver::ProcessOnConnect, base::Unretained(this), username)); |
| +} |
| + |
| +void It2MeObserver::OnClientDisconnected(const std::string& jid) { |
| + if (jid == authenticated_jid_) { |
| + authenticated_jid_.clear(); |
| + ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( |
| + &It2MeObserver::ProcessOnLastDisconnect, base::Unretained(this))); |
| + } |
| +} |
| + |
| +void It2MeObserver::OnAccessDenied() { |
| +} |
| + |
| +void It2MeObserver::OnShutdown() { |
| +} |
| + |
| +void It2MeObserver::Shutdown() { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + MonitorLocalInputs(false); |
| + ShowDisconnectWindow(false, std::string()); |
| + ShowContinueWindow(false); |
| + StartContinueWindowTimer(false); |
| + |
| + ui_thread_proxy_.Detach(); |
| +} |
| + |
| +void It2MeObserver::OnConnect(const std::string& username) { |
| + ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( |
| + &It2MeObserver::ProcessOnConnect, base::Unretained(this), username)); |
| +} |
| + |
| +void It2MeObserver::OnLastDisconnect() { |
| + ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( |
| + &It2MeObserver::ProcessOnLastDisconnect, base::Unretained(this))); |
| +} |
| + |
| +void It2MeObserver::ProcessOnConnect(const std::string& username) { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + MonitorLocalInputs(true); |
| + ShowDisconnectWindow(true, username); |
| + StartContinueWindowTimer(true); |
| +} |
| + |
| +void It2MeObserver::ProcessOnLastDisconnect() { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + MonitorLocalInputs(false); |
| + ShowDisconnectWindow(false, std::string()); |
| + ShowContinueWindow(false); |
| + StartContinueWindowTimer(false); |
| +} |
| + |
| +void It2MeObserver::MonitorLocalInputs(bool enable) { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + if (enable == is_monitoring_local_inputs_) |
| + return; |
| + if (enable) { |
| + local_input_monitor_->Start(host_); |
| + } else { |
| + local_input_monitor_->Stop(); |
| + } |
| + is_monitoring_local_inputs_ = enable; |
| +} |
| + |
| +void It2MeObserver::ShowDisconnectWindow(bool show, |
| + const std::string& username) { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + if (show) { |
| + disconnect_window_->Show(host_, username); |
| + } else { |
| + disconnect_window_->Hide(); |
| + } |
| +} |
| + |
| +void It2MeObserver::ShowContinueWindow(bool show) { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + if (show) { |
| + continue_window_->Show(host_, base::Bind( |
| + &It2MeObserver::ContinueSession, base::Unretained(this))); |
| + } else { |
| + continue_window_->Hide(); |
| + } |
| +} |
| + |
| +void It2MeObserver::ContinueSession(bool continue_session) { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + if (continue_session) { |
| + host_->PauseSession(false); |
| + timer_task_.reset(); |
| + StartContinueWindowTimer(true); |
| + } else { |
| + host_->Shutdown(base::Closure()); |
| + } |
| +} |
| + |
| +void It2MeObserver::StartContinueWindowTimer(bool start) { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + if (start) { |
| + timer_task_.reset(new TimerTask( |
| + context_->ui_message_loop(), |
| + base::Bind(&It2MeObserver::OnContinueWindowTimer, |
| + 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 :)
|
| + kContinueWindowShowTimeoutMs)); |
| + } else if (!start) { |
|
Sergey Ulanov
2011/11/29 20:18:00
if(!start) is redundant here.
Lambros
2011/11/30 20:47:02
Done.
|
| + timer_task_.reset(); |
| + } |
| +} |
| + |
| +void It2MeObserver::OnContinueWindowTimer() { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + host_->PauseSession(true); |
| + ShowContinueWindow(true); |
| + |
| + timer_task_.reset(new TimerTask( |
| + context_->ui_message_loop(), |
| + base::Bind(&It2MeObserver::OnShutdownHostTimer, |
| + 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.
|
| + kContinueWindowHideTimeoutMs)); |
| +} |
| + |
| +void It2MeObserver::OnShutdownHostTimer() { |
| + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); |
| + |
| + ShowContinueWindow(false); |
| + host_->Shutdown(base::Closure()); |
| +} |
| + |
| +} // namespace remoting |