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 <memory> |
10 #include <string> | 11 #include <string> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/debug/alias.h" | 17 #include "base/debug/alias.h" |
17 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
19 #include "base/macros.h" | 20 #include "base/macros.h" |
20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/ptr_util.h" |
21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
25 #include "base/strings/stringize_macros.h" | 26 #include "base/strings/stringize_macros.h" |
26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "ipc/attachment_broker_unprivileged.h" | 29 #include "ipc/attachment_broker_unprivileged.h" |
29 #include "ipc/ipc_channel.h" | 30 #include "ipc/ipc_channel.h" |
30 #include "ipc/ipc_channel_proxy.h" | 31 #include "ipc/ipc_channel_proxy.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 bool started() const override { return done_; } | 196 bool started() const override { return done_; } |
196 RejectionReason rejection_reason() const override { | 197 RejectionReason rejection_reason() const override { |
197 NOTREACHED(); | 198 NOTREACHED(); |
198 return INVALID_CREDENTIALS; | 199 return INVALID_CREDENTIALS; |
199 } | 200 } |
200 void ProcessMessage(const buzz::XmlElement* message, | 201 void ProcessMessage(const buzz::XmlElement* message, |
201 const base::Closure& resume_callback) override { | 202 const base::Closure& resume_callback) override { |
202 done_ = true; | 203 done_ = true; |
203 resume_callback.Run(); | 204 resume_callback.Run(); |
204 } | 205 } |
205 scoped_ptr<buzz::XmlElement> GetNextMessage() override { | 206 std::unique_ptr<buzz::XmlElement> GetNextMessage() override { |
206 NOTREACHED(); | 207 NOTREACHED(); |
207 return nullptr; | 208 return nullptr; |
208 } | 209 } |
209 const std::string& GetAuthKey() const override { return auth_key_; } | 210 const std::string& GetAuthKey() const override { return auth_key_; } |
210 scoped_ptr<protocol::ChannelAuthenticator> CreateChannelAuthenticator() | 211 std::unique_ptr<protocol::ChannelAuthenticator> CreateChannelAuthenticator() |
211 const override { | 212 const override { |
212 NOTREACHED(); | 213 NOTREACHED(); |
213 return nullptr; | 214 return nullptr; |
214 }; | 215 }; |
215 | 216 |
216 private: | 217 private: |
217 bool done_ = false; | 218 bool done_ = false; |
218 std::string auth_key_ = "NOKEY"; | 219 std::string auth_key_ = "NOKEY"; |
219 }; | 220 }; |
220 | 221 |
221 // Factory for Authenticator instances. | 222 // Factory for Authenticator instances. |
222 class NoopAuthenticatorFactory : public protocol::AuthenticatorFactory { | 223 class NoopAuthenticatorFactory : public protocol::AuthenticatorFactory { |
223 public: | 224 public: |
224 NoopAuthenticatorFactory() {} | 225 NoopAuthenticatorFactory() {} |
225 ~NoopAuthenticatorFactory() override {} | 226 ~NoopAuthenticatorFactory() override {} |
226 | 227 |
227 scoped_ptr<protocol::Authenticator> CreateAuthenticator( | 228 std::unique_ptr<protocol::Authenticator> CreateAuthenticator( |
228 const std::string& local_jid, | 229 const std::string& local_jid, |
229 const std::string& remote_jid) override { | 230 const std::string& remote_jid) override { |
230 return make_scoped_ptr(new NoopAuthenticator()); | 231 return base::WrapUnique(new NoopAuthenticator()); |
231 } | 232 } |
232 }; | 233 }; |
233 | 234 |
234 #endif // !defined(NDEBUG) | 235 #endif // !defined(NDEBUG) |
235 | 236 |
236 class HostProcess : public ConfigWatcher::Delegate, | 237 class HostProcess : public ConfigWatcher::Delegate, |
237 public HostChangeNotificationListener::Listener, | 238 public HostChangeNotificationListener::Listener, |
238 public IPC::Listener, | 239 public IPC::Listener, |
239 public base::RefCountedThreadSafe<HostProcess> { | 240 public base::RefCountedThreadSafe<HostProcess> { |
240 public: | 241 public: |
241 // |shutdown_watchdog| is armed when shutdown is started, and should be kept | 242 // |shutdown_watchdog| is armed when shutdown is started, and should be kept |
242 // alive as long as possible until the process exits (since destroying the | 243 // alive as long as possible until the process exits (since destroying the |
243 // watchdog disarms it). | 244 // watchdog disarms it). |
244 HostProcess(scoped_ptr<ChromotingHostContext> context, | 245 HostProcess(std::unique_ptr<ChromotingHostContext> context, |
245 int* exit_code_out, | 246 int* exit_code_out, |
246 ShutdownWatchdog* shutdown_watchdog); | 247 ShutdownWatchdog* shutdown_watchdog); |
247 | 248 |
248 // ConfigWatcher::Delegate interface. | 249 // ConfigWatcher::Delegate interface. |
249 void OnConfigUpdated(const std::string& serialized_config) override; | 250 void OnConfigUpdated(const std::string& serialized_config) override; |
250 void OnConfigWatcherError() override; | 251 void OnConfigWatcherError() override; |
251 | 252 |
252 // IPC::Listener implementation. | 253 // IPC::Listener implementation. |
253 bool OnMessageReceived(const IPC::Message& message) override; | 254 bool OnMessageReceived(const IPC::Message& message) override; |
254 void OnChannelError() override; | 255 void OnChannelError() override; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // Called on the network thread to set the host's Authenticator factory. | 324 // Called on the network thread to set the host's Authenticator factory. |
324 void CreateAuthenticatorFactory(); | 325 void CreateAuthenticatorFactory(); |
325 | 326 |
326 // Tear down resources that run on the UI thread. | 327 // Tear down resources that run on the UI thread. |
327 void ShutdownOnUiThread(); | 328 void ShutdownOnUiThread(); |
328 | 329 |
329 // Applies the host config, returning true if successful. | 330 // Applies the host config, returning true if successful. |
330 bool ApplyConfig(const base::DictionaryValue& config); | 331 bool ApplyConfig(const base::DictionaryValue& config); |
331 | 332 |
332 // Handles policy updates, by calling On*PolicyUpdate methods. | 333 // Handles policy updates, by calling On*PolicyUpdate methods. |
333 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 334 void OnPolicyUpdate(std::unique_ptr<base::DictionaryValue> policies); |
334 void OnPolicyError(); | 335 void OnPolicyError(); |
335 void ReportPolicyErrorAndRestartHost(); | 336 void ReportPolicyErrorAndRestartHost(); |
336 void ApplyHostDomainPolicy(); | 337 void ApplyHostDomainPolicy(); |
337 void ApplyUsernamePolicy(); | 338 void ApplyUsernamePolicy(); |
338 bool OnClientDomainPolicyUpdate(base::DictionaryValue* policies); | 339 bool OnClientDomainPolicyUpdate(base::DictionaryValue* policies); |
339 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); | 340 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); |
340 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 341 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
341 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 342 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
342 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 343 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
343 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 344 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
(...skipping 30 matching lines...) Expand all Loading... |
374 IPC::PlatformFileForTransit unprivileged_key); | 375 IPC::PlatformFileForTransit unprivileged_key); |
375 #endif // defined(OS_WIN) | 376 #endif // defined(OS_WIN) |
376 | 377 |
377 // Crashes the process in response to a daemon's request. The daemon passes | 378 // Crashes the process in response to a daemon's request. The daemon passes |
378 // the location of the code that detected the fatal error resulted in this | 379 // the location of the code that detected the fatal error resulted in this |
379 // request. | 380 // request. |
380 void OnCrash(const std::string& function_name, | 381 void OnCrash(const std::string& function_name, |
381 const std::string& file_name, | 382 const std::string& file_name, |
382 const int& line_number); | 383 const int& line_number); |
383 | 384 |
384 scoped_ptr<ChromotingHostContext> context_; | 385 std::unique_ptr<ChromotingHostContext> context_; |
385 | 386 |
386 // XMPP server/remoting bot configuration (initialized from the command line). | 387 // XMPP server/remoting bot configuration (initialized from the command line). |
387 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 388 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
388 std::string directory_bot_jid_; | 389 std::string directory_bot_jid_; |
389 | 390 |
390 // Created on the UI thread but used from the network thread. | 391 // Created on the UI thread but used from the network thread. |
391 base::FilePath host_config_path_; | 392 base::FilePath host_config_path_; |
392 std::string host_config_; | 393 std::string host_config_; |
393 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 394 std::unique_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
394 | 395 |
395 // Accessed on the network thread. | 396 // Accessed on the network thread. |
396 HostState state_ = HOST_STARTING; | 397 HostState state_ = HOST_STARTING; |
397 | 398 |
398 scoped_ptr<ConfigWatcher> config_watcher_; | 399 std::unique_ptr<ConfigWatcher> config_watcher_; |
399 | 400 |
400 std::string host_id_; | 401 std::string host_id_; |
401 std::string pin_hash_; | 402 std::string pin_hash_; |
402 scoped_refptr<RsaKeyPair> key_pair_; | 403 scoped_refptr<RsaKeyPair> key_pair_; |
403 std::string oauth_refresh_token_; | 404 std::string oauth_refresh_token_; |
404 std::string serialized_config_; | 405 std::string serialized_config_; |
405 std::string host_owner_; | 406 std::string host_owner_; |
406 std::string host_owner_email_; | 407 std::string host_owner_email_; |
407 bool use_service_account_ = false; | 408 bool use_service_account_ = false; |
408 bool enable_vp9_ = false; | 409 bool enable_vp9_ = false; |
409 | 410 |
410 scoped_ptr<PolicyWatcher> policy_watcher_; | 411 std::unique_ptr<PolicyWatcher> policy_watcher_; |
411 PolicyState policy_state_ = POLICY_INITIALIZING; | 412 PolicyState policy_state_ = POLICY_INITIALIZING; |
412 std::string client_domain_; | 413 std::string client_domain_; |
413 std::string host_domain_; | 414 std::string host_domain_; |
414 bool host_username_match_required_ = false; | 415 bool host_username_match_required_ = false; |
415 bool allow_nat_traversal_ = true; | 416 bool allow_nat_traversal_ = true; |
416 bool allow_relay_ = true; | 417 bool allow_relay_ = true; |
417 PortRange udp_port_range_; | 418 PortRange udp_port_range_; |
418 std::string talkgadget_prefix_; | 419 std::string talkgadget_prefix_; |
419 bool allow_pairing_ = true; | 420 bool allow_pairing_ = true; |
420 | 421 |
421 bool curtain_required_ = false; | 422 bool curtain_required_ = false; |
422 ThirdPartyAuthConfig third_party_auth_config_; | 423 ThirdPartyAuthConfig third_party_auth_config_; |
423 bool gnubby_auth_policy_enabled_ = false; | 424 bool gnubby_auth_policy_enabled_ = false; |
424 bool gnubby_extension_supported_ = false; | 425 bool gnubby_extension_supported_ = false; |
425 | 426 |
426 // Boolean to change flow, where necessary, if we're | 427 // Boolean to change flow, where necessary, if we're |
427 // capturing a window instead of the entire desktop. | 428 // capturing a window instead of the entire desktop. |
428 bool enable_window_capture_ = false; | 429 bool enable_window_capture_ = false; |
429 | 430 |
430 // Used to specify which window to stream, if enabled. | 431 // Used to specify which window to stream, if enabled. |
431 webrtc::WindowId window_id_ = 0; | 432 webrtc::WindowId window_id_ = 0; |
432 | 433 |
433 // Must outlive |gcd_state_updater_| and |signaling_connector_|. | 434 // Must outlive |gcd_state_updater_| and |signaling_connector_|. |
434 scoped_ptr<OAuthTokenGetter> oauth_token_getter_; | 435 std::unique_ptr<OAuthTokenGetter> oauth_token_getter_; |
435 | 436 |
436 // Must outlive |signaling_connector_|, |gcd_subscriber_|, and | 437 // Must outlive |signaling_connector_|, |gcd_subscriber_|, and |
437 // |heartbeat_sender_|. | 438 // |heartbeat_sender_|. |
438 scoped_ptr<SignalStrategy> signal_strategy_; | 439 std::unique_ptr<SignalStrategy> signal_strategy_; |
439 | 440 |
440 scoped_ptr<SignalingConnector> signaling_connector_; | 441 std::unique_ptr<SignalingConnector> signaling_connector_; |
441 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 442 std::unique_ptr<HeartbeatSender> heartbeat_sender_; |
442 #if defined(USE_GCD) | 443 #if defined(USE_GCD) |
443 scoped_ptr<GcdStateUpdater> gcd_state_updater_; | 444 std::unique_ptr<GcdStateUpdater> gcd_state_updater_; |
444 scoped_ptr<PushNotificationSubscriber> gcd_subscriber_; | 445 std::unique_ptr<PushNotificationSubscriber> gcd_subscriber_; |
445 #endif // defined(USE_GCD) | 446 #endif // defined(USE_GCD) |
446 | 447 |
447 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 448 std::unique_ptr<HostChangeNotificationListener> |
448 scoped_ptr<HostStatusLogger> host_status_logger_; | 449 host_change_notification_listener_; |
449 scoped_ptr<HostEventLogger> host_event_logger_; | 450 std::unique_ptr<HostStatusLogger> host_status_logger_; |
| 451 std::unique_ptr<HostEventLogger> host_event_logger_; |
450 | 452 |
451 scoped_ptr<ChromotingHost> host_; | 453 std::unique_ptr<ChromotingHost> host_; |
452 | 454 |
453 // Used to keep this HostProcess alive until it is shutdown. | 455 // Used to keep this HostProcess alive until it is shutdown. |
454 scoped_refptr<HostProcess> self_; | 456 scoped_refptr<HostProcess> self_; |
455 | 457 |
456 #if defined(REMOTING_MULTI_PROCESS) | 458 #if defined(REMOTING_MULTI_PROCESS) |
457 // Accessed on the UI thread. | 459 // Accessed on the UI thread. |
458 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 460 std::unique_ptr<IPC::ChannelProxy> daemon_channel_; |
459 | 461 |
460 // Owned as |desktop_environment_factory_|. | 462 // Owned as |desktop_environment_factory_|. |
461 DesktopSessionConnector* desktop_session_connector_ = nullptr; | 463 DesktopSessionConnector* desktop_session_connector_ = nullptr; |
462 #endif // defined(REMOTING_MULTI_PROCESS) | 464 #endif // defined(REMOTING_MULTI_PROCESS) |
463 | 465 |
464 int* exit_code_out_; | 466 int* exit_code_out_; |
465 bool signal_parent_ = false; | 467 bool signal_parent_ = false; |
466 | 468 |
467 scoped_refptr<PairingRegistry> pairing_registry_; | 469 scoped_refptr<PairingRegistry> pairing_registry_; |
468 | 470 |
469 ShutdownWatchdog* shutdown_watchdog_; | 471 ShutdownWatchdog* shutdown_watchdog_; |
470 | 472 |
471 DISALLOW_COPY_AND_ASSIGN(HostProcess); | 473 DISALLOW_COPY_AND_ASSIGN(HostProcess); |
472 }; | 474 }; |
473 | 475 |
474 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 476 HostProcess::HostProcess(std::unique_ptr<ChromotingHostContext> context, |
475 int* exit_code_out, | 477 int* exit_code_out, |
476 ShutdownWatchdog* shutdown_watchdog) | 478 ShutdownWatchdog* shutdown_watchdog) |
477 : context_(std::move(context)), | 479 : context_(std::move(context)), |
478 self_(this), | 480 self_(this), |
479 exit_code_out_(exit_code_out), | 481 exit_code_out_(exit_code_out), |
480 shutdown_watchdog_(shutdown_watchdog) { | 482 shutdown_watchdog_(shutdown_watchdog) { |
481 StartOnUiThread(); | 483 StartOnUiThread(); |
482 } | 484 } |
483 | 485 |
484 HostProcess::~HostProcess() { | 486 HostProcess::~HostProcess() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 if (broker && !broker->IsPrivilegedBroker()) | 531 if (broker && !broker->IsPrivilegedBroker()) |
530 broker->RegisterBrokerCommunicationChannel(daemon_channel_.get()); | 532 broker->RegisterBrokerCommunicationChannel(daemon_channel_.get()); |
531 | 533 |
532 #else // !defined(REMOTING_MULTI_PROCESS) | 534 #else // !defined(REMOTING_MULTI_PROCESS) |
533 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 535 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
534 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 536 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
535 | 537 |
536 // Read config from stdin if necessary. | 538 // Read config from stdin if necessary. |
537 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { | 539 if (host_config_path_ == base::FilePath(kStdinConfigPath)) { |
538 const size_t kBufferSize = 4096; | 540 const size_t kBufferSize = 4096; |
539 scoped_ptr<char[]> buf(new char[kBufferSize]); | 541 std::unique_ptr<char[]> buf(new char[kBufferSize]); |
540 size_t len; | 542 size_t len; |
541 while ((len = fread(buf.get(), 1, kBufferSize, stdin)) > 0) { | 543 while ((len = fread(buf.get(), 1, kBufferSize, stdin)) > 0) { |
542 host_config_.append(buf.get(), len); | 544 host_config_.append(buf.get(), len); |
543 } | 545 } |
544 } | 546 } |
545 } else { | 547 } else { |
546 base::FilePath default_config_dir = remoting::GetConfigDir(); | 548 base::FilePath default_config_dir = remoting::GetConfigDir(); |
547 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 549 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
548 } | 550 } |
549 | 551 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return; | 606 return; |
605 } | 607 } |
606 | 608 |
607 // Filter out duplicates. | 609 // Filter out duplicates. |
608 if (serialized_config_ == serialized_config) | 610 if (serialized_config_ == serialized_config) |
609 return; | 611 return; |
610 | 612 |
611 HOST_LOG << "Processing new host configuration."; | 613 HOST_LOG << "Processing new host configuration."; |
612 | 614 |
613 serialized_config_ = serialized_config; | 615 serialized_config_ = serialized_config; |
614 scoped_ptr<base::DictionaryValue> config( | 616 std::unique_ptr<base::DictionaryValue> config( |
615 HostConfigFromJson(serialized_config)); | 617 HostConfigFromJson(serialized_config)); |
616 if (!config) { | 618 if (!config) { |
617 LOG(ERROR) << "Invalid configuration."; | 619 LOG(ERROR) << "Invalid configuration."; |
618 ShutdownHost(kInvalidHostConfigurationExitCode); | 620 ShutdownHost(kInvalidHostConfigurationExitCode); |
619 return; | 621 return; |
620 } | 622 } |
621 | 623 |
622 if (!ApplyConfig(*config)) { | 624 if (!ApplyConfig(*config)) { |
623 LOG(ERROR) << "Failed to apply the configuration."; | 625 LOG(ERROR) << "Failed to apply the configuration."; |
624 ShutdownHost(kInvalidHostConfigurationExitCode); | 626 ShutdownHost(kInvalidHostConfigurationExitCode); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 if (state_ != HOST_STARTED) | 735 if (state_ != HOST_STARTED) |
734 return; | 736 return; |
735 | 737 |
736 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 738 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
737 kDisableAuthenticationSwitchName)) { | 739 kDisableAuthenticationSwitchName)) { |
738 #if defined(NDEBUG) | 740 #if defined(NDEBUG) |
739 LOG(ERROR) << "Authentication can be disabled only in debug builds."; | 741 LOG(ERROR) << "Authentication can be disabled only in debug builds."; |
740 ShutdownHost(kInitializationFailed); | 742 ShutdownHost(kInitializationFailed); |
741 #else // defined(NDEBUG) | 743 #else // defined(NDEBUG) |
742 host_->SetAuthenticatorFactory( | 744 host_->SetAuthenticatorFactory( |
743 make_scoped_ptr(new NoopAuthenticatorFactory())); | 745 base::WrapUnique(new NoopAuthenticatorFactory())); |
744 #endif // !defined(NDEBUG) | 746 #endif // !defined(NDEBUG) |
745 return; | 747 return; |
746 } | 748 } |
747 | 749 |
748 std::string local_certificate = key_pair_->GenerateCertificate(); | 750 std::string local_certificate = key_pair_->GenerateCertificate(); |
749 if (local_certificate.empty()) { | 751 if (local_certificate.empty()) { |
750 LOG(ERROR) << "Failed to generate host certificate."; | 752 LOG(ERROR) << "Failed to generate host certificate."; |
751 ShutdownHost(kInitializationFailed); | 753 ShutdownHost(kInitializationFailed); |
752 return; | 754 return; |
753 } | 755 } |
754 | 756 |
755 scoped_ptr<protocol::AuthenticatorFactory> factory; | 757 std::unique_ptr<protocol::AuthenticatorFactory> factory; |
756 | 758 |
757 if (third_party_auth_config_.is_null()) { | 759 if (third_party_auth_config_.is_null()) { |
758 scoped_refptr<PairingRegistry> pairing_registry; | 760 scoped_refptr<PairingRegistry> pairing_registry; |
759 if (allow_pairing_) { | 761 if (allow_pairing_) { |
760 // On Windows |pairing_registry_| is initialized in | 762 // On Windows |pairing_registry_| is initialized in |
761 // InitializePairingRegistry(). | 763 // InitializePairingRegistry(). |
762 #if !defined(OS_WIN) | 764 #if !defined(OS_WIN) |
763 if (!pairing_registry_) { | 765 if (!pairing_registry_) { |
764 scoped_ptr<PairingRegistry::Delegate> delegate = | 766 std::unique_ptr<PairingRegistry::Delegate> delegate = |
765 CreatePairingRegistryDelegate(); | 767 CreatePairingRegistryDelegate(); |
766 | 768 |
767 if (delegate) | 769 if (delegate) |
768 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), | 770 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), |
769 std::move(delegate)); | 771 std::move(delegate)); |
770 } | 772 } |
771 #endif // defined(OS_WIN) | 773 #endif // defined(OS_WIN) |
772 | 774 |
773 pairing_registry = pairing_registry_; | 775 pairing_registry = pairing_registry_; |
774 } | 776 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 // |privileged_key| can be nullptr but not |unprivileged_key|. | 971 // |privileged_key| can be nullptr but not |unprivileged_key|. |
970 DCHECK(unprivileged_key.IsValid()); | 972 DCHECK(unprivileged_key.IsValid()); |
971 // |pairing_registry_| should only be initialized once. | 973 // |pairing_registry_| should only be initialized once. |
972 DCHECK(!pairing_registry_); | 974 DCHECK(!pairing_registry_); |
973 | 975 |
974 HKEY privileged_hkey = reinterpret_cast<HKEY>( | 976 HKEY privileged_hkey = reinterpret_cast<HKEY>( |
975 IPC::PlatformFileForTransitToPlatformFile(privileged_key)); | 977 IPC::PlatformFileForTransitToPlatformFile(privileged_key)); |
976 HKEY unprivileged_hkey = reinterpret_cast<HKEY>( | 978 HKEY unprivileged_hkey = reinterpret_cast<HKEY>( |
977 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); | 979 IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); |
978 | 980 |
979 scoped_ptr<PairingRegistryDelegateWin> delegate( | 981 std::unique_ptr<PairingRegistryDelegateWin> delegate( |
980 new PairingRegistryDelegateWin()); | 982 new PairingRegistryDelegateWin()); |
981 delegate->SetRootKeys(privileged_hkey, unprivileged_hkey); | 983 delegate->SetRootKeys(privileged_hkey, unprivileged_hkey); |
982 | 984 |
983 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), | 985 pairing_registry_ = new PairingRegistry(context_->file_task_runner(), |
984 std::move(delegate)); | 986 std::move(delegate)); |
985 | 987 |
986 // (Re)Create the authenticator factory now that |pairing_registry_| has been | 988 // (Re)Create the authenticator factory now that |pairing_registry_| has been |
987 // initialized. | 989 // initialized. |
988 CreateAuthenticatorFactory(); | 990 CreateAuthenticatorFactory(); |
989 } | 991 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 // Allow offering of VP9 encoding to be overridden by the command-line. | 1045 // Allow offering of VP9 encoding to be overridden by the command-line. |
1044 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableVp9SwitchName)) { | 1046 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableVp9SwitchName)) { |
1045 enable_vp9_ = true; | 1047 enable_vp9_ = true; |
1046 } else { | 1048 } else { |
1047 config.GetBoolean(kEnableVp9ConfigPath, &enable_vp9_); | 1049 config.GetBoolean(kEnableVp9ConfigPath, &enable_vp9_); |
1048 } | 1050 } |
1049 | 1051 |
1050 return true; | 1052 return true; |
1051 } | 1053 } |
1052 | 1054 |
1053 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 1055 void HostProcess::OnPolicyUpdate( |
| 1056 std::unique_ptr<base::DictionaryValue> policies) { |
1054 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 1057 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
1055 context_->network_task_runner()->PostTask( | 1058 context_->network_task_runner()->PostTask( |
1056 FROM_HERE, base::Bind(&HostProcess::OnPolicyUpdate, this, | 1059 FROM_HERE, base::Bind(&HostProcess::OnPolicyUpdate, this, |
1057 base::Passed(&policies))); | 1060 base::Passed(&policies))); |
1058 return; | 1061 return; |
1059 } | 1062 } |
1060 | 1063 |
1061 bool restart_required = false; | 1064 bool restart_required = false; |
1062 restart_required |= OnClientDomainPolicyUpdate(policies.get()); | 1065 restart_required |= OnClientDomainPolicyUpdate(policies.get()); |
1063 restart_required |= OnHostDomainPolicyUpdate(policies.get()); | 1066 restart_required |= OnHostDomainPolicyUpdate(policies.get()); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 #endif // defined(USE_GCD) | 1387 #endif // defined(USE_GCD) |
1385 DCHECK(!heartbeat_sender_); | 1388 DCHECK(!heartbeat_sender_); |
1386 | 1389 |
1387 // Create SignalStrategy. | 1390 // Create SignalStrategy. |
1388 XmppSignalStrategy* xmpp_signal_strategy = new XmppSignalStrategy( | 1391 XmppSignalStrategy* xmpp_signal_strategy = new XmppSignalStrategy( |
1389 net::ClientSocketFactory::GetDefaultFactory(), | 1392 net::ClientSocketFactory::GetDefaultFactory(), |
1390 context_->url_request_context_getter(), xmpp_server_config_); | 1393 context_->url_request_context_getter(), xmpp_server_config_); |
1391 signal_strategy_.reset(xmpp_signal_strategy); | 1394 signal_strategy_.reset(xmpp_signal_strategy); |
1392 | 1395 |
1393 // Create SignalingConnector. | 1396 // Create SignalingConnector. |
1394 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(new DnsBlackholeChecker( | 1397 std::unique_ptr<DnsBlackholeChecker> dns_blackhole_checker( |
1395 context_->url_request_context_getter(), talkgadget_prefix_)); | 1398 new DnsBlackholeChecker(context_->url_request_context_getter(), |
1396 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( | 1399 talkgadget_prefix_)); |
| 1400 std::unique_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( |
1397 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, | 1401 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, |
1398 oauth_refresh_token_, | 1402 oauth_refresh_token_, |
1399 use_service_account_)); | 1403 use_service_account_)); |
1400 oauth_token_getter_.reset( | 1404 oauth_token_getter_.reset( |
1401 new OAuthTokenGetterImpl(std::move(oauth_credentials), | 1405 new OAuthTokenGetterImpl(std::move(oauth_credentials), |
1402 context_->url_request_context_getter(), false)); | 1406 context_->url_request_context_getter(), false)); |
1403 signaling_connector_.reset(new SignalingConnector( | 1407 signaling_connector_.reset(new SignalingConnector( |
1404 xmpp_signal_strategy, std::move(dns_blackhole_checker), | 1408 xmpp_signal_strategy, std::move(dns_blackhole_checker), |
1405 oauth_token_getter_.get(), | 1409 oauth_token_getter_.get(), |
1406 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); | 1410 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
1407 | 1411 |
1408 #if defined(USE_GCD) | 1412 #if defined(USE_GCD) |
1409 // Create objects to manage GCD state. | 1413 // Create objects to manage GCD state. |
1410 ServiceUrls* service_urls = ServiceUrls::GetInstance(); | 1414 ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
1411 scoped_ptr<GcdRestClient> gcd_rest_client(new GcdRestClient( | 1415 std::unique_ptr<GcdRestClient> gcd_rest_client(new GcdRestClient( |
1412 service_urls->gcd_base_url(), host_id_, | 1416 service_urls->gcd_base_url(), host_id_, |
1413 context_->url_request_context_getter(), oauth_token_getter_.get())); | 1417 context_->url_request_context_getter(), oauth_token_getter_.get())); |
1414 gcd_state_updater_.reset(new GcdStateUpdater( | 1418 gcd_state_updater_.reset(new GcdStateUpdater( |
1415 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), | 1419 base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), |
1416 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), | 1420 base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), |
1417 signal_strategy_.get(), std::move(gcd_rest_client))); | 1421 signal_strategy_.get(), std::move(gcd_rest_client))); |
1418 PushNotificationSubscriber::Subscription sub; | 1422 PushNotificationSubscriber::Subscription sub; |
1419 sub.channel = "cloud_devices"; | 1423 sub.channel = "cloud_devices"; |
1420 PushNotificationSubscriber::SubscriptionList subs; | 1424 PushNotificationSubscriber::SubscriptionList subs; |
1421 subs.push_back(sub); | 1425 subs.push_back(sub); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 // For legacy reasons we have to restrict the port range to a set of default | 1472 // For legacy reasons we have to restrict the port range to a set of default |
1469 // values when nat traversal is disabled, even if the port range was not | 1473 // values when nat traversal is disabled, even if the port range was not |
1470 // set in policy. | 1474 // set in policy. |
1471 network_settings.port_range.min_port = NetworkSettings::kDefaultMinPort; | 1475 network_settings.port_range.min_port = NetworkSettings::kDefaultMinPort; |
1472 network_settings.port_range.max_port = NetworkSettings::kDefaultMaxPort; | 1476 network_settings.port_range.max_port = NetworkSettings::kDefaultMaxPort; |
1473 } | 1477 } |
1474 | 1478 |
1475 scoped_refptr<protocol::TransportContext> transport_context = | 1479 scoped_refptr<protocol::TransportContext> transport_context = |
1476 new protocol::TransportContext( | 1480 new protocol::TransportContext( |
1477 signal_strategy_.get(), | 1481 signal_strategy_.get(), |
1478 make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()), | 1482 base::WrapUnique(new protocol::ChromiumPortAllocatorFactory()), |
1479 make_scoped_ptr(new ChromiumUrlRequestFactory( | 1483 base::WrapUnique(new ChromiumUrlRequestFactory( |
1480 context_->url_request_context_getter())), | 1484 context_->url_request_context_getter())), |
1481 network_settings, protocol::TransportRole::SERVER); | 1485 network_settings, protocol::TransportRole::SERVER); |
1482 transport_context->set_ice_config_url( | 1486 transport_context->set_ice_config_url( |
1483 ServiceUrls::GetInstance()->ice_config_url()); | 1487 ServiceUrls::GetInstance()->ice_config_url()); |
1484 | 1488 |
1485 scoped_ptr<protocol::SessionManager> session_manager( | 1489 std::unique_ptr<protocol::SessionManager> session_manager( |
1486 new protocol::JingleSessionManager(signal_strategy_.get())); | 1490 new protocol::JingleSessionManager(signal_strategy_.get())); |
1487 | 1491 |
1488 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = | 1492 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config = |
1489 protocol::CandidateSessionConfig::CreateDefault(); | 1493 protocol::CandidateSessionConfig::CreateDefault(); |
1490 if (!desktop_environment_factory_->SupportsAudioCapture()) | 1494 if (!desktop_environment_factory_->SupportsAudioCapture()) |
1491 protocol_config->DisableAudioChannel(); | 1495 protocol_config->DisableAudioChannel(); |
1492 if (enable_vp9_) | 1496 if (enable_vp9_) |
1493 protocol_config->set_vp9_experiment_enabled(true); | 1497 protocol_config->set_vp9_experiment_enabled(true); |
1494 protocol_config->set_webrtc_supported(true); | 1498 protocol_config->set_webrtc_supported(true); |
1495 session_manager->set_protocol_config(std::move(protocol_config)); | 1499 session_manager->set_protocol_config(std::move(protocol_config)); |
1496 | 1500 |
1497 host_.reset(new ChromotingHost(desktop_environment_factory_.get(), | 1501 host_.reset(new ChromotingHost(desktop_environment_factory_.get(), |
1498 std::move(session_manager), transport_context, | 1502 std::move(session_manager), transport_context, |
1499 context_->audio_task_runner(), | 1503 context_->audio_task_runner(), |
1500 context_->video_encode_task_runner())); | 1504 context_->video_encode_task_runner())); |
1501 | 1505 |
1502 if (gnubby_auth_policy_enabled_ && gnubby_extension_supported_) { | 1506 if (gnubby_auth_policy_enabled_ && gnubby_extension_supported_) { |
1503 host_->AddExtension(make_scoped_ptr(new GnubbyExtension())); | 1507 host_->AddExtension(base::WrapUnique(new GnubbyExtension())); |
1504 } | 1508 } |
1505 | 1509 |
1506 // TODO(simonmorris): Get the maximum session duration from a policy. | 1510 // TODO(simonmorris): Get the maximum session duration from a policy. |
1507 #if defined(OS_LINUX) | 1511 #if defined(OS_LINUX) |
1508 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 1512 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
1509 #endif | 1513 #endif |
1510 | 1514 |
1511 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 1515 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
1512 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); | 1516 this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
1513 | 1517 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 // network thread. base::GetLinuxDistro() caches the result. | 1676 // network thread. base::GetLinuxDistro() caches the result. |
1673 base::GetLinuxDistro(); | 1677 base::GetLinuxDistro(); |
1674 #endif | 1678 #endif |
1675 | 1679 |
1676 // Enable support for SSL server sockets, which must be done while still | 1680 // Enable support for SSL server sockets, which must be done while still |
1677 // single-threaded. | 1681 // single-threaded. |
1678 net::EnableSSLServerSockets(); | 1682 net::EnableSSLServerSockets(); |
1679 | 1683 |
1680 // Create the main message loop and start helper threads. | 1684 // Create the main message loop and start helper threads. |
1681 base::MessageLoopForUI message_loop; | 1685 base::MessageLoopForUI message_loop; |
1682 scoped_ptr<ChromotingHostContext> context = ChromotingHostContext::Create( | 1686 std::unique_ptr<ChromotingHostContext> context = |
1683 new AutoThreadTaskRunner(message_loop.task_runner(), | 1687 ChromotingHostContext::Create( |
1684 base::MessageLoop::QuitWhenIdleClosure())); | 1688 new AutoThreadTaskRunner(message_loop.task_runner(), |
| 1689 base::MessageLoop::QuitWhenIdleClosure())); |
1685 if (!context) | 1690 if (!context) |
1686 return kInitializationFailed; | 1691 return kInitializationFailed; |
1687 | 1692 |
1688 // NetworkChangeNotifier must be initialized after MessageLoop. | 1693 // NetworkChangeNotifier must be initialized after MessageLoop. |
1689 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | 1694 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier( |
1690 net::NetworkChangeNotifier::Create()); | 1695 net::NetworkChangeNotifier::Create()); |
1691 | 1696 |
1692 // Create & start the HostProcess using these threads. | 1697 // Create & start the HostProcess using these threads. |
1693 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). | 1698 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). |
1694 // Remove this hack as part of the multi-process refactoring. | 1699 // Remove this hack as part of the multi-process refactoring. |
1695 int exit_code = kSuccessExitCode; | 1700 int exit_code = kSuccessExitCode; |
1696 ShutdownWatchdog shutdown_watchdog( | 1701 ShutdownWatchdog shutdown_watchdog( |
1697 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1702 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
1698 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); | 1703 new HostProcess(std::move(context), &exit_code, &shutdown_watchdog); |
1699 | 1704 |
1700 // Run the main (also UI) message loop until the host no longer needs it. | 1705 // Run the main (also UI) message loop until the host no longer needs it. |
1701 message_loop.Run(); | 1706 message_loop.Run(); |
1702 | 1707 |
1703 return exit_code; | 1708 return exit_code; |
1704 } | 1709 } |
1705 | 1710 |
1706 } // namespace remoting | 1711 } // namespace remoting |
OLD | NEW |