Chromium Code Reviews| 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 // This file implements a standalone host process for Me2Me. | 5 // This file implements a standalone host process for Me2Me. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | |
| 8 | 9 |
| 9 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "base/atomic_sequence_num.h" | |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/callback.h" | 13 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 18 #include "base/scoped_native_library.h" | 20 #include "base/scoped_native_library.h" |
| 19 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 32 #include "remoting/base/auto_thread_task_runner.h" | 34 #include "remoting/base/auto_thread_task_runner.h" |
| 33 #include "remoting/base/breakpad.h" | 35 #include "remoting/base/breakpad.h" |
| 34 #include "remoting/base/constants.h" | 36 #include "remoting/base/constants.h" |
| 35 #include "remoting/host/branding.h" | 37 #include "remoting/host/branding.h" |
| 36 #include "remoting/host/chromoting_host.h" | 38 #include "remoting/host/chromoting_host.h" |
| 37 #include "remoting/host/chromoting_host_context.h" | 39 #include "remoting/host/chromoting_host_context.h" |
| 38 #include "remoting/host/chromoting_messages.h" | 40 #include "remoting/host/chromoting_messages.h" |
| 39 #include "remoting/host/config_file_watcher.h" | 41 #include "remoting/host/config_file_watcher.h" |
| 40 #include "remoting/host/curtain_mode.h" | 42 #include "remoting/host/curtain_mode.h" |
| 41 #include "remoting/host/curtaining_host_observer.h" | 43 #include "remoting/host/curtaining_host_observer.h" |
| 44 #include "remoting/host/daemon_sender.h" | |
| 42 #include "remoting/host/desktop_environment_factory.h" | 45 #include "remoting/host/desktop_environment_factory.h" |
| 43 #include "remoting/host/desktop_resizer.h" | 46 #include "remoting/host/desktop_resizer.h" |
| 44 #include "remoting/host/dns_blackhole_checker.h" | 47 #include "remoting/host/dns_blackhole_checker.h" |
| 45 #include "remoting/host/event_executor.h" | 48 #include "remoting/host/event_executor.h" |
| 46 #include "remoting/host/heartbeat_sender.h" | 49 #include "remoting/host/heartbeat_sender.h" |
| 47 #include "remoting/host/host_config.h" | 50 #include "remoting/host/host_config.h" |
| 48 #include "remoting/host/host_event_logger.h" | 51 #include "remoting/host/host_event_logger.h" |
| 49 #include "remoting/host/host_exit_codes.h" | 52 #include "remoting/host/host_exit_codes.h" |
| 50 #include "remoting/host/host_user_interface.h" | 53 #include "remoting/host/host_user_interface.h" |
| 54 #include "remoting/host/ipc_desktop_environment_factory.h" | |
| 51 #include "remoting/host/json_host_config.h" | 55 #include "remoting/host/json_host_config.h" |
| 52 #include "remoting/host/log_to_server.h" | 56 #include "remoting/host/log_to_server.h" |
| 53 #include "remoting/host/network_settings.h" | 57 #include "remoting/host/network_settings.h" |
| 54 #include "remoting/host/policy_hack/policy_watcher.h" | 58 #include "remoting/host/policy_hack/policy_watcher.h" |
| 55 #include "remoting/host/resizing_host_observer.h" | 59 #include "remoting/host/resizing_host_observer.h" |
| 56 #include "remoting/host/session_manager_factory.h" | 60 #include "remoting/host/session_manager_factory.h" |
| 57 #include "remoting/host/signaling_connector.h" | 61 #include "remoting/host/signaling_connector.h" |
| 58 #include "remoting/host/usage_stats_consent.h" | 62 #include "remoting/host/usage_stats_consent.h" |
| 59 #include "remoting/host/video_frame_capturer.h" | 63 #include "remoting/host/video_frame_capturer.h" |
| 60 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 64 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 109 |
| 106 void QuitMessageLoop(MessageLoop* message_loop) { | 110 void QuitMessageLoop(MessageLoop* message_loop) { |
| 107 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 111 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 108 } | 112 } |
| 109 | 113 |
| 110 } // namespace | 114 } // namespace |
| 111 | 115 |
| 112 namespace remoting { | 116 namespace remoting { |
| 113 | 117 |
| 114 class HostProcess | 118 class HostProcess |
| 115 : public HeartbeatSender::Listener, | 119 : public ConfigFileWatcher::Delegate, |
| 116 public IPC::Listener, | 120 #if defined(REMOTING_MULTI_PROCESS) |
| 117 public ConfigFileWatcher::Delegate { | 121 public DaemonSender, |
| 122 #endif // defined(REMOTING_MULTI_PROCESS) | |
| 123 public HeartbeatSender::Listener, | |
| 124 public IPC::Listener { | |
| 118 public: | 125 public: |
| 119 explicit HostProcess(scoped_ptr<ChromotingHostContext> context) | 126 explicit HostProcess(scoped_ptr<ChromotingHostContext> context) |
| 120 : context_(context.Pass()), | 127 : context_(context.Pass()), |
| 121 config_(FilePath()), | 128 config_(FilePath()), |
| 122 allow_nat_traversal_(true), | 129 allow_nat_traversal_(true), |
| 123 restarting_(false), | 130 restarting_(false), |
| 124 shutting_down_(false), | 131 shutting_down_(false), |
| 125 #if defined(OS_WIN) | 132 #if defined(OS_WIN) && defined(REMOTING_MULTI_PROCESS) |
| 133 desktop_environment_factory_(new IpcDesktopEnvironmentFactory( | |
| 134 context_->input_task_runner(), | |
| 135 context_->ui_task_runner(), | |
| 136 ALLOW_THIS_IN_INITIALIZER_LIST(this))), | |
| 137 #elif defined(OS_WIN) && !defined(REMOTING_MULTI_PROCESS) | |
| 126 desktop_environment_factory_(new SessionDesktopEnvironmentFactory( | 138 desktop_environment_factory_(new SessionDesktopEnvironmentFactory( |
| 127 context_->input_task_runner(), context_->ui_task_runner())), | 139 context_->input_task_runner(), context_->ui_task_runner())), |
| 128 #else // !defined(OS_WIN) | 140 #else // !defined(OS_WIN) |
| 129 desktop_environment_factory_(new DesktopEnvironmentFactory( | 141 desktop_environment_factory_(new DesktopEnvironmentFactory( |
| 130 context_->input_task_runner(), context_->ui_task_runner())), | 142 context_->input_task_runner(), context_->ui_task_runner())), |
| 131 #endif // !defined(OS_WIN) | 143 #endif // !defined(OS_WIN) |
| 132 desktop_resizer_(DesktopResizer::Create()), | 144 desktop_resizer_(DesktopResizer::Create()), |
| 133 exit_code_(kSuccessExitCode) { | 145 exit_code_(kSuccessExitCode) { |
| 134 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 146 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 135 curtain_ = CurtainMode::Create( | 147 curtain_ = CurtainMode::Create( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 | 286 |
| 275 // IPC::Listener implementation. | 287 // IPC::Listener implementation. |
| 276 virtual bool OnMessageReceived(const IPC::Message& message) { | 288 virtual bool OnMessageReceived(const IPC::Message& message) { |
| 277 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 289 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 278 | 290 |
| 279 #if defined(REMOTING_MULTI_PROCESS) | 291 #if defined(REMOTING_MULTI_PROCESS) |
| 280 bool handled = true; | 292 bool handled = true; |
| 281 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) | 293 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) |
| 282 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration, | 294 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration, |
| 283 OnConfigUpdated) | 295 OnConfigUpdated) |
| 296 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_TerminalClosed, | |
| 297 OnTerminalClosed) | |
| 284 IPC_MESSAGE_UNHANDLED(handled = false) | 298 IPC_MESSAGE_UNHANDLED(handled = false) |
| 285 IPC_END_MESSAGE_MAP() | 299 IPC_END_MESSAGE_MAP() |
| 286 return handled; | 300 return handled; |
| 287 #else // !defined(REMOTING_MULTI_PROCESS) | 301 #else // !defined(REMOTING_MULTI_PROCESS) |
| 288 return false; | 302 return false; |
| 289 #endif // !defined(REMOTING_MULTI_PROCESS) | 303 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 290 } | 304 } |
| 291 | 305 |
| 292 void StartHostProcess() { | 306 void StartHostProcess() { |
| 293 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 307 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 294 | 308 |
| 295 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 309 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 296 OnConfigWatcherError(); | 310 OnConfigWatcherError(); |
| 297 return; | 311 return; |
| 298 } | 312 } |
| 299 | 313 |
| 300 context_->network_task_runner()->PostTask( | 314 context_->network_task_runner()->PostTask( |
| 301 FROM_HERE, | 315 FROM_HERE, |
| 302 base::Bind(&HostProcess::ListenForShutdownSignal, | 316 base::Bind(&HostProcess::ListenForShutdownSignal, |
| 303 base::Unretained(this))); | 317 base::Unretained(this))); |
| 304 | 318 |
| 305 StartWatchingConfigChanges(); | 319 StartWatchingConfigChanges(); |
| 306 } | 320 } |
| 307 | 321 |
| 308 int get_exit_code() const { return exit_code_; } | 322 int get_exit_code() const { return exit_code_; } |
| 309 | 323 |
| 324 #if defined(REMOTING_MULTI_PROCESS) | |
| 325 // DaemonSender implementation | |
| 326 virtual void CloseTerminal(DesktopEnvironment* desktop_environment) OVERRIDE; | |
| 327 virtual void OpenTerminal(DesktopEnvironment* desktop_environment) OVERRIDE; | |
| 328 | |
| 329 // Maps |termonal_id| to the correspondinf desktop environment instance and | |
|
Wez
2012/10/13 00:47:15
typo: |terminal_id|
Wez
2012/10/13 00:47:15
typo: corresponding
Wez
2012/10/13 00:47:15
nit: desktop environment -> DesktopEnvironment
Wez
2012/10/13 00:47:15
nit: Reword "Closes any client connection that is
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
| |
| 330 // closes the corresponding connection if needed. | |
| 331 void OnTerminalClosed(int terminal_id); | |
| 332 #endif // defined(REMOTING_MULTI_PROCESS) | |
| 333 | |
| 310 private: | 334 private: |
| 311 void ShutdownHostProcess() { | 335 void ShutdownHostProcess() { |
| 312 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 336 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 313 | 337 |
| 314 // Tear down resources that use ChromotingHostContext threads. | 338 // Tear down resources that use ChromotingHostContext threads. |
| 315 config_watcher_.reset(); | 339 config_watcher_.reset(); |
| 316 daemon_channel_.reset(); | 340 daemon_channel_.reset(); |
| 317 desktop_environment_factory_.reset(); | 341 desktop_environment_factory_.reset(); |
| 318 host_user_interface_.reset(); | 342 host_user_interface_.reset(); |
| 319 | 343 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 scoped_ptr<SignalingConnector> signaling_connector_; | 709 scoped_ptr<SignalingConnector> signaling_connector_; |
| 686 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 710 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 687 scoped_ptr<LogToServer> log_to_server_; | 711 scoped_ptr<LogToServer> log_to_server_; |
| 688 scoped_ptr<HostEventLogger> host_event_logger_; | 712 scoped_ptr<HostEventLogger> host_event_logger_; |
| 689 | 713 |
| 690 scoped_ptr<HostUserInterface> host_user_interface_; | 714 scoped_ptr<HostUserInterface> host_user_interface_; |
| 691 | 715 |
| 692 scoped_refptr<ChromotingHost> host_; | 716 scoped_refptr<ChromotingHost> host_; |
| 693 | 717 |
| 694 int exit_code_; | 718 int exit_code_; |
| 719 | |
| 720 #if defined(REMOTING_MULTI_PROCESS) | |
| 721 // A list of desktop environment instances known to the daemon process. | |
| 722 std::map<int, DesktopEnvironment*> registered_terminals_; | |
|
Wez
2012/10/13 00:47:15
nit: registered -> active
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
| |
| 723 | |
| 724 // This gives us more than 67 years of unique IDs assuming a new ID is | |
| 725 // allocated every second. | |
| 726 static base::StaticAtomicSequenceNumber terminal_id_; | |
|
Wez
2012/10/13 00:47:15
Do we need StatucAtomicSequenceNumber; we're not r
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
| |
| 727 #endif // defined(REMOTING_MULTI_PROCESS) | |
| 728 | |
| 695 }; | 729 }; |
| 696 | 730 |
| 731 #if defined(REMOTING_MULTI_PROCESS) | |
|
Wez
2012/10/13 00:47:15
I really think we need to move the multi-process s
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
| |
| 732 | |
| 733 base::StaticAtomicSequenceNumber HostProcess::terminal_id_; | |
| 734 | |
| 735 void HostProcess::CloseTerminal(DesktopEnvironment* desktop_environment) { | |
| 736 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 737 | |
| 738 std::map<int, DesktopEnvironment*>::iterator i; | |
| 739 for (i = registered_terminals_.begin(); i != registered_terminals_.end(); | |
| 740 ++i) { | |
| 741 if (i->second == desktop_environment) | |
| 742 break; | |
| 743 } | |
| 744 | |
| 745 if (i != registered_terminals_.end()) { | |
| 746 int terminal_id = i->first; | |
| 747 registered_terminals_.erase(i); | |
| 748 | |
| 749 VLOG(1) << "Network: unregistered desktop environment " << terminal_id; | |
| 750 daemon_channel_->Send( | |
| 751 new ChromotingNetworkHostMsg_CloseTerminal(terminal_id)); | |
| 752 } | |
| 753 } | |
| 754 | |
| 755 void HostProcess::OpenTerminal(DesktopEnvironment* desktop_environment) { | |
|
Wez
2012/10/13 00:47:15
OpenTerminal -> CreateTerminal / AttachTerminal
alexeypa (please no reviews)
2012/10/16 19:32:25
Done.
| |
| 756 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 757 | |
| 758 int terminal_id = terminal_id_.GetNext(); | |
| 759 bool inserted = registered_terminals_.insert( | |
| 760 std::make_pair(terminal_id, desktop_environment)).second; | |
| 761 CHECK(inserted); | |
| 762 | |
| 763 VLOG(1) << "Network: registered desktop environment " << terminal_id; | |
| 764 daemon_channel_->Send(new ChromotingNetworkHostMsg_OpenTerminal(terminal_id)); | |
| 765 } | |
| 766 | |
| 767 void HostProcess::OnTerminalClosed(int terminal_id) { | |
| 768 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | |
| 769 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | |
| 770 &HostProcess::OnTerminalClosed, base::Unretained(this), terminal_id)); | |
| 771 return; | |
| 772 } | |
| 773 | |
| 774 std::map<int, DesktopEnvironment*>::iterator i = | |
| 775 registered_terminals_.find(terminal_id); | |
| 776 if (i != registered_terminals_.end()) { | |
| 777 DesktopEnvironment* desktop_environment = i->second; | |
| 778 registered_terminals_.erase(i); | |
|
Wez
2012/10/13 00:47:15
Why not let the client disconnection trigger Close
alexeypa (please no reviews)
2012/10/16 19:32:25
This gives one less message sent over IPC and make
| |
| 779 | |
| 780 // Disconnect the client for given desktop environment. | |
| 781 host_->DisconnectClient(desktop_environment); | |
| 782 } | |
| 783 } | |
| 784 | |
| 785 #endif // defined(REMOTING_MULTI_PROCESS) | |
| 786 | |
| 697 } // namespace remoting | 787 } // namespace remoting |
| 698 | 788 |
| 699 int main(int argc, char** argv) { | 789 int main(int argc, char** argv) { |
| 700 #if defined(OS_MACOSX) | 790 #if defined(OS_MACOSX) |
| 701 // Needed so we don't leak objects when threads are created. | 791 // Needed so we don't leak objects when threads are created. |
| 702 base::mac::ScopedNSAutoreleasePool pool; | 792 base::mac::ScopedNSAutoreleasePool pool; |
| 703 #endif | 793 #endif |
| 704 | 794 |
| 705 CommandLine::Init(argc, argv); | 795 CommandLine::Init(argc, argv); |
| 706 | 796 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 user32.GetFunctionPointer("SetProcessDPIAware")); | 889 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 800 set_process_dpi_aware(); | 890 set_process_dpi_aware(); |
| 801 } | 891 } |
| 802 | 892 |
| 803 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 893 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 804 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 894 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 805 return main(0, NULL); | 895 return main(0, NULL); |
| 806 } | 896 } |
| 807 | 897 |
| 808 #endif // defined(OS_WIN) | 898 #endif // defined(OS_WIN) |
| OLD | NEW |