| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host_user_interface.h" | 5 #include "remoting/host/host_user_interface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "remoting/host/chromoting_host.h" | 8 #include "remoting/host/chromoting_host.h" |
| 9 #include "remoting/host/disconnect_window.h" | 9 #include "remoting/host/disconnect_window.h" |
| 10 #include "remoting/host/local_input_monitor.h" | 10 #include "remoting/host/local_input_monitor.h" |
| 11 | 11 |
| 12 namespace remoting { | 12 namespace remoting { |
| 13 | 13 |
| 14 HostUserInterface::HostUserInterface( | 14 HostUserInterface::HostUserInterface( |
| 15 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 15 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 16 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 16 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 17 const UiStrings& ui_strings) | 17 const UiStrings& ui_strings) |
| 18 : host_(NULL), | 18 : host_(NULL), |
| 19 network_task_runner_(network_task_runner), | 19 network_task_runner_(network_task_runner), |
| 20 ui_task_runner_(ui_task_runner), | 20 ui_task_runner_(ui_task_runner), |
| 21 is_monitoring_local_inputs_(false), | |
| 22 ui_strings_(ui_strings), | 21 ui_strings_(ui_strings), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 22 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 24 weak_ptr_(weak_factory_.GetWeakPtr()) { | 23 weak_ptr_(weak_factory_.GetWeakPtr()) { |
| 25 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 24 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 26 } | 25 } |
| 27 | 26 |
| 28 HostUserInterface::~HostUserInterface() { | 27 HostUserInterface::~HostUserInterface() { |
| 29 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 28 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 30 | 29 |
| 31 MonitorLocalInputs(false); | |
| 32 disconnect_window_->Hide(); | 30 disconnect_window_->Hide(); |
| 33 } | 31 } |
| 34 | 32 |
| 35 void HostUserInterface::Init() { | 33 void HostUserInterface::Init() { |
| 36 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 34 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 37 | 35 |
| 38 disconnect_window_ = DisconnectWindow::Create(&ui_strings()); | 36 disconnect_window_ = DisconnectWindow::Create(&ui_strings()); |
| 39 local_input_monitor_ = LocalInputMonitor::Create(ui_task_runner_, | |
| 40 network_task_runner_, | |
| 41 ui_task_runner_); | |
| 42 } | 37 } |
| 43 | 38 |
| 44 void HostUserInterface::Start(ChromotingHost* host, | 39 void HostUserInterface::Start(ChromotingHost* host, |
| 45 const base::Closure& disconnect_callback) { | 40 const base::Closure& disconnect_callback) { |
| 46 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 41 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 47 DCHECK(host_ == NULL); | 42 DCHECK(host_ == NULL); |
| 48 | 43 |
| 49 host_ = host; | 44 host_ = host; |
| 50 disconnect_callback_ = disconnect_callback; | 45 disconnect_callback_ = disconnect_callback; |
| 51 host_->AddStatusObserver(this); | 46 host_->AddStatusObserver(this); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 80 | 75 |
| 81 // Host status observers must be removed on the network thread, so | 76 // Host status observers must be removed on the network thread, so |
| 82 // it must happen here instead of in the destructor. | 77 // it must happen here instead of in the destructor. |
| 83 host_->RemoveStatusObserver(this); | 78 host_->RemoveStatusObserver(this); |
| 84 host_ = NULL; | 79 host_ = NULL; |
| 85 } | 80 } |
| 86 | 81 |
| 87 void HostUserInterface::OnDisconnectCallback() { | 82 void HostUserInterface::OnDisconnectCallback() { |
| 88 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 83 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 89 | 84 |
| 90 MonitorLocalInputs(false); | |
| 91 disconnect_window_->Hide(); | 85 disconnect_window_->Hide(); |
| 92 DisconnectSession(); | 86 DisconnectSession(); |
| 93 } | 87 } |
| 94 | 88 |
| 95 base::SingleThreadTaskRunner* HostUserInterface::network_task_runner() const { | 89 base::SingleThreadTaskRunner* HostUserInterface::network_task_runner() const { |
| 96 return network_task_runner_; | 90 return network_task_runner_; |
| 97 } | 91 } |
| 98 | 92 |
| 99 base::SingleThreadTaskRunner* HostUserInterface::ui_task_runner() const { | 93 base::SingleThreadTaskRunner* HostUserInterface::ui_task_runner() const { |
| 100 return ui_task_runner_; | 94 return ui_task_runner_; |
| 101 } | 95 } |
| 102 | 96 |
| 103 void HostUserInterface::DisconnectSession() const { | 97 void HostUserInterface::DisconnectSession() const { |
| 104 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 98 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 105 | 99 |
| 106 disconnect_callback_.Run(); | 100 disconnect_callback_.Run(); |
| 107 } | 101 } |
| 108 | 102 |
| 109 void HostUserInterface::ProcessOnClientAuthenticated( | 103 void HostUserInterface::ProcessOnClientAuthenticated( |
| 110 const std::string& username) { | 104 const std::string& username) { |
| 111 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 105 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 112 | 106 |
| 113 if (!disconnect_window_->Show( | 107 if (!disconnect_window_->Show( |
| 114 base::Bind(&HostUserInterface::OnDisconnectCallback, weak_ptr_), | 108 base::Bind(&HostUserInterface::OnDisconnectCallback, weak_ptr_), |
| 115 username)) { | 109 username)) { |
| 116 LOG(ERROR) << "Failed to show the disconnect window."; | 110 LOG(ERROR) << "Failed to show the disconnect window."; |
| 117 DisconnectSession(); | 111 DisconnectSession(); |
| 118 return; | 112 return; |
| 119 } | 113 } |
| 120 | |
| 121 MonitorLocalInputs(true); | |
| 122 } | 114 } |
| 123 | 115 |
| 124 void HostUserInterface::ProcessOnClientDisconnected() { | 116 void HostUserInterface::ProcessOnClientDisconnected() { |
| 125 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 117 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 126 | 118 |
| 127 MonitorLocalInputs(false); | |
| 128 disconnect_window_->Hide(); | 119 disconnect_window_->Hide(); |
| 129 } | 120 } |
| 130 | 121 |
| 131 void HostUserInterface::MonitorLocalInputs(bool enable) { | |
| 132 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 133 | |
| 134 if (enable != is_monitoring_local_inputs_) { | |
| 135 if (enable) { | |
| 136 local_input_monitor_->Start(host_, disconnect_callback_); | |
| 137 } else { | |
| 138 local_input_monitor_->Stop(); | |
| 139 } | |
| 140 is_monitoring_local_inputs_ = enable; | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 } // namespace remoting | 122 } // namespace remoting |
| OLD | NEW |