| 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 19 matching lines...) Expand all Loading... |
| 30 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
| 31 #include "net/socket/ssl_server_socket.h" | 31 #include "net/socket/ssl_server_socket.h" |
| 32 #include "remoting/base/auto_thread_task_runner.h" | 32 #include "remoting/base/auto_thread_task_runner.h" |
| 33 #include "remoting/base/breakpad.h" | 33 #include "remoting/base/breakpad.h" |
| 34 #include "remoting/base/constants.h" | 34 #include "remoting/base/constants.h" |
| 35 #include "remoting/host/branding.h" | 35 #include "remoting/host/branding.h" |
| 36 #include "remoting/host/chromoting_host.h" | 36 #include "remoting/host/chromoting_host.h" |
| 37 #include "remoting/host/chromoting_host_context.h" | 37 #include "remoting/host/chromoting_host_context.h" |
| 38 #include "remoting/host/chromoting_messages.h" | 38 #include "remoting/host/chromoting_messages.h" |
| 39 #include "remoting/host/config_file_watcher.h" | 39 #include "remoting/host/config_file_watcher.h" |
| 40 #include "remoting/host/constants.h" |
| 40 #include "remoting/host/config_file_watcher.h" | 41 #include "remoting/host/config_file_watcher.h" |
| 41 #include "remoting/host/desktop_environment_factory.h" | 42 #include "remoting/host/desktop_environment_factory.h" |
| 42 #include "remoting/host/dns_blackhole_checker.h" | 43 #include "remoting/host/dns_blackhole_checker.h" |
| 43 #include "remoting/host/event_executor.h" | 44 #include "remoting/host/event_executor.h" |
| 44 #include "remoting/host/heartbeat_sender.h" | 45 #include "remoting/host/heartbeat_sender.h" |
| 45 #include "remoting/host/host_config.h" | 46 #include "remoting/host/host_config.h" |
| 46 #include "remoting/host/host_event_logger.h" | 47 #include "remoting/host/host_event_logger.h" |
| 47 #include "remoting/host/host_exit_codes.h" | |
| 48 #include "remoting/host/host_user_interface.h" | 48 #include "remoting/host/host_user_interface.h" |
| 49 #include "remoting/host/json_host_config.h" | 49 #include "remoting/host/json_host_config.h" |
| 50 #include "remoting/host/log_to_server.h" | 50 #include "remoting/host/log_to_server.h" |
| 51 #include "remoting/host/network_settings.h" | 51 #include "remoting/host/network_settings.h" |
| 52 #include "remoting/host/policy_hack/policy_watcher.h" | 52 #include "remoting/host/policy_hack/policy_watcher.h" |
| 53 #include "remoting/host/session_manager_factory.h" | 53 #include "remoting/host/session_manager_factory.h" |
| 54 #include "remoting/host/signaling_connector.h" | 54 #include "remoting/host/signaling_connector.h" |
| 55 #include "remoting/host/usage_stats_consent.h" | 55 #include "remoting/host/usage_stats_consent.h" |
| 56 #include "remoting/host/video_frame_capturer.h" | 56 #include "remoting/host/video_frame_capturer.h" |
| 57 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 57 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (!ApplyConfig()) { | 191 if (!ApplyConfig()) { |
| 192 LOG(ERROR) << "Failed to apply the configuration."; | 192 LOG(ERROR) << "Failed to apply the configuration."; |
| 193 OnConfigWatcherError(); | 193 OnConfigWatcherError(); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Start watching the policy (and eventually start the host) if this is | 197 // Start watching the policy (and eventually start the host) if this is |
| 198 // the first configuration update. Otherwise, post a task to create new | 198 // the first configuration update. Otherwise, post a task to create new |
| 199 // authenticator factory in case PIN has changed. | 199 // authenticator factory in case PIN has changed. |
| 200 if (policy_watcher_.get() == NULL) { | 200 if (policy_watcher_.get() == NULL) { |
| 201 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 201 bool want_user_interface = true; | 202 bool want_user_interface = true; |
| 202 #if defined(OS_LINUX) | 203 |
| 203 want_user_interface = false; | 204 #if defined(OS_MACOSX) |
| 204 #elif defined(OS_MACOSX) | |
| 205 // Don't try to display any UI on top of the system's login screen as this | 205 // Don't try to display any UI on top of the system's login screen as this |
| 206 // is rejected by the Window Server on OS X 10.7.4, and prevents the | 206 // is rejected by the Window Server on OS X 10.7.4, and prevents the |
| 207 // capturer from working (http://crbug.com/140984). | 207 // capturer from working (http://crbug.com/140984). |
| 208 | 208 |
| 209 // TODO(lambroslambrou): Use a better technique of detecting whether we're | 209 // TODO(lambroslambrou): Use a better technique of detecting whether we're |
| 210 // running in the LoginWindow context, and refactor this into a separate | 210 // running in the LoginWindow context, and refactor this into a separate |
| 211 // function to be used here and in CurtainMode::ActivateCurtain(). | 211 // function to be used here and in CurtainMode::ActivateCurtain(). |
| 212 want_user_interface = getuid() != 0; | 212 if (getuid() == 0) { |
| 213 want_user_interface = false; |
| 214 } |
| 213 #endif // OS_MACOSX | 215 #endif // OS_MACOSX |
| 214 | 216 |
| 215 if (want_user_interface) { | 217 if (want_user_interface) { |
| 216 host_user_interface_.reset(new HostUserInterface(context_.get())); | 218 host_user_interface_.reset(new HostUserInterface(context_.get())); |
| 217 } | 219 } |
| 220 #endif // OS_MACOSX || OS_WIN |
| 218 | 221 |
| 219 StartWatchingPolicy(); | 222 StartWatchingPolicy(); |
| 220 } else { | 223 } else { |
| 221 // PostTask to create new authenticator factory in case PIN has changed. | 224 // PostTask to create new authenticator factory in case PIN has changed. |
| 222 context_->network_task_runner()->PostTask( | 225 context_->network_task_runner()->PostTask( |
| 223 FROM_HERE, | 226 FROM_HERE, |
| 224 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 227 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
| 225 base::Unretained(this))); | 228 base::Unretained(this))); |
| 226 } | 229 } |
| 227 } | 230 } |
| 228 | 231 |
| 229 virtual void OnConfigWatcherError() OVERRIDE { | 232 virtual void OnConfigWatcherError() OVERRIDE { |
| 230 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 233 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 231 | 234 |
| 232 context_->network_task_runner()->PostTask( | 235 context_->network_task_runner()->PostTask( |
| 233 FROM_HERE, | 236 FROM_HERE, |
| 234 base::Bind(&HostProcess::Shutdown, base::Unretained(this), | 237 base::Bind(&HostProcess::Shutdown, base::Unretained(this), |
| 235 kInvalidHostConfigurationExitCode)); | 238 kInvalidHostConfigurationExitCode)); |
| 236 } | 239 } |
| 237 | 240 |
| 238 void StartWatchingConfigChanges() { | 241 void StartWatchingConfigChanges() { |
| 239 #if !defined(REMOTING_MULTI_PROCESS) | 242 #if !defined(REMOTING_MULTI_PROCESS) |
| 243 |
| 240 // Start watching the host configuration file. | 244 // Start watching the host configuration file. |
| 241 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), | 245 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), |
| 242 context_->file_task_runner(), | 246 context_->file_task_runner(), |
| 243 this)); | 247 this)); |
| 244 config_watcher_->Watch(host_config_path_); | 248 config_watcher_->Watch(host_config_path_); |
| 245 #endif // !defined(REMOTING_MULTI_PROCESS) | 249 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 246 } | 250 } |
| 247 | 251 |
| 252 #if defined(OS_POSIX) |
| 248 void ListenForShutdownSignal() { | 253 void ListenForShutdownSignal() { |
| 249 #if defined(OS_POSIX) | |
| 250 remoting::RegisterSignalHandler( | 254 remoting::RegisterSignalHandler( |
| 251 SIGTERM, | 255 SIGTERM, |
| 252 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); | 256 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); |
| 257 } |
| 253 #endif // OS_POSIX | 258 #endif // OS_POSIX |
| 254 } | |
| 255 | 259 |
| 256 void CreateAuthenticatorFactory() { | 260 void CreateAuthenticatorFactory() { |
| 257 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 261 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 258 | 262 |
| 259 std::string local_certificate = key_pair_.GenerateCertificate(); | 263 std::string local_certificate = key_pair_.GenerateCertificate(); |
| 260 if (local_certificate.empty()) { | 264 if (local_certificate.empty()) { |
| 261 LOG(ERROR) << "Failed to generate host certificate."; | 265 LOG(ERROR) << "Failed to generate host certificate."; |
| 262 Shutdown(kHostInitializationFailed); | 266 Shutdown(kHostInitializationFailed); |
| 263 return; | 267 return; |
| 264 } | 268 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 287 } | 291 } |
| 288 | 292 |
| 289 void StartHostProcess() { | 293 void StartHostProcess() { |
| 290 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 294 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 291 | 295 |
| 292 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 296 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 293 OnConfigWatcherError(); | 297 OnConfigWatcherError(); |
| 294 return; | 298 return; |
| 295 } | 299 } |
| 296 | 300 |
| 301 #if defined(OS_POSIX) |
| 297 context_->network_task_runner()->PostTask( | 302 context_->network_task_runner()->PostTask( |
| 298 FROM_HERE, | 303 FROM_HERE, |
| 299 base::Bind(&HostProcess::ListenForShutdownSignal, | 304 base::Bind(&HostProcess::ListenForShutdownSignal, |
| 300 base::Unretained(this))); | 305 base::Unretained(this))); |
| 306 #endif // OS_POSIX |
| 301 | 307 |
| 302 StartWatchingConfigChanges(); | 308 StartWatchingConfigChanges(); |
| 303 } | 309 } |
| 304 | 310 |
| 305 int get_exit_code() const { return exit_code_; } | 311 int get_exit_code() const { return exit_code_; } |
| 306 | 312 |
| 307 private: | 313 private: |
| 308 void ShutdownHostProcess() { | 314 void ShutdownHostProcess() { |
| 309 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 315 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 310 | 316 |
| 317 #if !defined(REMOTING_MULTI_PROCESS) |
| 311 config_watcher_.reset(); | 318 config_watcher_.reset(); |
| 319 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 312 | 320 |
| 313 daemon_channel_.reset(); | 321 daemon_channel_.reset(); |
| 322 |
| 323 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 314 host_user_interface_.reset(); | 324 host_user_interface_.reset(); |
| 325 #endif |
| 315 | 326 |
| 316 if (policy_watcher_.get()) { | 327 if (policy_watcher_.get()) { |
| 317 base::WaitableEvent done_event(true, false); | 328 base::WaitableEvent done_event(true, false); |
| 318 policy_watcher_->StopWatching(&done_event); | 329 policy_watcher_->StopWatching(&done_event); |
| 319 done_event.Wait(); | 330 done_event.Wait(); |
| 320 policy_watcher_.reset(); | 331 policy_watcher_.reset(); |
| 321 } | 332 } |
| 322 | 333 |
| 323 context_.reset(); | 334 context_.reset(); |
| 324 } | 335 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 574 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
| 564 #endif | 575 #endif |
| 565 | 576 |
| 566 heartbeat_sender_.reset(new HeartbeatSender( | 577 heartbeat_sender_.reset(new HeartbeatSender( |
| 567 this, host_id_, signal_strategy_.get(), &key_pair_)); | 578 this, host_id_, signal_strategy_.get(), &key_pair_)); |
| 568 | 579 |
| 569 log_to_server_.reset( | 580 log_to_server_.reset( |
| 570 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 581 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); |
| 571 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); | 582 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); |
| 572 | 583 |
| 584 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 573 if (host_user_interface_.get()) { | 585 if (host_user_interface_.get()) { |
| 574 host_user_interface_->Start( | 586 host_user_interface_->Start( |
| 575 host_, base::Bind(&HostProcess::OnDisconnectRequested, | 587 host_, base::Bind(&HostProcess::OnDisconnectRequested, |
| 576 base::Unretained(this))); | 588 base::Unretained(this))); |
| 577 } | 589 } |
| 590 #endif |
| 578 | 591 |
| 579 host_->Start(xmpp_login_); | 592 host_->Start(xmpp_login_); |
| 580 | 593 |
| 581 CreateAuthenticatorFactory(); | 594 CreateAuthenticatorFactory(); |
| 582 } | 595 } |
| 583 | 596 |
| 584 void OnAuthFailed() { | 597 void OnAuthFailed() { |
| 585 Shutdown(kInvalidOauthCredentialsExitCode); | 598 Shutdown(kInvalidOauthCredentialsExitCode); |
| 586 } | 599 } |
| 587 | 600 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 heartbeat_sender_.reset(); | 668 heartbeat_sender_.reset(); |
| 656 signaling_connector_.reset(); | 669 signaling_connector_.reset(); |
| 657 signal_strategy_.reset(); | 670 signal_strategy_.reset(); |
| 658 } | 671 } |
| 659 | 672 |
| 660 scoped_ptr<ChromotingHostContext> context_; | 673 scoped_ptr<ChromotingHostContext> context_; |
| 661 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 674 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 662 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 675 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 663 | 676 |
| 664 JsonHostConfig config_; | 677 JsonHostConfig config_; |
| 678 #if !defined(REMOTING_MULTI_PROCESS) |
| 665 FilePath host_config_path_; | 679 FilePath host_config_path_; |
| 666 scoped_ptr<ConfigFileWatcher> config_watcher_; | 680 scoped_ptr<ConfigFileWatcher> config_watcher_; |
| 681 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 667 | 682 |
| 668 std::string host_id_; | 683 std::string host_id_; |
| 669 HostKeyPair key_pair_; | 684 HostKeyPair key_pair_; |
| 670 protocol::SharedSecretHash host_secret_hash_; | 685 protocol::SharedSecretHash host_secret_hash_; |
| 671 std::string xmpp_login_; | 686 std::string xmpp_login_; |
| 672 std::string xmpp_auth_token_; | 687 std::string xmpp_auth_token_; |
| 673 std::string xmpp_auth_service_; | 688 std::string xmpp_auth_service_; |
| 674 | 689 |
| 675 std::string oauth_refresh_token_; | 690 std::string oauth_refresh_token_; |
| 676 bool oauth_use_official_client_id_; | 691 bool oauth_use_official_client_id_; |
| 677 | 692 |
| 678 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 693 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 679 bool allow_nat_traversal_; | 694 bool allow_nat_traversal_; |
| 680 std::string talkgadget_prefix_; | 695 std::string talkgadget_prefix_; |
| 681 | 696 |
| 682 bool restarting_; | 697 bool restarting_; |
| 683 bool shutting_down_; | 698 bool shutting_down_; |
| 684 | 699 |
| 685 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 700 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
| 686 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 701 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 687 scoped_ptr<SignalingConnector> signaling_connector_; | 702 scoped_ptr<SignalingConnector> signaling_connector_; |
| 688 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 703 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 689 scoped_ptr<LogToServer> log_to_server_; | 704 scoped_ptr<LogToServer> log_to_server_; |
| 690 scoped_ptr<HostEventLogger> host_event_logger_; | 705 scoped_ptr<HostEventLogger> host_event_logger_; |
| 691 | 706 |
| 707 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 692 scoped_ptr<HostUserInterface> host_user_interface_; | 708 scoped_ptr<HostUserInterface> host_user_interface_; |
| 709 #endif |
| 693 | 710 |
| 694 scoped_refptr<ChromotingHost> host_; | 711 scoped_refptr<ChromotingHost> host_; |
| 695 | 712 |
| 696 int exit_code_; | 713 int exit_code_; |
| 697 | 714 |
| 698 #if defined(OS_MACOSX) | 715 #if defined(OS_MACOSX) |
| 699 remoting::CurtainMode curtain_; | 716 remoting::CurtainMode curtain_; |
| 700 #endif // defined(OS_MACOSX) | 717 #endif // defined(OS_MACOSX) |
| 701 }; | 718 }; |
| 702 | 719 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 user32.GetFunctionPointer("SetProcessDPIAware")); | 822 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 806 set_process_dpi_aware(); | 823 set_process_dpi_aware(); |
| 807 } | 824 } |
| 808 | 825 |
| 809 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 826 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 810 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 827 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 811 return main(0, NULL); | 828 return main(0, NULL); |
| 812 } | 829 } |
| 813 | 830 |
| 814 #endif // defined(OS_WIN) | 831 #endif // defined(OS_WIN) |
| OLD | NEW |