| 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 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/scoped_native_library.h" | 17 #include "base/scoped_native_library.h" |
| 18 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/stringize_macros.h" | 20 #include "base/stringize_macros.h" |
| 21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "crypto/nss_util.h" | 26 #include "crypto/nss_util.h" |
| 27 #include "google_apis/google_api_keys.h" | 27 #include "google_apis/google_api_keys.h" |
| 28 #include "ipc/ipc_channel.h" | 28 #include "ipc/ipc_channel.h" |
| 29 #include "ipc/ipc_channel_proxy.h" | 29 #include "ipc/ipc_channel_proxy.h" |
| 30 #include "ipc/ipc_listener.h" |
| 30 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
| 31 #include "net/socket/ssl_server_socket.h" | 32 #include "net/socket/ssl_server_socket.h" |
| 32 #include "remoting/base/auto_thread_task_runner.h" | 33 #include "remoting/base/auto_thread_task_runner.h" |
| 33 #include "remoting/base/breakpad.h" | 34 #include "remoting/base/breakpad.h" |
| 34 #include "remoting/base/constants.h" | 35 #include "remoting/base/constants.h" |
| 35 #include "remoting/host/branding.h" | 36 #include "remoting/host/branding.h" |
| 36 #include "remoting/host/chromoting_host.h" | 37 #include "remoting/host/chromoting_host.h" |
| 37 #include "remoting/host/chromoting_host_context.h" | 38 #include "remoting/host/chromoting_host_context.h" |
| 38 #include "remoting/host/chromoting_messages.h" | 39 #include "remoting/host/chromoting_messages.h" |
| 39 #include "remoting/host/config_file_watcher.h" | 40 #include "remoting/host/config_file_watcher.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 bool InitWithCommandLine(const CommandLine* cmd_line); | 126 bool InitWithCommandLine(const CommandLine* cmd_line); |
| 126 | 127 |
| 127 // ConfigFileWatcher::Delegate interface. | 128 // ConfigFileWatcher::Delegate interface. |
| 128 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE; | 129 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE; |
| 129 virtual void OnConfigWatcherError() OVERRIDE; | 130 virtual void OnConfigWatcherError() OVERRIDE; |
| 130 | 131 |
| 131 void StartWatchingConfigChanges(); | 132 void StartWatchingConfigChanges(); |
| 132 void CreateAuthenticatorFactory(); | 133 void CreateAuthenticatorFactory(); |
| 133 | 134 |
| 134 // IPC::Listener implementation. | 135 // IPC::Listener implementation. |
| 135 virtual bool OnMessageReceived(const IPC::Message& message); | 136 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 137 virtual void OnChannelError() OVERRIDE; |
| 136 | 138 |
| 137 // HeartbeatSender::Listener overrides. | 139 // HeartbeatSender::Listener overrides. |
| 138 virtual void OnUnknownHostIdError() OVERRIDE; | 140 virtual void OnUnknownHostIdError() OVERRIDE; |
| 139 | 141 |
| 140 void StartHostProcess(); | 142 void StartHostProcess(); |
| 141 | 143 |
| 142 int get_exit_code() const; | 144 int get_exit_code() const; |
| 143 | 145 |
| 144 private: | 146 private: |
| 145 #if defined(OS_POSIX) | 147 #if defined(OS_POSIX) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 174 void RestartHost(); | 176 void RestartHost(); |
| 175 | 177 |
| 176 void RestartOnHostShutdown(); | 178 void RestartOnHostShutdown(); |
| 177 | 179 |
| 178 void Shutdown(int exit_code); | 180 void Shutdown(int exit_code); |
| 179 | 181 |
| 180 void OnShutdownFinished(); | 182 void OnShutdownFinished(); |
| 181 | 183 |
| 182 void ResetHost(); | 184 void ResetHost(); |
| 183 | 185 |
| 186 // Crashes the process in response to a daemon's request. The daemon passes |
| 187 // the location of the code that detected the fatal error resulted in this |
| 188 // request. |
| 189 void OnCrash(const std::string& function_name, |
| 190 const std::string& file_name, |
| 191 const int& line_number); |
| 192 |
| 184 scoped_ptr<ChromotingHostContext> context_; | 193 scoped_ptr<ChromotingHostContext> context_; |
| 185 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 194 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 186 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 195 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 187 | 196 |
| 188 FilePath host_config_path_; | 197 FilePath host_config_path_; |
| 189 scoped_ptr<ConfigFileWatcher> config_watcher_; | 198 scoped_ptr<ConfigFileWatcher> config_watcher_; |
| 190 | 199 |
| 191 // Accessed on the network thread. | 200 // Accessed on the network thread. |
| 192 std::string host_id_; | 201 std::string host_id_; |
| 193 protocol::SharedSecretHash host_secret_hash_; | 202 protocol::SharedSecretHash host_secret_hash_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 #endif // defined(REMOTING_MULTI_PROCESS) | 248 #endif // defined(REMOTING_MULTI_PROCESS) |
| 240 exit_code_(kSuccessExitCode) { | 249 exit_code_(kSuccessExitCode) { |
| 241 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 250 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 242 curtain_ = CurtainMode::Create( | 251 curtain_ = CurtainMode::Create( |
| 243 base::Bind(&HostProcess::OnDisconnectRequested, | 252 base::Bind(&HostProcess::OnDisconnectRequested, |
| 244 base::Unretained(this)), | 253 base::Unretained(this)), |
| 245 base::Bind(&HostProcess::RejectAuthenticatingClient, | 254 base::Bind(&HostProcess::RejectAuthenticatingClient, |
| 246 base::Unretained(this))); | 255 base::Unretained(this))); |
| 247 } | 256 } |
| 248 | 257 |
| 249 // Crashes the process in response to a daemon's request. The daemon passes | |
| 250 // the location of the code that detected the fatal error resulted in this | |
| 251 // request. | |
| 252 void OnCrash(const std::string& function_name, | |
| 253 const std::string& file_name, | |
| 254 const int& line_number) { | |
| 255 CHECK(false); | |
| 256 } | |
| 257 | |
| 258 bool HostProcess::InitWithCommandLine(const CommandLine* cmd_line) { | 258 bool HostProcess::InitWithCommandLine(const CommandLine* cmd_line) { |
| 259 #if defined(REMOTING_MULTI_PROCESS) | 259 #if defined(REMOTING_MULTI_PROCESS) |
| 260 // Parse the handle value and convert it to a handle/file descriptor. | 260 // Parse the handle value and convert it to a handle/file descriptor. |
| 261 std::string channel_name = | 261 std::string channel_name = |
| 262 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); | 262 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); |
| 263 | 263 |
| 264 int pipe_handle = 0; | 264 int pipe_handle = 0; |
| 265 if (channel_name.empty() || | 265 if (channel_name.empty() || |
| 266 !base::StringToInt(channel_name, &pipe_handle)) { | 266 !base::StringToInt(channel_name, &pipe_handle)) { |
| 267 LOG(ERROR) << "Invalid '" << kDaemonPipeSwitchName | 267 LOG(ERROR) << "Invalid '" << kDaemonPipeSwitchName |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 bool HostProcess::OnMessageReceived(const IPC::Message& message) { | 398 bool HostProcess::OnMessageReceived(const IPC::Message& message) { |
| 399 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 399 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 400 | 400 |
| 401 #if defined(REMOTING_MULTI_PROCESS) | 401 #if defined(REMOTING_MULTI_PROCESS) |
| 402 bool handled = true; | 402 bool handled = true; |
| 403 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) | 403 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) |
| 404 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Crash, | 404 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Crash, |
| 405 OnCrash) | 405 OnCrash) |
| 406 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration, | 406 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration, |
| 407 OnConfigUpdated) | 407 OnConfigUpdated) |
| 408 IPC_MESSAGE_FORWARD( |
| 409 ChromotingDaemonNetworkMsg_DesktopAttached, |
| 410 desktop_session_connector_, |
| 411 DesktopSessionConnector::OnDesktopSessionAgentAttached) |
| 408 IPC_MESSAGE_FORWARD(ChromotingDaemonNetworkMsg_TerminalDisconnected, | 412 IPC_MESSAGE_FORWARD(ChromotingDaemonNetworkMsg_TerminalDisconnected, |
| 409 desktop_session_connector_, | 413 desktop_session_connector_, |
| 410 DesktopSessionConnector::OnTerminalDisconnected) | 414 DesktopSessionConnector::OnTerminalDisconnected) |
| 411 IPC_MESSAGE_UNHANDLED(handled = false) | 415 IPC_MESSAGE_UNHANDLED(handled = false) |
| 412 IPC_END_MESSAGE_MAP() | 416 IPC_END_MESSAGE_MAP() |
| 413 return handled; | 417 return handled; |
| 414 #else // !defined(REMOTING_MULTI_PROCESS) | 418 #else // !defined(REMOTING_MULTI_PROCESS) |
| 415 return false; | 419 return false; |
| 416 #endif // !defined(REMOTING_MULTI_PROCESS) | 420 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 417 } | 421 } |
| 418 | 422 |
| 423 void HostProcess::OnChannelError() { |
| 424 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 425 |
| 426 // Shutdown the host if the daemon disconnected the channel. |
| 427 context_->network_task_runner()->PostTask( |
| 428 FROM_HERE, |
| 429 base::Bind(&HostProcess::Shutdown, base::Unretained(this), |
| 430 kSuccessExitCode)); |
| 431 } |
| 432 |
| 419 void HostProcess::StartHostProcess() { | 433 void HostProcess::StartHostProcess() { |
| 420 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 434 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 421 | 435 |
| 422 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 436 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 423 OnConfigWatcherError(); | 437 OnConfigWatcherError(); |
| 424 return; | 438 return; |
| 425 } | 439 } |
| 426 | 440 |
| 427 // Create a desktop environment factory appropriate to the build type & | 441 // Create a desktop environment factory appropriate to the build type & |
| 428 // platform. | 442 // platform. |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 837 |
| 824 curtaining_host_observer_.reset(); | 838 curtaining_host_observer_.reset(); |
| 825 host_event_logger_.reset(); | 839 host_event_logger_.reset(); |
| 826 log_to_server_.reset(); | 840 log_to_server_.reset(); |
| 827 heartbeat_sender_.reset(); | 841 heartbeat_sender_.reset(); |
| 828 signaling_connector_.reset(); | 842 signaling_connector_.reset(); |
| 829 signal_strategy_.reset(); | 843 signal_strategy_.reset(); |
| 830 resizing_host_observer_.reset(); | 844 resizing_host_observer_.reset(); |
| 831 } | 845 } |
| 832 | 846 |
| 847 void HostProcess::OnCrash(const std::string& function_name, |
| 848 const std::string& file_name, |
| 849 const int& line_number) { |
| 850 CHECK(false); |
| 851 } |
| 852 |
| 833 } // namespace remoting | 853 } // namespace remoting |
| 834 | 854 |
| 835 int main(int argc, char** argv) { | 855 int main(int argc, char** argv) { |
| 836 #if defined(OS_MACOSX) | 856 #if defined(OS_MACOSX) |
| 837 // Needed so we don't leak objects when threads are created. | 857 // Needed so we don't leak objects when threads are created. |
| 838 base::mac::ScopedNSAutoreleasePool pool; | 858 base::mac::ScopedNSAutoreleasePool pool; |
| 839 #endif | 859 #endif |
| 840 | 860 |
| 841 CommandLine::Init(argc, argv); | 861 CommandLine::Init(argc, argv); |
| 842 | 862 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 user32.GetFunctionPointer("SetProcessDPIAware")); | 943 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 924 set_process_dpi_aware(); | 944 set_process_dpi_aware(); |
| 925 } | 945 } |
| 926 | 946 |
| 927 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 947 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 928 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 948 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 929 return main(0, NULL); | 949 return main(0, NULL); |
| 930 } | 950 } |
| 931 | 951 |
| 932 #endif // defined(OS_WIN) | 952 #endif // defined(OS_WIN) |
| OLD | NEW |