| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // Allowed state transitions: | 198 // Allowed state transitions: |
| 199 // INITIALIZING->STARTED | 199 // INITIALIZING->STARTED |
| 200 // INITIALIZING->STOPPED | 200 // INITIALIZING->STOPPED |
| 201 // STARTED->STOPPING_TO_RESTART | 201 // STARTED->STOPPING_TO_RESTART |
| 202 // STARTED->STOPPING | 202 // STARTED->STOPPING |
| 203 // STOPPING_TO_RESTART->STARTED | 203 // STOPPING_TO_RESTART->STARTED |
| 204 // STOPPING_TO_RESTART->STOPPING | 204 // STOPPING_TO_RESTART->STOPPING |
| 205 // STOPPING->STOPPED | 205 // STOPPING->STOPPED |
| 206 // STOPPED->STARTED | 206 // STOPPED->STARTED |
| 207 // | 207 // |
| 208 // |host_| must be NULL in INITIALIZING and STOPPED states and not-NULL in | 208 // |host_| must be nullptr in INITIALIZING and STOPPED states and not |
| 209 // all other states. | 209 // nullptr in all other states. |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 friend class base::RefCountedThreadSafe<HostProcess>; | 212 friend class base::RefCountedThreadSafe<HostProcess>; |
| 213 ~HostProcess() override; | 213 ~HostProcess() override; |
| 214 | 214 |
| 215 void StartOnNetworkThread(); | 215 void StartOnNetworkThread(); |
| 216 | 216 |
| 217 #if defined(OS_POSIX) | 217 #if defined(OS_POSIX) |
| 218 // Callback passed to RegisterSignalHandler() to handle SIGTERM events. | 218 // Callback passed to RegisterSignalHandler() to handle SIGTERM events. |
| 219 void SigTermHandler(int signal_number); | 219 void SigTermHandler(int signal_number); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 allow_nat_traversal_(true), | 378 allow_nat_traversal_(true), |
| 379 allow_relay_(true), | 379 allow_relay_(true), |
| 380 min_udp_port_(0), | 380 min_udp_port_(0), |
| 381 max_udp_port_(0), | 381 max_udp_port_(0), |
| 382 allow_pairing_(true), | 382 allow_pairing_(true), |
| 383 curtain_required_(false), | 383 curtain_required_(false), |
| 384 enable_gnubby_auth_(false), | 384 enable_gnubby_auth_(false), |
| 385 enable_window_capture_(false), | 385 enable_window_capture_(false), |
| 386 window_id_(0), | 386 window_id_(0), |
| 387 #if defined(REMOTING_MULTI_PROCESS) | 387 #if defined(REMOTING_MULTI_PROCESS) |
| 388 desktop_session_connector_(NULL), | 388 desktop_session_connector_(nullptr), |
| 389 #endif // defined(REMOTING_MULTI_PROCESS) | 389 #endif // defined(REMOTING_MULTI_PROCESS) |
| 390 self_(this), | 390 self_(this), |
| 391 exit_code_out_(exit_code_out), | 391 exit_code_out_(exit_code_out), |
| 392 signal_parent_(false), | 392 signal_parent_(false), |
| 393 shutdown_watchdog_(shutdown_watchdog) { | 393 shutdown_watchdog_(shutdown_watchdog) { |
| 394 StartOnUiThread(); | 394 StartOnUiThread(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 HostProcess::~HostProcess() { | 397 HostProcess::~HostProcess() { |
| 398 // Verify that UI components have been torn down. | 398 // Verify that UI components have been torn down. |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 775 |
| 776 void HostProcess::ShutdownOnUiThread() { | 776 void HostProcess::ShutdownOnUiThread() { |
| 777 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 777 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 778 | 778 |
| 779 // Tear down resources that need to be torn down on the UI thread. | 779 // Tear down resources that need to be torn down on the UI thread. |
| 780 network_change_notifier_.reset(); | 780 network_change_notifier_.reset(); |
| 781 daemon_channel_.reset(); | 781 daemon_channel_.reset(); |
| 782 desktop_environment_factory_.reset(); | 782 desktop_environment_factory_.reset(); |
| 783 | 783 |
| 784 // It is now safe for the HostProcess to be deleted. | 784 // It is now safe for the HostProcess to be deleted. |
| 785 self_ = NULL; | 785 self_ = nullptr; |
| 786 | 786 |
| 787 #if defined(OS_LINUX) | 787 #if defined(OS_LINUX) |
| 788 // Cause the global AudioPipeReader to be freed, otherwise the audio | 788 // Cause the global AudioPipeReader to be freed, otherwise the audio |
| 789 // thread will remain in-use and prevent the process from exiting. | 789 // thread will remain in-use and prevent the process from exiting. |
| 790 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 790 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
| 791 // See crbug.com/161373 and crbug.com/104544. | 791 // See crbug.com/161373 and crbug.com/104544. |
| 792 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); | 792 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); |
| 793 #endif | 793 #endif |
| 794 } | 794 } |
| 795 | 795 |
| 796 // Overridden from HeartbeatSender::Listener | 796 // Overridden from HeartbeatSender::Listener |
| 797 void HostProcess::OnUnknownHostIdError() { | 797 void HostProcess::OnUnknownHostIdError() { |
| 798 LOG(ERROR) << "Host ID not found."; | 798 LOG(ERROR) << "Host ID not found."; |
| 799 ShutdownHost(kInvalidHostIdExitCode); | 799 ShutdownHost(kInvalidHostIdExitCode); |
| 800 } | 800 } |
| 801 | 801 |
| 802 void HostProcess::OnHeartbeatSuccessful() { | 802 void HostProcess::OnHeartbeatSuccessful() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 826 #else // !defined(OS_WIN) | 826 #else // !defined(OS_WIN) |
| 827 NOTREACHED(); | 827 NOTREACHED(); |
| 828 #endif // !defined(OS_WIN) | 828 #endif // !defined(OS_WIN) |
| 829 } | 829 } |
| 830 | 830 |
| 831 #if defined(OS_WIN) | 831 #if defined(OS_WIN) |
| 832 void HostProcess::InitializePairingRegistry( | 832 void HostProcess::InitializePairingRegistry( |
| 833 IPC::PlatformFileForTransit privileged_key, | 833 IPC::PlatformFileForTransit privileged_key, |
| 834 IPC::PlatformFileForTransit unprivileged_key) { | 834 IPC::PlatformFileForTransit unprivileged_key) { |
| 835 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 835 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 836 // |privileged_key| can be NULL but not |unprivileged_key|. | 836 // |privileged_key| can be nullptr but not |unprivileged_key|. |
| 837 DCHECK(unprivileged_key); | 837 DCHECK(unprivileged_key); |
| 838 // |pairing_registry_| should only be initialized once. | 838 // |pairing_registry_| should only be initialized once. |
| 839 DCHECK(!pairing_registry_); | 839 DCHECK(!pairing_registry_); |
| 840 | 840 |
| 841 HKEY privileged_hkey = reinterpret_cast<HKEY>( | 841 HKEY privileged_hkey = reinterpret_cast<HKEY>( |
| 842 IPC::PlatformFileForTransitToPlatformFile(privileged_key)); | 842 IPC::PlatformFileForTransitToPlatformFile(privileged_key)); |
| 843 HKEY unprivileged_hkey = reinterpret_cast<HKEY>( | 843 HKEY unprivileged_hkey = reinterpret_cast<HKEY>( |
| 844 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); | 844 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); |
| 845 | 845 |
| 846 scoped_ptr<PairingRegistryDelegateWin> delegate( | 846 scoped_ptr<PairingRegistryDelegateWin> delegate( |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 int HostProcessMain() { | 1505 int HostProcessMain() { |
| 1506 #if defined(OS_LINUX) | 1506 #if defined(OS_LINUX) |
| 1507 // Required in order for us to run multiple X11 threads. | 1507 // Required in order for us to run multiple X11 threads. |
| 1508 XInitThreads(); | 1508 XInitThreads(); |
| 1509 | 1509 |
| 1510 // Required for any calls into GTK functions, such as the Disconnect and | 1510 // Required for any calls into GTK functions, such as the Disconnect and |
| 1511 // Continue windows, though these should not be used for the Me2Me case | 1511 // Continue windows, though these should not be used for the Me2Me case |
| 1512 // (crbug.com/104377). | 1512 // (crbug.com/104377). |
| 1513 gtk_init(NULL, NULL); | 1513 gtk_init(nullptr, nullptr); |
| 1514 #endif | 1514 #endif |
| 1515 | 1515 |
| 1516 // Enable support for SSL server sockets, which must be done while still | 1516 // Enable support for SSL server sockets, which must be done while still |
| 1517 // single-threaded. | 1517 // single-threaded. |
| 1518 net::EnableSSLServerSockets(); | 1518 net::EnableSSLServerSockets(); |
| 1519 | 1519 |
| 1520 // Ensures runtime specific CPU features are initialized. | 1520 // Ensures runtime specific CPU features are initialized. |
| 1521 media::InitializeCPUSpecificMediaFeatures(); | 1521 media::InitializeCPUSpecificMediaFeatures(); |
| 1522 | 1522 |
| 1523 // Create the main message loop and start helper threads. | 1523 // Create the main message loop and start helper threads. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1536 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1536 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
| 1537 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1537 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); |
| 1538 | 1538 |
| 1539 // Run the main (also UI) message loop until the host no longer needs it. | 1539 // Run the main (also UI) message loop until the host no longer needs it. |
| 1540 message_loop.Run(); | 1540 message_loop.Run(); |
| 1541 | 1541 |
| 1542 return exit_code; | 1542 return exit_code; |
| 1543 } | 1543 } |
| 1544 | 1544 |
| 1545 } // namespace remoting | 1545 } // namespace remoting |
| OLD | NEW |