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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringize_macros.h" | 20 #include "base/strings/stringize_macros.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 #include "ipc/attachment_broker_unprivileged.h" | |
23 #include "ipc/ipc_channel.h" | 24 #include "ipc/ipc_channel.h" |
24 #include "ipc/ipc_channel_proxy.h" | 25 #include "ipc/ipc_channel_proxy.h" |
25 #include "ipc/ipc_listener.h" | 26 #include "ipc/ipc_listener.h" |
26 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
27 #include "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
28 #include "net/socket/client_socket_factory.h" | 29 #include "net/socket/client_socket_factory.h" |
29 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
30 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
31 #include "policy/policy_constants.h" | 32 #include "policy/policy_constants.h" |
32 #include "remoting/base/auto_thread_task_runner.h" | 33 #include "remoting/base/auto_thread_task_runner.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 | 309 |
309 // Crashes the process in response to a daemon's request. The daemon passes | 310 // Crashes the process in response to a daemon's request. The daemon passes |
310 // the location of the code that detected the fatal error resulted in this | 311 // the location of the code that detected the fatal error resulted in this |
311 // request. | 312 // request. |
312 void OnCrash(const std::string& function_name, | 313 void OnCrash(const std::string& function_name, |
313 const std::string& file_name, | 314 const std::string& file_name, |
314 const int& line_number); | 315 const int& line_number); |
315 | 316 |
316 scoped_ptr<ChromotingHostContext> context_; | 317 scoped_ptr<ChromotingHostContext> context_; |
317 | 318 |
319 scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_; | |
Sergey Ulanov
2015/12/12 06:41:33
Why do we need attachment broker now, but didn't n
erikchen
2015/12/18 19:14:10
An attachment broker is needed in each process tha
| |
320 | |
318 // Accessed on the UI thread. | 321 // Accessed on the UI thread. |
319 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 322 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
320 | 323 |
321 // XMPP server/remoting bot configuration (initialized from the command line). | 324 // XMPP server/remoting bot configuration (initialized from the command line). |
322 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 325 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
323 std::string directory_bot_jid_; | 326 std::string directory_bot_jid_; |
324 | 327 |
325 // Created on the UI thread but used from the network thread. | 328 // Created on the UI thread but used from the network thread. |
326 base::FilePath host_config_path_; | 329 base::FilePath host_config_path_; |
327 std::string host_config_; | 330 std::string host_config_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 | 401 |
399 ShutdownWatchdog* shutdown_watchdog_; | 402 ShutdownWatchdog* shutdown_watchdog_; |
400 | 403 |
401 DISALLOW_COPY_AND_ASSIGN(HostProcess); | 404 DISALLOW_COPY_AND_ASSIGN(HostProcess); |
402 }; | 405 }; |
403 | 406 |
404 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 407 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
405 int* exit_code_out, | 408 int* exit_code_out, |
406 ShutdownWatchdog* shutdown_watchdog) | 409 ShutdownWatchdog* shutdown_watchdog) |
407 : context_(context.Pass()), | 410 : context_(context.Pass()), |
411 attachment_broker_(IPC::AttachmentBrokerUnprivileged::CreateBroker() | |
412 .release()), | |
Sergey Ulanov
2015/12/12 06:41:33
don't need release() here
erikchen
2015/12/18 19:14:10
Done.
| |
408 state_(HOST_STARTING), | 413 state_(HOST_STARTING), |
409 use_service_account_(false), | 414 use_service_account_(false), |
410 enable_vp9_(false), | 415 enable_vp9_(false), |
411 frame_recorder_buffer_size_(0), | 416 frame_recorder_buffer_size_(0), |
412 policy_state_(POLICY_INITIALIZING), | 417 policy_state_(POLICY_INITIALIZING), |
413 host_username_match_required_(false), | 418 host_username_match_required_(false), |
414 allow_nat_traversal_(true), | 419 allow_nat_traversal_(true), |
415 allow_relay_(true), | 420 allow_relay_(true), |
416 allow_pairing_(true), | 421 allow_pairing_(true), |
417 curtain_required_(false), | 422 curtain_required_(false), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 #elif defined(OS_POSIX) | 469 #elif defined(OS_POSIX) |
465 base::FileDescriptor pipe(pipe_handle, true); | 470 base::FileDescriptor pipe(pipe_handle, true); |
466 IPC::ChannelHandle channel_handle(channel_name, pipe); | 471 IPC::ChannelHandle channel_handle(channel_name, pipe); |
467 #endif // defined(OS_POSIX) | 472 #endif // defined(OS_POSIX) |
468 | 473 |
469 // Connect to the daemon process. | 474 // Connect to the daemon process. |
470 daemon_channel_ = IPC::ChannelProxy::Create(channel_handle, | 475 daemon_channel_ = IPC::ChannelProxy::Create(channel_handle, |
471 IPC::Channel::MODE_CLIENT, | 476 IPC::Channel::MODE_CLIENT, |
472 this, | 477 this, |
473 context_->network_task_runner()); | 478 context_->network_task_runner()); |
479 attachment_broker_->DesignateBrokerCommunicationChannel( | |
Sergey Ulanov
2015/12/12 06:41:33
Comments for IPC::AttachmentBrokerUnprivileged::Cr
erikchen
2015/12/18 19:14:10
good point. Added a conditional.
| |
480 daemon_channel_.get()); | |
481 | |
474 #else // !defined(REMOTING_MULTI_PROCESS) | 482 #else // !defined(REMOTING_MULTI_PROCESS) |
475 // Connect to the daemon process. | 483 // Connect to the daemon process. |
476 std::string channel_name = | 484 std::string channel_name = |
477 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); | 485 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); |
478 if (!channel_name.empty()) { | 486 if (!channel_name.empty()) { |
479 daemon_channel_ = | 487 daemon_channel_ = |
480 IPC::ChannelProxy::Create(channel_name, IPC::Channel::MODE_CLIENT, this, | 488 IPC::ChannelProxy::Create(channel_name, IPC::Channel::MODE_CLIENT, this, |
481 context_->network_task_runner().get()); | 489 context_->network_task_runner().get()); |
490 attachment_broker_->DesignateBrokerCommunicationChannel( | |
491 daemon_channel_.get()); | |
482 } | 492 } |
483 | 493 |
484 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 494 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
485 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 495 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
486 | 496 |
487 // Read config from stdin if necessary. | 497 // Read config from stdin if necessary. |
488 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { | 498 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { |
489 const size_t kBufferSize = 4096; | 499 const size_t kBufferSize = 4096; |
490 scoped_ptr<char[]> buf(new char[kBufferSize]); | 500 scoped_ptr<char[]> buf(new char[kBufferSize]); |
491 size_t len; | 501 size_t len; |
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1646 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1656 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
1647 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1657 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); |
1648 | 1658 |
1649 // Run the main (also UI) message loop until the host no longer needs it. | 1659 // Run the main (also UI) message loop until the host no longer needs it. |
1650 message_loop.Run(); | 1660 message_loop.Run(); |
1651 | 1661 |
1652 return exit_code; | 1662 return exit_code; |
1653 } | 1663 } |
1654 | 1664 |
1655 } // namespace remoting | 1665 } // namespace remoting |
OLD | NEW |