| 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "remoting/host/log_to_server.h" | 47 #include "remoting/host/log_to_server.h" |
| 48 #include "remoting/host/network_settings.h" | 48 #include "remoting/host/network_settings.h" |
| 49 #include "remoting/host/policy_hack/policy_watcher.h" | 49 #include "remoting/host/policy_hack/policy_watcher.h" |
| 50 #include "remoting/host/session_manager_factory.h" | 50 #include "remoting/host/session_manager_factory.h" |
| 51 #include "remoting/host/signaling_connector.h" | 51 #include "remoting/host/signaling_connector.h" |
| 52 #include "remoting/host/usage_stats_consent.h" | 52 #include "remoting/host/usage_stats_consent.h" |
| 53 #include "remoting/host/video_frame_capturer.h" | 53 #include "remoting/host/video_frame_capturer.h" |
| 54 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 54 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 55 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 55 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
| 56 | 56 |
| 57 #if defined(OS_POSIX) |
| 58 #include <signal.h> |
| 59 #include "remoting/host/posix/signal_handler.h" |
| 60 #endif // defined(OS_POSIX) |
| 61 |
| 57 #if defined(OS_MACOSX) | 62 #if defined(OS_MACOSX) |
| 58 #include "base/mac/scoped_cftyperef.h" | 63 #include "base/mac/scoped_cftyperef.h" |
| 59 #include "base/mac/scoped_nsautorelease_pool.h" | 64 #include "base/mac/scoped_nsautorelease_pool.h" |
| 60 #include "remoting/host/curtain_mode_mac.h" | 65 #include "remoting/host/curtain_mode_mac.h" |
| 61 #endif // defined(OS_MACOSX) | 66 #endif // defined(OS_MACOSX) |
| 62 | 67 |
| 63 #if defined(OS_POSIX) | 68 #if defined(OS_POSIX) |
| 64 #include <signal.h> | 69 #include <signal.h> |
| 65 #endif // defined(OS_POSIX) | 70 #endif // defined(OS_POSIX) |
| 66 | 71 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 FilePath default_config_dir = remoting::GetConfigDir(); | 149 FilePath default_config_dir = remoting::GetConfigDir(); |
| 145 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 150 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
| 146 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 151 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| 147 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 152 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 148 } | 153 } |
| 149 #endif // !defined(REMOTING_MULTI_PROCESS) | 154 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 150 | 155 |
| 151 return true; | 156 return true; |
| 152 } | 157 } |
| 153 | 158 |
| 159 #if defined(OS_POSIX) |
| 160 void SigTermHandler(int signal_number) { |
| 161 DCHECK(signal_number == SIGTERM); |
| 162 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 163 LOG(INFO) << "Caught SIGTERM: Shutting down..."; |
| 164 Shutdown(kSuccessExitCode); |
| 165 } |
| 166 #endif |
| 167 |
| 154 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE { | 168 virtual void OnConfigUpdated(const std::string& serialized_config) OVERRIDE { |
| 155 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 169 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 156 | 170 |
| 157 LOG(INFO) << "Processing new host configuration."; | 171 LOG(INFO) << "Processing new host configuration."; |
| 158 | 172 |
| 159 if (!config_.SetSerializedData(serialized_config)) { | 173 if (!config_.SetSerializedData(serialized_config)) { |
| 160 LOG(ERROR) << "Invalid configuration."; | 174 LOG(ERROR) << "Invalid configuration."; |
| 161 OnConfigWatcherError(); | 175 OnConfigWatcherError(); |
| 162 return; | 176 return; |
| 163 } | 177 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 222 |
| 209 context_->network_task_runner()->PostTask( | 223 context_->network_task_runner()->PostTask( |
| 210 FROM_HERE, | 224 FROM_HERE, |
| 211 base::Bind(&HostProcess::Shutdown, base::Unretained(this), | 225 base::Bind(&HostProcess::Shutdown, base::Unretained(this), |
| 212 kInvalidHostConfigurationExitCode)); | 226 kInvalidHostConfigurationExitCode)); |
| 213 } | 227 } |
| 214 | 228 |
| 215 void StartWatchingConfigChanges() { | 229 void StartWatchingConfigChanges() { |
| 216 #if !defined(REMOTING_MULTI_PROCESS) | 230 #if !defined(REMOTING_MULTI_PROCESS) |
| 217 | 231 |
| 218 #if defined(OS_POSIX) | |
| 219 // Ignore SIGHUP sent by the daemon controller since we use | |
| 220 // |ConfigFileWatcher| instead. | |
| 221 signal(SIGHUP, SIG_IGN); | |
| 222 #endif // defined(OS_POSIX) | |
| 223 | |
| 224 // Start watching the host configuration file. | 232 // Start watching the host configuration file. |
| 225 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), | 233 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), |
| 226 context_->file_task_runner(), | 234 context_->file_task_runner(), |
| 227 this)); | 235 this)); |
| 228 config_watcher_->Watch(host_config_path_); | 236 config_watcher_->Watch(host_config_path_); |
| 229 #endif // !defined(REMOTING_MULTI_PROCESS) | 237 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 230 } | 238 } |
| 231 | 239 |
| 240 #if defined(OS_POSIX) |
| 241 void ListenForShutdownSignal() { |
| 242 remoting::RegisterSignalHandler( |
| 243 SIGTERM, |
| 244 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); |
| 245 } |
| 246 #endif // OS_POSIX |
| 247 |
| 232 void CreateAuthenticatorFactory() { | 248 void CreateAuthenticatorFactory() { |
| 233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 249 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 234 scoped_ptr<protocol::AuthenticatorFactory> factory( | 250 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 235 new protocol::Me2MeHostAuthenticatorFactory( | 251 new protocol::Me2MeHostAuthenticatorFactory( |
| 236 key_pair_.GenerateCertificate(), | 252 key_pair_.GenerateCertificate(), |
| 237 *key_pair_.private_key(), host_secret_hash_)); | 253 *key_pair_.private_key(), host_secret_hash_)); |
| 238 host_->SetAuthenticatorFactory(factory.Pass()); | 254 host_->SetAuthenticatorFactory(factory.Pass()); |
| 239 } | 255 } |
| 240 | 256 |
| 241 // IPC::Listener implementation. | 257 // IPC::Listener implementation. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 256 } | 272 } |
| 257 | 273 |
| 258 void StartHostProcess() { | 274 void StartHostProcess() { |
| 259 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 275 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 260 | 276 |
| 261 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 277 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 262 OnConfigWatcherError(); | 278 OnConfigWatcherError(); |
| 263 return; | 279 return; |
| 264 } | 280 } |
| 265 | 281 |
| 282 #if defined(OS_POSIX) |
| 283 context_->network_task_runner()->PostTask( |
| 284 FROM_HERE, |
| 285 base::Bind(&HostProcess::ListenForShutdownSignal, |
| 286 base::Unretained(this))); |
| 287 #endif // OS_POSIX |
| 288 |
| 266 StartWatchingConfigChanges(); | 289 StartWatchingConfigChanges(); |
| 267 } | 290 } |
| 268 | 291 |
| 269 int get_exit_code() const { return exit_code_; } | 292 int get_exit_code() const { return exit_code_; } |
| 270 | 293 |
| 271 private: | 294 private: |
| 272 void ShutdownHostProcess() { | 295 void ShutdownHostProcess() { |
| 273 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 296 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 274 | 297 |
| 275 #if !defined(REMOTING_MULTI_PROCESS) | 298 #if !defined(REMOTING_MULTI_PROCESS) |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 user32.GetFunctionPointer("SetProcessDPIAware")); | 802 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 780 set_process_dpi_aware(); | 803 set_process_dpi_aware(); |
| 781 } | 804 } |
| 782 | 805 |
| 783 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 806 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 784 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 807 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 785 return main(0, NULL); | 808 return main(0, NULL); |
| 786 } | 809 } |
| 787 | 810 |
| 788 #endif // defined(OS_WIN) | 811 #endif // defined(OS_WIN) |
| OLD | NEW |