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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 // Crashes the process in response to a daemon's request. The daemon passes | 379 // Crashes the process in response to a daemon's request. The daemon passes |
380 // the location of the code that detected the fatal error resulted in this | 380 // the location of the code that detected the fatal error resulted in this |
381 // request. | 381 // request. |
382 void OnCrash(const std::string& function_name, | 382 void OnCrash(const std::string& function_name, |
383 const std::string& file_name, | 383 const std::string& file_name, |
384 const int& line_number); | 384 const int& line_number); |
385 | 385 |
386 scoped_ptr<ChromotingHostContext> context_; | 386 scoped_ptr<ChromotingHostContext> context_; |
387 | 387 |
388 scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_; | |
389 | |
390 // Accessed on the UI thread. | |
391 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | |
392 | |
393 // XMPP server/remoting bot configuration (initialized from the command line). | 388 // XMPP server/remoting bot configuration (initialized from the command line). |
394 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 389 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
395 std::string directory_bot_jid_; | 390 std::string directory_bot_jid_; |
396 | 391 |
397 // Created on the UI thread but used from the network thread. | 392 // Created on the UI thread but used from the network thread. |
398 base::FilePath host_config_path_; | 393 base::FilePath host_config_path_; |
399 std::string host_config_; | 394 std::string host_config_; |
400 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 395 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
401 | 396 |
402 // Accessed on the network thread. | 397 // Accessed on the network thread. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 448 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
454 scoped_ptr<HostStatusLogger> host_status_logger_; | 449 scoped_ptr<HostStatusLogger> host_status_logger_; |
455 scoped_ptr<HostEventLogger> host_event_logger_; | 450 scoped_ptr<HostEventLogger> host_event_logger_; |
456 | 451 |
457 scoped_ptr<ChromotingHost> host_; | 452 scoped_ptr<ChromotingHost> host_; |
458 | 453 |
459 // Used to keep this HostProcess alive until it is shutdown. | 454 // Used to keep this HostProcess alive until it is shutdown. |
460 scoped_refptr<HostProcess> self_; | 455 scoped_refptr<HostProcess> self_; |
461 | 456 |
462 #if defined(REMOTING_MULTI_PROCESS) | 457 #if defined(REMOTING_MULTI_PROCESS) |
463 DesktopSessionConnector* desktop_session_connector_; | 458 // Accessed on the UI thread. |
| 459 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 460 |
| 461 // AttachmentBroker for |daemon_channel_|. |
| 462 scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_; |
| 463 |
| 464 // Owned as |desktop_environment_factory_|. |
| 465 DesktopSessionConnector* desktop_session_connector_ = nullptr; |
464 #endif // defined(REMOTING_MULTI_PROCESS) | 466 #endif // defined(REMOTING_MULTI_PROCESS) |
465 | 467 |
466 int* exit_code_out_; | 468 int* exit_code_out_; |
467 bool signal_parent_; | 469 bool signal_parent_; |
468 | 470 |
469 scoped_refptr<PairingRegistry> pairing_registry_; | 471 scoped_refptr<PairingRegistry> pairing_registry_; |
470 | 472 |
471 ShutdownWatchdog* shutdown_watchdog_; | 473 ShutdownWatchdog* shutdown_watchdog_; |
472 | 474 |
473 DISALLOW_COPY_AND_ASSIGN(HostProcess); | 475 DISALLOW_COPY_AND_ASSIGN(HostProcess); |
474 }; | 476 }; |
475 | 477 |
476 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 478 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
477 int* exit_code_out, | 479 int* exit_code_out, |
478 ShutdownWatchdog* shutdown_watchdog) | 480 ShutdownWatchdog* shutdown_watchdog) |
479 : context_(std::move(context)), | 481 : context_(std::move(context)), |
480 attachment_broker_(IPC::AttachmentBrokerUnprivileged::CreateBroker()), | |
481 state_(HOST_STARTING), | 482 state_(HOST_STARTING), |
482 use_service_account_(false), | 483 use_service_account_(false), |
483 enable_vp9_(false), | 484 enable_vp9_(false), |
484 frame_recorder_buffer_size_(0), | 485 frame_recorder_buffer_size_(0), |
485 policy_state_(POLICY_INITIALIZING), | 486 policy_state_(POLICY_INITIALIZING), |
486 host_username_match_required_(false), | 487 host_username_match_required_(false), |
487 allow_nat_traversal_(true), | 488 allow_nat_traversal_(true), |
488 allow_relay_(true), | 489 allow_relay_(true), |
489 allow_pairing_(true), | 490 allow_pairing_(true), |
490 curtain_required_(false), | 491 curtain_required_(false), |
491 enable_gnubby_auth_(false), | 492 enable_gnubby_auth_(false), |
492 enable_window_capture_(false), | 493 enable_window_capture_(false), |
493 window_id_(0), | 494 window_id_(0), |
494 self_(this), | 495 self_(this), |
495 #if defined(REMOTING_MULTI_PROCESS) | |
496 desktop_session_connector_(nullptr), | |
497 #endif // defined(REMOTING_MULTI_PROCESS) | |
498 exit_code_out_(exit_code_out), | 496 exit_code_out_(exit_code_out), |
499 signal_parent_(false), | 497 signal_parent_(false), |
500 shutdown_watchdog_(shutdown_watchdog) { | 498 shutdown_watchdog_(shutdown_watchdog) { |
501 StartOnUiThread(); | 499 StartOnUiThread(); |
502 } | 500 } |
503 | 501 |
504 HostProcess::~HostProcess() { | 502 HostProcess::~HostProcess() { |
505 // Verify that UI components have been torn down. | 503 // Verify that UI components have been torn down. |
506 DCHECK(!config_watcher_); | 504 DCHECK(!config_watcher_); |
507 DCHECK(!daemon_channel_); | |
508 DCHECK(!desktop_environment_factory_); | 505 DCHECK(!desktop_environment_factory_); |
509 | 506 |
510 // We might be getting deleted on one of the threads the |host_context| owns, | 507 // We might be getting deleted on one of the threads the |host_context| owns, |
511 // so we need to post it back to the caller thread to safely join & delete the | 508 // so we need to post it back to the caller thread to safely join & delete the |
512 // threads it contains. This will go away when we move to AutoThread. | 509 // threads it contains. This will go away when we move to AutoThread. |
513 // |context_release()| will null |context_| before the method is invoked, so | 510 // |context_release()| will null |context_| before the method is invoked, so |
514 // we need to pull out the task-runner on which to call DeleteSoon first. | 511 // we need to pull out the task-runner on which to call DeleteSoon first. |
515 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 512 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
516 context_->ui_task_runner(); | 513 context_->ui_task_runner(); |
517 task_runner->DeleteSoon(FROM_HERE, context_.release()); | 514 task_runner->DeleteSoon(FROM_HERE, context_.release()); |
(...skipping 19 matching lines...) Expand all Loading... |
537 #elif defined(OS_POSIX) | 534 #elif defined(OS_POSIX) |
538 base::FileDescriptor pipe(pipe_handle, true); | 535 base::FileDescriptor pipe(pipe_handle, true); |
539 IPC::ChannelHandle channel_handle(channel_name, pipe); | 536 IPC::ChannelHandle channel_handle(channel_name, pipe); |
540 #endif // defined(OS_POSIX) | 537 #endif // defined(OS_POSIX) |
541 | 538 |
542 // Connect to the daemon process. | 539 // Connect to the daemon process. |
543 daemon_channel_ = IPC::ChannelProxy::Create(channel_handle, | 540 daemon_channel_ = IPC::ChannelProxy::Create(channel_handle, |
544 IPC::Channel::MODE_CLIENT, | 541 IPC::Channel::MODE_CLIENT, |
545 this, | 542 this, |
546 context_->network_task_runner()); | 543 context_->network_task_runner()); |
| 544 |
| 545 attachment_broker_ = IPC::AttachmentBrokerUnprivileged::CreateBroker(); |
547 if (attachment_broker_) { | 546 if (attachment_broker_) { |
548 attachment_broker_->DesignateBrokerCommunicationChannel( | 547 attachment_broker_->DesignateBrokerCommunicationChannel( |
549 daemon_channel_.get()); | 548 daemon_channel_.get()); |
550 } | 549 } |
551 | 550 |
552 #else // !defined(REMOTING_MULTI_PROCESS) | 551 #else // !defined(REMOTING_MULTI_PROCESS) |
553 // Connect to the daemon process. | |
554 std::string channel_name = | |
555 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); | |
556 if (!channel_name.empty()) { | |
557 daemon_channel_ = | |
558 IPC::ChannelProxy::Create(channel_name, IPC::Channel::MODE_CLIENT, this, | |
559 context_->network_task_runner().get()); | |
560 if (attachment_broker_) { | |
561 attachment_broker_->DesignateBrokerCommunicationChannel( | |
562 daemon_channel_.get()); | |
563 } | |
564 } | |
565 | |
566 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 552 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
567 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 553 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
568 | 554 |
569 // Read config from stdin if necessary. | 555 // Read config from stdin if necessary. |
570 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { | 556 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { |
571 const size_t kBufferSize = 4096; | 557 const size_t kBufferSize = 4096; |
572 scoped_ptr<char[]> buf(new char[kBufferSize]); | 558 scoped_ptr<char[]> buf(new char[kBufferSize]); |
573 size_t len; | 559 size_t len; |
574 while ((len = fread(buf.get(), 1, kBufferSize, stdin)) > 0) { | 560 while ((len = fread(buf.get(), 1, kBufferSize, stdin)) > 0) { |
575 host_config_.append(buf.get(), len); | 561 host_config_.append(buf.get(), len); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 } | 884 } |
899 | 885 |
900 base::FilePath gnubby_socket_name = base::CommandLine::ForCurrentProcess()-> | 886 base::FilePath gnubby_socket_name = base::CommandLine::ForCurrentProcess()-> |
901 GetSwitchValuePath(kAuthSocknameSwitchName); | 887 GetSwitchValuePath(kAuthSocknameSwitchName); |
902 if (!gnubby_socket_name.empty()) | 888 if (!gnubby_socket_name.empty()) |
903 remoting::GnubbyAuthHandler::SetGnubbySocketName(gnubby_socket_name); | 889 remoting::GnubbyAuthHandler::SetGnubbySocketName(gnubby_socket_name); |
904 #endif // defined(OS_LINUX) | 890 #endif // defined(OS_LINUX) |
905 | 891 |
906 // Create a desktop environment factory appropriate to the build type & | 892 // Create a desktop environment factory appropriate to the build type & |
907 // platform. | 893 // platform. |
908 #if defined(OS_WIN) | 894 #if defined(REMOTING_MULTI_PROCESS) |
909 IpcDesktopEnvironmentFactory* desktop_environment_factory = | 895 IpcDesktopEnvironmentFactory* desktop_environment_factory = |
910 new IpcDesktopEnvironmentFactory( | 896 new IpcDesktopEnvironmentFactory( |
911 context_->audio_task_runner(), | 897 context_->audio_task_runner(), |
912 context_->network_task_runner(), | 898 context_->network_task_runner(), |
913 context_->video_capture_task_runner(), | 899 context_->video_capture_task_runner(), |
914 context_->network_task_runner(), | 900 context_->network_task_runner(), |
915 daemon_channel_.get()); | 901 daemon_channel_.get()); |
916 desktop_session_connector_ = desktop_environment_factory; | 902 desktop_session_connector_ = desktop_environment_factory; |
917 #else // !defined(OS_WIN) | 903 #else // !defined(REMOTING_MULTI_PROCESS) |
918 BasicDesktopEnvironmentFactory* desktop_environment_factory; | 904 BasicDesktopEnvironmentFactory* desktop_environment_factory; |
919 if (enable_window_capture_) { | 905 if (enable_window_capture_) { |
920 desktop_environment_factory = | 906 desktop_environment_factory = |
921 new SingleWindowDesktopEnvironmentFactory( | 907 new SingleWindowDesktopEnvironmentFactory( |
922 context_->network_task_runner(), | 908 context_->network_task_runner(), |
923 context_->input_task_runner(), | 909 context_->input_task_runner(), |
924 context_->ui_task_runner(), | 910 context_->ui_task_runner(), |
925 window_id_); | 911 window_id_); |
926 } else { | 912 } else { |
927 desktop_environment_factory = | 913 desktop_environment_factory = |
928 new Me2MeDesktopEnvironmentFactory( | 914 new Me2MeDesktopEnvironmentFactory( |
929 context_->network_task_runner(), | 915 context_->network_task_runner(), |
930 context_->input_task_runner(), | 916 context_->input_task_runner(), |
931 context_->ui_task_runner()); | 917 context_->ui_task_runner()); |
932 } | 918 } |
933 #endif // !defined(OS_WIN) | 919 #endif // !defined(REMOTING_MULTI_PROCESS) |
934 desktop_environment_factory->set_supports_touch_events( | 920 desktop_environment_factory->set_supports_touch_events( |
935 InputInjector::SupportsTouchEvents()); | 921 InputInjector::SupportsTouchEvents()); |
936 | 922 |
937 desktop_environment_factory_.reset(desktop_environment_factory); | 923 desktop_environment_factory_.reset(desktop_environment_factory); |
938 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); | 924 desktop_environment_factory_->SetEnableGnubbyAuth(enable_gnubby_auth_); |
939 | 925 |
940 context_->network_task_runner()->PostTask( | 926 context_->network_task_runner()->PostTask( |
941 FROM_HERE, | 927 FROM_HERE, |
942 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 928 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
943 } | 929 } |
944 | 930 |
945 void HostProcess::ShutdownOnUiThread() { | 931 void HostProcess::ShutdownOnUiThread() { |
946 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 932 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
947 | 933 |
948 // Tear down resources that need to be torn down on the UI thread. | 934 // Tear down resources that need to be torn down on the UI thread. |
949 daemon_channel_.reset(); | |
950 desktop_environment_factory_.reset(); | 935 desktop_environment_factory_.reset(); |
951 policy_watcher_.reset(); | 936 policy_watcher_.reset(); |
952 | 937 |
| 938 #if defined(REMOTING_MULTI_PROCESS) |
| 939 attachment_broker_.reset(); |
| 940 daemon_channel_.reset(); |
| 941 #endif // defined(REMOTING_MULTI_PROCESS) |
| 942 |
953 // It is now safe for the HostProcess to be deleted. | 943 // It is now safe for the HostProcess to be deleted. |
954 self_ = nullptr; | 944 self_ = nullptr; |
955 | 945 |
956 #if defined(OS_LINUX) | 946 #if defined(OS_LINUX) |
957 // Cause the global AudioPipeReader to be freed, otherwise the audio | 947 // Cause the global AudioPipeReader to be freed, otherwise the audio |
958 // thread will remain in-use and prevent the process from exiting. | 948 // thread will remain in-use and prevent the process from exiting. |
959 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 949 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
960 // See crbug.com/161373 and crbug.com/104544. | 950 // See crbug.com/161373 and crbug.com/104544. |
961 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); | 951 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); |
962 #endif | 952 #endif |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1739 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
1750 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); | 1740 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); |
1751 | 1741 |
1752 // Run the main (also UI) message loop until the host no longer needs it. | 1742 // Run the main (also UI) message loop until the host no longer needs it. |
1753 message_loop.Run(); | 1743 message_loop.Run(); |
1754 | 1744 |
1755 return exit_code; | 1745 return exit_code; |
1756 } | 1746 } |
1757 | 1747 |
1758 } // namespace remoting | 1748 } // namespace remoting |
OLD | NEW |