| 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 | 8 |
| 9 #include <cstdint> | 9 #include <cstdint> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringize_macros.h" | 27 #include "base/strings/stringize_macros.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "components/policy/policy_constants.h" | 30 #include "components/policy/policy_constants.h" |
| 31 #include "ipc/attachment_broker_unprivileged.h" | 31 #include "ipc/attachment_broker_unprivileged.h" |
| 32 #include "ipc/ipc_channel.h" | 32 #include "ipc/ipc_channel.h" |
| 33 #include "ipc/ipc_channel_proxy.h" | 33 #include "ipc/ipc_channel_proxy.h" |
| 34 #include "ipc/ipc_listener.h" | 34 #include "ipc/ipc_listener.h" |
| 35 #include "jingle/glue/thread_wrapper.h" | 35 #include "jingle/glue/thread_wrapper.h" |
| 36 #include "mojo/edk/embedder/embedder.h" | |
| 37 #include "mojo/edk/embedder/platform_channel_pair.h" | |
| 38 #include "mojo/edk/embedder/scoped_ipc_support.h" | |
| 39 #include "net/base/network_change_notifier.h" | 36 #include "net/base/network_change_notifier.h" |
| 40 #include "net/base/url_util.h" | 37 #include "net/base/url_util.h" |
| 41 #include "net/socket/client_socket_factory.h" | 38 #include "net/socket/client_socket_factory.h" |
| 42 #include "net/url_request/url_fetcher.h" | 39 #include "net/url_request/url_fetcher.h" |
| 43 #include "remoting/base/auto_thread_task_runner.h" | 40 #include "remoting/base/auto_thread_task_runner.h" |
| 44 #include "remoting/base/breakpad.h" | 41 #include "remoting/base/breakpad.h" |
| 45 #include "remoting/base/chromium_url_request.h" | 42 #include "remoting/base/chromium_url_request.h" |
| 46 #include "remoting/base/constants.h" | 43 #include "remoting/base/constants.h" |
| 47 #include "remoting/base/logging.h" | 44 #include "remoting/base/logging.h" |
| 48 #include "remoting/base/rsa_key_pair.h" | 45 #include "remoting/base/rsa_key_pair.h" |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 std::unique_ptr<HostStatusLogger> host_status_logger_; | 403 std::unique_ptr<HostStatusLogger> host_status_logger_; |
| 407 std::unique_ptr<HostEventLogger> host_event_logger_; | 404 std::unique_ptr<HostEventLogger> host_event_logger_; |
| 408 std::unique_ptr<HostPowerSaveBlocker> power_save_blocker_; | 405 std::unique_ptr<HostPowerSaveBlocker> power_save_blocker_; |
| 409 | 406 |
| 410 std::unique_ptr<ChromotingHost> host_; | 407 std::unique_ptr<ChromotingHost> host_; |
| 411 | 408 |
| 412 // Used to keep this HostProcess alive until it is shutdown. | 409 // Used to keep this HostProcess alive until it is shutdown. |
| 413 scoped_refptr<HostProcess> self_; | 410 scoped_refptr<HostProcess> self_; |
| 414 | 411 |
| 415 #if defined(REMOTING_MULTI_PROCESS) | 412 #if defined(REMOTING_MULTI_PROCESS) |
| 416 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; | |
| 417 | |
| 418 // Accessed on the UI thread. | 413 // Accessed on the UI thread. |
| 419 std::unique_ptr<IPC::ChannelProxy> daemon_channel_; | 414 std::unique_ptr<IPC::ChannelProxy> daemon_channel_; |
| 420 | 415 |
| 421 // Owned as |desktop_environment_factory_|. | 416 // Owned as |desktop_environment_factory_|. |
| 422 DesktopSessionConnector* desktop_session_connector_ = nullptr; | 417 DesktopSessionConnector* desktop_session_connector_ = nullptr; |
| 423 #endif // defined(REMOTING_MULTI_PROCESS) | 418 #endif // defined(REMOTING_MULTI_PROCESS) |
| 424 | 419 |
| 425 int* exit_code_out_; | 420 int* exit_code_out_; |
| 426 bool signal_parent_ = false; | 421 bool signal_parent_ = false; |
| 427 | 422 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 452 // threads it contains. This will go away when we move to AutoThread. | 447 // threads it contains. This will go away when we move to AutoThread. |
| 453 // |context_release()| will null |context_| before the method is invoked, so | 448 // |context_release()| will null |context_| before the method is invoked, so |
| 454 // we need to pull out the task-runner on which to call DeleteSoon first. | 449 // we need to pull out the task-runner on which to call DeleteSoon first. |
| 455 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 450 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 456 context_->ui_task_runner(); | 451 context_->ui_task_runner(); |
| 457 task_runner->DeleteSoon(FROM_HERE, context_.release()); | 452 task_runner->DeleteSoon(FROM_HERE, context_.release()); |
| 458 } | 453 } |
| 459 | 454 |
| 460 bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) { | 455 bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) { |
| 461 #if defined(REMOTING_MULTI_PROCESS) | 456 #if defined(REMOTING_MULTI_PROCESS) |
| 462 // Mojo keeps the task runner passed to it alive forever, so an | 457 // Parse the handle value and convert it to a handle/file descriptor. |
| 463 // AutoThreadTaskRunner should not be passed to it. Otherwise, the process may | 458 std::string channel_name = |
| 464 // never shut down cleanly. | 459 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); |
| 465 ipc_support_ = base::MakeUnique<mojo::edk::ScopedIPCSupport>( | 460 |
| 466 context_->network_task_runner()->task_runner()); | 461 int pipe_handle = 0; |
| 467 mojo::edk::SetParentPipeHandle( | 462 if (channel_name.empty() || |
| 468 mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess( | 463 !base::StringToInt(channel_name, &pipe_handle)) { |
| 469 *cmd_line)); | 464 LOG(ERROR) << "Invalid '" << kDaemonPipeSwitchName |
| 465 << "' value: " << channel_name; |
| 466 return false; |
| 467 } |
| 468 |
| 469 #if defined(OS_WIN) |
| 470 base::win::ScopedHandle pipe(reinterpret_cast<HANDLE>(pipe_handle)); |
| 471 IPC::ChannelHandle channel_handle(pipe.Get()); |
| 472 #elif defined(OS_POSIX) |
| 473 base::FileDescriptor pipe(pipe_handle, true); |
| 474 IPC::ChannelHandle channel_handle(channel_name, pipe); |
| 475 #endif // defined(OS_POSIX) |
| 470 | 476 |
| 471 // Connect to the daemon process. | 477 // Connect to the daemon process. |
| 472 daemon_channel_.reset( | 478 daemon_channel_.reset( |
| 473 new IPC::ChannelProxy(this, context_->network_task_runner())); | 479 new IPC::ChannelProxy(this, context_->network_task_runner())); |
| 474 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | 480 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); |
| 475 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 481 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
| 476 if (broker && !broker->IsPrivilegedBroker()) | 482 if (broker && !broker->IsPrivilegedBroker()) |
| 477 broker->RegisterBrokerCommunicationChannel(daemon_channel_.get()); | 483 broker->RegisterBrokerCommunicationChannel(daemon_channel_.get()); |
| 478 daemon_channel_->Init(mojo::edk::CreateChildMessagePipe( | 484 daemon_channel_->Init(channel_handle, IPC::Channel::MODE_CLIENT, |
| 479 cmd_line->GetSwitchValueASCII(kMojoPipeToken)) | |
| 480 .release(), | |
| 481 IPC::Channel::MODE_CLIENT, | |
| 482 /*create_pipe_now=*/true); | 485 /*create_pipe_now=*/true); |
| 483 | 486 |
| 484 #else // !defined(REMOTING_MULTI_PROCESS) | 487 #else // !defined(REMOTING_MULTI_PROCESS) |
| 485 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 488 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| 486 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 489 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 487 | 490 |
| 488 // Read config from stdin if necessary. | 491 // Read config from stdin if necessary. |
| 489 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { | 492 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { |
| 490 const size_t kBufferSize = 4096; | 493 const size_t kBufferSize = 4096; |
| 491 std::unique_ptr<char[]> buf(new char[kBufferSize]); | 494 std::unique_ptr<char[]> buf(new char[kBufferSize]); |
| (...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1662 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
| 1660 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); | 1663 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); |
| 1661 | 1664 |
| 1662 // Run the main (also UI) message loop until the host no longer needs it. | 1665 // Run the main (also UI) message loop until the host no longer needs it. |
| 1663 base::RunLoop().Run(); | 1666 base::RunLoop().Run(); |
| 1664 | 1667 |
| 1665 return exit_code; | 1668 return exit_code; |
| 1666 } | 1669 } |
| 1667 | 1670 |
| 1668 } // namespace remoting | 1671 } // namespace remoting |
| OLD | NEW |