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/ipc_channel.h" | 23 #include "ipc/ipc_channel.h" |
24 #include "ipc/ipc_channel_proxy.h" | 24 #include "ipc/ipc_channel_proxy.h" |
25 #include "ipc/ipc_listener.h" | 25 #include "ipc/ipc_listener.h" |
| 26 #include "jingle/glue/thread_wrapper.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" |
33 #include "remoting/base/breakpad.h" | 34 #include "remoting/base/breakpad.h" |
34 #include "remoting/base/constants.h" | 35 #include "remoting/base/constants.h" |
35 #include "remoting/base/logging.h" | 36 #include "remoting/base/logging.h" |
(...skipping 29 matching lines...) Expand all Loading... |
65 #include "remoting/host/session_manager_factory.h" | 66 #include "remoting/host/session_manager_factory.h" |
66 #include "remoting/host/shutdown_watchdog.h" | 67 #include "remoting/host/shutdown_watchdog.h" |
67 #include "remoting/host/signaling_connector.h" | 68 #include "remoting/host/signaling_connector.h" |
68 #include "remoting/host/single_window_desktop_environment.h" | 69 #include "remoting/host/single_window_desktop_environment.h" |
69 #include "remoting/host/switches.h" | 70 #include "remoting/host/switches.h" |
70 #include "remoting/host/third_party_auth_config.h" | 71 #include "remoting/host/third_party_auth_config.h" |
71 #include "remoting/host/token_validator_factory_impl.h" | 72 #include "remoting/host/token_validator_factory_impl.h" |
72 #include "remoting/host/usage_stats_consent.h" | 73 #include "remoting/host/usage_stats_consent.h" |
73 #include "remoting/host/username.h" | 74 #include "remoting/host/username.h" |
74 #include "remoting/host/video_frame_recorder_host_extension.h" | 75 #include "remoting/host/video_frame_recorder_host_extension.h" |
| 76 #include "remoting/protocol/authenticator.h" |
| 77 #include "remoting/protocol/channel_authenticator.h" |
| 78 #include "remoting/protocol/chromium_port_allocator_factory.h" |
| 79 #include "remoting/protocol/jingle_session_manager.h" |
75 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 80 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
76 #include "remoting/protocol/network_settings.h" | 81 #include "remoting/protocol/network_settings.h" |
77 #include "remoting/protocol/pairing_registry.h" | 82 #include "remoting/protocol/pairing_registry.h" |
78 #include "remoting/protocol/port_range.h" | 83 #include "remoting/protocol/port_range.h" |
79 #include "remoting/protocol/token_validator.h" | 84 #include "remoting/protocol/token_validator.h" |
| 85 #include "remoting/protocol/webrtc_transport.h" |
80 #include "remoting/signaling/push_notification_subscriber.h" | 86 #include "remoting/signaling/push_notification_subscriber.h" |
81 #include "remoting/signaling/xmpp_signal_strategy.h" | 87 #include "remoting/signaling/xmpp_signal_strategy.h" |
| 88 #include "third_party/webrtc/base/scoped_ref_ptr.h" |
82 | 89 |
83 #if defined(OS_POSIX) | 90 #if defined(OS_POSIX) |
84 #include <signal.h> | 91 #include <signal.h> |
85 #include <sys/types.h> | 92 #include <sys/types.h> |
86 #include <unistd.h> | 93 #include <unistd.h> |
87 #include "base/file_descriptor_posix.h" | 94 #include "base/file_descriptor_posix.h" |
88 #include "remoting/host/pam_authorization_factory_posix.h" | 95 #include "remoting/host/pam_authorization_factory_posix.h" |
89 #include "remoting/host/posix/signal_handler.h" | 96 #include "remoting/host/posix/signal_handler.h" |
90 #endif // defined(OS_POSIX) | 97 #endif // defined(OS_POSIX) |
91 | 98 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const char kSignalParentSwitchName[] = "signal-parent"; | 148 const char kSignalParentSwitchName[] = "signal-parent"; |
142 | 149 |
143 // Command line switch used to enable VP9 encoding. | 150 // Command line switch used to enable VP9 encoding. |
144 const char kEnableVp9SwitchName[] = "enable-vp9"; | 151 const char kEnableVp9SwitchName[] = "enable-vp9"; |
145 | 152 |
146 // Command line switch used to enable and configure the frame-recorder. | 153 // Command line switch used to enable and configure the frame-recorder. |
147 const char kFrameRecorderBufferKbName[] = "frame-recorder-buffer-kb"; | 154 const char kFrameRecorderBufferKbName[] = "frame-recorder-buffer-kb"; |
148 | 155 |
149 const char kWindowIdSwitchName[] = "window-id"; | 156 const char kWindowIdSwitchName[] = "window-id"; |
150 | 157 |
| 158 // Command line switch used to enable WebRTC-based protocol. |
| 159 const char kEnableWebrtc[] = "enable-webrtc"; |
| 160 |
151 // Maximum time to wait for clean shutdown to occur, before forcing termination | 161 // Maximum time to wait for clean shutdown to occur, before forcing termination |
152 // of the process. | 162 // of the process. |
153 const int kShutdownTimeoutSeconds = 15; | 163 const int kShutdownTimeoutSeconds = 15; |
154 | 164 |
155 // Maximum time to wait for reporting host-offline-reason to the service, | 165 // Maximum time to wait for reporting host-offline-reason to the service, |
156 // before continuing normal process shutdown. | 166 // before continuing normal process shutdown. |
157 const int kHostOfflineReasonTimeoutSeconds = 10; | 167 const int kHostOfflineReasonTimeoutSeconds = 10; |
158 | 168 |
159 // Host offline reasons not associated with shutting down the host process | 169 // Host offline reasons not associated with shutting down the host process |
160 // and therefore not expressible through HostExitCodes enum. | 170 // and therefore not expressible through HostExitCodes enum. |
161 const char kHostOfflineReasonPolicyReadError[] = "POLICY_READ_ERROR"; | 171 const char kHostOfflineReasonPolicyReadError[] = "POLICY_READ_ERROR"; |
162 const char kHostOfflineReasonPolicyChangeRequiresRestart[] = | 172 const char kHostOfflineReasonPolicyChangeRequiresRestart[] = |
163 "POLICY_CHANGE_REQUIRES_RESTART"; | 173 "POLICY_CHANGE_REQUIRES_RESTART"; |
164 | 174 |
165 } // namespace | 175 } // namespace |
166 | 176 |
167 namespace remoting { | 177 namespace remoting { |
168 | 178 |
| 179 #if !defined(NDEBUG) |
| 180 |
| 181 // Authenticator that accepts all connections. Use only for testing. |
| 182 class NoopAuthenticator : public protocol::Authenticator { |
| 183 public: |
| 184 NoopAuthenticator() {} |
| 185 ~NoopAuthenticator() override {} |
| 186 |
| 187 // protocol::Authenticator interface. |
| 188 State state() const override { return done_ ? ACCEPTED : WAITING_MESSAGE; } |
| 189 bool started() const override { return done_; } |
| 190 RejectionReason rejection_reason() const override { |
| 191 NOTREACHED(); |
| 192 return INVALID_CREDENTIALS; |
| 193 } |
| 194 void ProcessMessage(const buzz::XmlElement* message, |
| 195 const base::Closure& resume_callback) override { |
| 196 done_ = true; |
| 197 resume_callback.Run(); |
| 198 } |
| 199 scoped_ptr<buzz::XmlElement> GetNextMessage() override { |
| 200 NOTREACHED(); |
| 201 return nullptr; |
| 202 } |
| 203 const std::string& GetAuthKey() const override { return auth_key_; } |
| 204 scoped_ptr<protocol::ChannelAuthenticator> CreateChannelAuthenticator() |
| 205 const override { |
| 206 NOTREACHED(); |
| 207 return nullptr; |
| 208 }; |
| 209 |
| 210 private: |
| 211 bool done_ = false; |
| 212 std::string auth_key_ = "NOKEY"; |
| 213 }; |
| 214 |
| 215 // Factory for Authenticator instances. |
| 216 class NoopAuthenticatorFactory : public protocol::AuthenticatorFactory { |
| 217 public: |
| 218 NoopAuthenticatorFactory() {} |
| 219 ~NoopAuthenticatorFactory() override {} |
| 220 |
| 221 scoped_ptr<protocol::Authenticator> CreateAuthenticator( |
| 222 const std::string& local_jid, |
| 223 const std::string& remote_jid, |
| 224 const buzz::XmlElement* first_message) override { |
| 225 return make_scoped_ptr(new NoopAuthenticator()); |
| 226 } |
| 227 }; |
| 228 |
| 229 #endif // !defined(NDEBUG) |
| 230 |
169 class HostProcess : public ConfigWatcher::Delegate, | 231 class HostProcess : public ConfigWatcher::Delegate, |
170 public HostChangeNotificationListener::Listener, | 232 public HostChangeNotificationListener::Listener, |
171 public IPC::Listener, | 233 public IPC::Listener, |
172 public base::RefCountedThreadSafe<HostProcess> { | 234 public base::RefCountedThreadSafe<HostProcess> { |
173 public: | 235 public: |
174 // |shutdown_watchdog| is armed when shutdown is started, and should be kept | 236 // |shutdown_watchdog| is armed when shutdown is started, and should be kept |
175 // alive as long as possible until the process exits (since destroying the | 237 // alive as long as possible until the process exits (since destroying the |
176 // watchdog disarms it). | 238 // watchdog disarms it). |
177 HostProcess(scoped_ptr<ChromotingHostContext> context, | 239 HostProcess(scoped_ptr<ChromotingHostContext> context, |
178 int* exit_code_out, | 240 int* exit_code_out, |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 ShutdownHost(kSuccessExitCode); | 739 ShutdownHost(kSuccessExitCode); |
678 } | 740 } |
679 #endif // OS_POSIX | 741 #endif // OS_POSIX |
680 | 742 |
681 void HostProcess::CreateAuthenticatorFactory() { | 743 void HostProcess::CreateAuthenticatorFactory() { |
682 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 744 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
683 | 745 |
684 if (state_ != HOST_STARTED) | 746 if (state_ != HOST_STARTED) |
685 return; | 747 return; |
686 | 748 |
| 749 #if !defined(NDEBUG) |
| 750 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableWebrtc)) { |
| 751 host_->SetAuthenticatorFactory( |
| 752 make_scoped_ptr(new NoopAuthenticatorFactory())); |
| 753 return; |
| 754 } |
| 755 #endif // !defined(NDEBUG) |
| 756 |
687 std::string local_certificate = key_pair_->GenerateCertificate(); | 757 std::string local_certificate = key_pair_->GenerateCertificate(); |
688 if (local_certificate.empty()) { | 758 if (local_certificate.empty()) { |
689 LOG(ERROR) << "Failed to generate host certificate."; | 759 LOG(ERROR) << "Failed to generate host certificate."; |
690 ShutdownHost(kInitializationFailed); | 760 ShutdownHost(kInitializationFailed); |
691 return; | 761 return; |
692 } | 762 } |
693 | 763 |
694 scoped_ptr<protocol::AuthenticatorFactory> factory; | 764 scoped_ptr<protocol::AuthenticatorFactory> factory; |
695 | 765 |
696 if (third_party_auth_config_.is_null()) { | 766 if (third_party_auth_config_.is_null()) { |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 if (!udp_port_range_.is_null()) { | 1489 if (!udp_port_range_.is_null()) { |
1420 network_settings.port_range = udp_port_range_; | 1490 network_settings.port_range = udp_port_range_; |
1421 } else if (!allow_nat_traversal_) { | 1491 } else if (!allow_nat_traversal_) { |
1422 // For legacy reasons we have to restrict the port range to a set of default | 1492 // For legacy reasons we have to restrict the port range to a set of default |
1423 // values when nat traversal is disabled, even if the port range was not | 1493 // values when nat traversal is disabled, even if the port range was not |
1424 // set in policy. | 1494 // set in policy. |
1425 network_settings.port_range.min_port = NetworkSettings::kDefaultMinPort; | 1495 network_settings.port_range.min_port = NetworkSettings::kDefaultMinPort; |
1426 network_settings.port_range.max_port = NetworkSettings::kDefaultMaxPort; | 1496 network_settings.port_range.max_port = NetworkSettings::kDefaultMaxPort; |
1427 } | 1497 } |
1428 | 1498 |
1429 scoped_ptr<protocol::SessionManager> session_manager = | 1499 scoped_ptr<protocol::SessionManager> session_manager; |
1430 CreateHostSessionManager(signal_strategy_.get(), network_settings, | 1500 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableWebrtc)) { |
1431 context_->url_request_context_getter()); | 1501 #if !defined(NDEBUG) |
| 1502 network_settings.flags = protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING; |
| 1503 |
| 1504 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
| 1505 port_allocator_factory = protocol::ChromiumPortAllocatorFactory::Create( |
| 1506 network_settings, context_->url_request_context_getter()); |
| 1507 |
| 1508 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 1509 |
| 1510 // The network thread is also used as worker thread for webrtc. |
| 1511 // |
| 1512 // TODO(sergeyu): Figure out if we would benefit from using a separate |
| 1513 // thread as a worker thread. |
| 1514 scoped_ptr<protocol::TransportFactory> transport_factory( |
| 1515 new protocol::WebrtcTransportFactory( |
| 1516 jingle_glue::JingleThreadWrapper::current(), signal_strategy_.get(), |
| 1517 port_allocator_factory, protocol::TransportRole::SERVER)); |
| 1518 |
| 1519 session_manager.reset( |
| 1520 new protocol::JingleSessionManager(transport_factory.Pass())); |
| 1521 #else // !defined(NDEBUG) |
| 1522 LOG(ERROR) << "WebRTC is enabled only in debug builds."; |
| 1523 ShutdownHost(kUsageExitCode); |
| 1524 return; |
| 1525 #endif // defined(NDEBUG) |
| 1526 } else { |
| 1527 session_manager = |
| 1528 CreateHostSessionManager(signal_strategy_.get(), network_settings, |
| 1529 context_->url_request_context_getter()); |
| 1530 } |
1432 | 1531 |
1433 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 1532 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = |
1434 protocol::CandidateSessionConfig::CreateDefault(); | 1533 protocol::CandidateSessionConfig::CreateDefault(); |
1435 if (!desktop_environment_factory_->SupportsAudioCapture()) | 1534 if (!desktop_environment_factory_->SupportsAudioCapture()) |
1436 protocol_config->DisableAudioChannel(); | 1535 protocol_config->DisableAudioChannel(); |
1437 if (enable_vp9_) | 1536 if (enable_vp9_) |
1438 protocol_config->set_vp9_experiment_enabled(true); | 1537 protocol_config->set_vp9_experiment_enabled(true); |
| 1538 #if !defined(NDEBUG) |
| 1539 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableWebrtc)) { |
| 1540 protocol_config->set_webrtc_supported(true); |
| 1541 } |
| 1542 #endif // !defined(NDEBUG) |
1439 session_manager->set_protocol_config(protocol_config.Pass()); | 1543 session_manager->set_protocol_config(protocol_config.Pass()); |
1440 | 1544 |
1441 host_.reset(new ChromotingHost( | 1545 host_.reset(new ChromotingHost( |
1442 signal_strategy_.get(), desktop_environment_factory_.get(), | 1546 signal_strategy_.get(), desktop_environment_factory_.get(), |
1443 session_manager.Pass(), context_->audio_task_runner(), | 1547 session_manager.Pass(), context_->audio_task_runner(), |
1444 context_->input_task_runner(), context_->video_capture_task_runner(), | 1548 context_->input_task_runner(), context_->video_capture_task_runner(), |
1445 context_->video_encode_task_runner(), context_->network_task_runner(), | 1549 context_->video_encode_task_runner(), context_->network_task_runner(), |
1446 context_->ui_task_runner())); | 1550 context_->ui_task_runner())); |
1447 | 1551 |
1448 if (frame_recorder_buffer_size_ > 0) { | 1552 if (frame_recorder_buffer_size_ > 0) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1750 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
1647 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1751 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); |
1648 | 1752 |
1649 // Run the main (also UI) message loop until the host no longer needs it. | 1753 // Run the main (also UI) message loop until the host no longer needs it. |
1650 message_loop.Run(); | 1754 message_loop.Run(); |
1651 | 1755 |
1652 return exit_code; | 1756 return exit_code; |
1653 } | 1757 } |
1654 | 1758 |
1655 } // namespace remoting | 1759 } // namespace remoting |
OLD | NEW |