| 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/daemon_process.h" | 5 #include "remoting/host/daemon_process.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 std::ostream& operator<<(std::ostream& os, const ScreenResolution& resolution) { | 31 std::ostream& operator<<(std::ostream& os, const ScreenResolution& resolution) { |
| 32 return os << resolution.dimensions().width() << "x" | 32 return os << resolution.dimensions().width() << "x" |
| 33 << resolution.dimensions().height() << " at " | 33 << resolution.dimensions().height() << " at " |
| 34 << resolution.dpi().x() << "x" << resolution.dpi().y() << " DPI"; | 34 << resolution.dpi().x() << "x" << resolution.dpi().y() << " DPI"; |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 DaemonProcess::~DaemonProcess() { | 39 DaemonProcess::~DaemonProcess() { |
| 40 DCHECK(!config_watcher_.get()); | 40 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 41 DCHECK(desktop_sessions_.empty()); | 41 |
| 42 host_event_logger_.reset(); |
| 43 weak_factory_.InvalidateWeakPtrs(); |
| 44 |
| 45 config_watcher_.reset(); |
| 46 DeleteAllDesktopSessions(); |
| 42 } | 47 } |
| 43 | 48 |
| 44 void DaemonProcess::OnConfigUpdated(const std::string& serialized_config) { | 49 void DaemonProcess::OnConfigUpdated(const std::string& serialized_config) { |
| 45 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 50 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 46 | 51 |
| 47 if (serialized_config_ != serialized_config) { | 52 if (serialized_config_ != serialized_config) { |
| 48 serialized_config_ = serialized_config; | 53 serialized_config_ = serialized_config; |
| 49 SendToNetwork( | 54 SendToNetwork( |
| 50 new ChromotingDaemonNetworkMsg_Configuration(serialized_config_)); | 55 new ChromotingDaemonNetworkMsg_Configuration(serialized_config_)); |
| 51 } | 56 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 161 |
| 157 VLOG(1) << "Daemon: closed desktop session " << terminal_id; | 162 VLOG(1) << "Daemon: closed desktop session " << terminal_id; |
| 158 SendToNetwork( | 163 SendToNetwork( |
| 159 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); | 164 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); |
| 160 } | 165 } |
| 161 | 166 |
| 162 DaemonProcess::DaemonProcess( | 167 DaemonProcess::DaemonProcess( |
| 163 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 168 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 164 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 169 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 165 const base::Closure& stopped_callback) | 170 const base::Closure& stopped_callback) |
| 166 : Stoppable(caller_task_runner, stopped_callback), | 171 : caller_task_runner_(caller_task_runner), |
| 167 caller_task_runner_(caller_task_runner), | |
| 168 io_task_runner_(io_task_runner), | 172 io_task_runner_(io_task_runner), |
| 169 next_terminal_id_(0), | 173 next_terminal_id_(0), |
| 174 stopped_callback_(stopped_callback), |
| 170 weak_factory_(this) { | 175 weak_factory_(this) { |
| 171 DCHECK(caller_task_runner->BelongsToCurrentThread()); | 176 DCHECK(caller_task_runner->BelongsToCurrentThread()); |
| 172 } | 177 } |
| 173 | 178 |
| 174 void DaemonProcess::CreateDesktopSession(int terminal_id, | 179 void DaemonProcess::CreateDesktopSession(int terminal_id, |
| 175 const ScreenResolution& resolution, | 180 const ScreenResolution& resolution, |
| 176 bool virtual_terminal) { | 181 bool virtual_terminal) { |
| 177 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 182 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 178 | 183 |
| 179 // Validate the supplied terminal ID. An attempt to create a desktop session | 184 // Validate the supplied terminal ID. An attempt to create a desktop session |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 this)); | 268 this)); |
| 264 config_watcher_->Watch(config_path); | 269 config_watcher_->Watch(config_path); |
| 265 | 270 |
| 266 host_event_logger_ = | 271 host_event_logger_ = |
| 267 HostEventLogger::Create(weak_factory_.GetWeakPtr(), kApplicationName); | 272 HostEventLogger::Create(weak_factory_.GetWeakPtr(), kApplicationName); |
| 268 | 273 |
| 269 // Launch the process. | 274 // Launch the process. |
| 270 LaunchNetworkProcess(); | 275 LaunchNetworkProcess(); |
| 271 } | 276 } |
| 272 | 277 |
| 278 void DaemonProcess::Stop() { |
| 279 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 280 |
| 281 if (!stopped_callback_.is_null()) { |
| 282 base::Closure stopped_callback = stopped_callback_; |
| 283 stopped_callback_.Reset(); |
| 284 stopped_callback.Run(); |
| 285 } |
| 286 } |
| 287 |
| 273 bool DaemonProcess::WasTerminalIdAllocated(int terminal_id) { | 288 bool DaemonProcess::WasTerminalIdAllocated(int terminal_id) { |
| 274 return terminal_id < next_terminal_id_; | 289 return terminal_id < next_terminal_id_; |
| 275 } | 290 } |
| 276 | 291 |
| 277 void DaemonProcess::OnAccessDenied(const std::string& jid) { | 292 void DaemonProcess::OnAccessDenied(const std::string& jid) { |
| 278 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 293 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 279 | 294 |
| 280 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnAccessDenied(jid)); | 295 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnAccessDenied(jid)); |
| 281 } | 296 } |
| 282 | 297 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 360 |
| 346 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnStart(xmpp_login)); | 361 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnStart(xmpp_login)); |
| 347 } | 362 } |
| 348 | 363 |
| 349 void DaemonProcess::OnHostShutdown() { | 364 void DaemonProcess::OnHostShutdown() { |
| 350 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 365 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 351 | 366 |
| 352 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnShutdown()); | 367 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnShutdown()); |
| 353 } | 368 } |
| 354 | 369 |
| 355 void DaemonProcess::DoStop() { | |
| 356 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | |
| 357 | |
| 358 host_event_logger_.reset(); | |
| 359 weak_factory_.InvalidateWeakPtrs(); | |
| 360 | |
| 361 config_watcher_.reset(); | |
| 362 DeleteAllDesktopSessions(); | |
| 363 | |
| 364 CompleteStopping(); | |
| 365 } | |
| 366 | |
| 367 void DaemonProcess::DeleteAllDesktopSessions() { | 370 void DaemonProcess::DeleteAllDesktopSessions() { |
| 368 while (!desktop_sessions_.empty()) { | 371 while (!desktop_sessions_.empty()) { |
| 369 delete desktop_sessions_.front(); | 372 delete desktop_sessions_.front(); |
| 370 desktop_sessions_.pop_front(); | 373 desktop_sessions_.pop_front(); |
| 371 } | 374 } |
| 372 } | 375 } |
| 373 | 376 |
| 374 } // namespace remoting | 377 } // namespace remoting |
| OLD | NEW |