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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/alias.h" | 13 #include "base/debug/alias.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "crypto/nss_util.h" | 24 #include "crypto/nss_util.h" |
25 #include "ipc/ipc_channel.h" | 25 #include "ipc/ipc_channel.h" |
26 #include "ipc/ipc_channel_proxy.h" | 26 #include "ipc/ipc_channel_proxy.h" |
27 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
28 #include "media/base/media.h" | 28 #include "media/base/media.h" |
29 #include "net/base/network_change_notifier.h" | |
29 #include "net/socket/client_socket_factory.h" | 30 #include "net/socket/client_socket_factory.h" |
30 #include "net/socket/ssl_server_socket.h" | 31 #include "net/socket/ssl_server_socket.h" |
31 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
32 #include "policy/policy_constants.h" | 33 #include "policy/policy_constants.h" |
33 #include "remoting/base/auto_thread_task_runner.h" | 34 #include "remoting/base/auto_thread_task_runner.h" |
34 #include "remoting/base/breakpad.h" | 35 #include "remoting/base/breakpad.h" |
35 #include "remoting/base/constants.h" | 36 #include "remoting/base/constants.h" |
36 #include "remoting/base/logging.h" | 37 #include "remoting/base/logging.h" |
37 #include "remoting/base/rsa_key_pair.h" | 38 #include "remoting/base/rsa_key_pair.h" |
38 #include "remoting/base/service_urls.h" | 39 #include "remoting/base/service_urls.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 253 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
253 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 254 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
254 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 255 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
255 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 256 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
256 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 257 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
257 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 258 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
258 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 259 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
259 | 260 |
260 scoped_ptr<HostSignalingManager> CreateHostSignalingManager(); | 261 scoped_ptr<HostSignalingManager> CreateHostSignalingManager(); |
261 | 262 |
263 void StartHostIfReady(); | |
262 void StartHost(); | 264 void StartHost(); |
263 | 265 |
264 // Overrides for HostSignalingManager::Listener interface. | 266 // Overrides for HostSignalingManager::Listener interface. |
265 void OnHeartbeatSuccessful() override; | 267 void OnHeartbeatSuccessful() override; |
266 void OnUnknownHostIdError() override; | 268 void OnUnknownHostIdError() override; |
267 void OnAuthFailed() override; | 269 void OnAuthFailed() override; |
268 | 270 |
269 void RestartHost(); | 271 void RestartHost(); |
270 | 272 |
271 // Stops the host and shuts down the process with the specified |exit_code|. | 273 // Stops the host and shuts down the process with the specified |exit_code|. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 scoped_refptr<RsaKeyPair> key_pair_; | 318 scoped_refptr<RsaKeyPair> key_pair_; |
317 std::string oauth_refresh_token_; | 319 std::string oauth_refresh_token_; |
318 std::string serialized_config_; | 320 std::string serialized_config_; |
319 std::string host_owner_; | 321 std::string host_owner_; |
320 std::string host_owner_email_; | 322 std::string host_owner_email_; |
321 bool use_service_account_; | 323 bool use_service_account_; |
322 bool enable_vp9_; | 324 bool enable_vp9_; |
323 int64_t frame_recorder_buffer_size_; | 325 int64_t frame_recorder_buffer_size_; |
324 | 326 |
325 scoped_ptr<PolicyWatcher> policy_watcher_; | 327 scoped_ptr<PolicyWatcher> policy_watcher_; |
328 bool policies_loaded_; | |
326 std::string host_domain_; | 329 std::string host_domain_; |
327 bool host_username_match_required_; | 330 bool host_username_match_required_; |
328 bool allow_nat_traversal_; | 331 bool allow_nat_traversal_; |
329 bool allow_relay_; | 332 bool allow_relay_; |
330 uint16 min_udp_port_; | 333 uint16 min_udp_port_; |
331 uint16 max_udp_port_; | 334 uint16 max_udp_port_; |
332 std::string talkgadget_prefix_; | 335 std::string talkgadget_prefix_; |
333 bool allow_pairing_; | 336 bool allow_pairing_; |
334 | 337 |
335 bool curtain_required_; | 338 bool curtain_required_; |
336 ThirdPartyAuthConfig third_party_auth_config_; | 339 ThirdPartyAuthConfig third_party_auth_config_; |
337 bool enable_gnubby_auth_; | 340 bool enable_gnubby_auth_; |
338 | 341 |
339 // Boolean to change flow, where ncessary, if we're | 342 // Boolean to change flow, where necessary, if we're |
340 // capturing a window instead of the entire desktop. | 343 // capturing a window instead of the entire desktop. |
341 bool enable_window_capture_; | 344 bool enable_window_capture_; |
342 | 345 |
343 // Used to specify which window to stream, if enabled. | 346 // Used to specify which window to stream, if enabled. |
344 webrtc::WindowId window_id_; | 347 webrtc::WindowId window_id_; |
345 | 348 |
346 // Used to send heartbeats while running, and the reason for going offline | 349 // Used to send heartbeats while running, and the reason for going offline |
347 // when shutting down. | 350 // when shutting down. |
348 scoped_ptr<HostSignalingManager> host_signaling_manager_; | 351 scoped_ptr<HostSignalingManager> host_signaling_manager_; |
349 | 352 |
(...skipping 21 matching lines...) Expand all Loading... | |
371 }; | 374 }; |
372 | 375 |
373 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 376 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
374 int* exit_code_out, | 377 int* exit_code_out, |
375 ShutdownWatchdog* shutdown_watchdog) | 378 ShutdownWatchdog* shutdown_watchdog) |
376 : context_(context.Pass()), | 379 : context_(context.Pass()), |
377 state_(HOST_INITIALIZING), | 380 state_(HOST_INITIALIZING), |
378 use_service_account_(false), | 381 use_service_account_(false), |
379 enable_vp9_(false), | 382 enable_vp9_(false), |
380 frame_recorder_buffer_size_(0), | 383 frame_recorder_buffer_size_(0), |
384 policies_loaded_(false), | |
381 host_username_match_required_(false), | 385 host_username_match_required_(false), |
382 allow_nat_traversal_(true), | 386 allow_nat_traversal_(true), |
383 allow_relay_(true), | 387 allow_relay_(true), |
384 min_udp_port_(0), | 388 min_udp_port_(0), |
385 max_udp_port_(0), | 389 max_udp_port_(0), |
386 allow_pairing_(true), | 390 allow_pairing_(true), |
387 curtain_required_(false), | 391 curtain_required_(false), |
388 enable_gnubby_auth_(false), | 392 enable_gnubby_auth_(false), |
389 enable_window_capture_(false), | 393 enable_window_capture_(false), |
390 window_id_(0), | 394 window_id_(0), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 return; | 545 return; |
542 } | 546 } |
543 | 547 |
544 if (!ApplyConfig(*config)) { | 548 if (!ApplyConfig(*config)) { |
545 LOG(ERROR) << "Failed to apply the configuration."; | 549 LOG(ERROR) << "Failed to apply the configuration."; |
546 ShutdownHost(kInvalidHostConfigurationExitCode); | 550 ShutdownHost(kInvalidHostConfigurationExitCode); |
547 return; | 551 return; |
548 } | 552 } |
549 | 553 |
550 if (state_ == HOST_INITIALIZING) { | 554 if (state_ == HOST_INITIALIZING) { |
551 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is | 555 StartHostIfReady(); |
552 // already loaded so PolicyWatcher has to be started here. Separate policy | 556 } else if (state_ == HOST_STARTED) { |
553 // loading from policy verifications and move |policy_watcher_| | 557 DCHECK(policies_loaded_); |
554 // initialization to StartOnNetworkThread(). | 558 |
555 policy_watcher_ = | |
556 PolicyWatcher::Create(nullptr, context_->file_task_runner()); | |
557 policy_watcher_->StartWatching( | |
558 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)), | |
559 base::Bind(&HostProcess::OnPolicyError, base::Unretained(this))); | |
560 } else { | |
561 // Reapply policies that could be affected by a new config. | 559 // Reapply policies that could be affected by a new config. |
562 ApplyHostDomainPolicy(); | 560 ApplyHostDomainPolicy(); |
563 ApplyUsernamePolicy(); | 561 ApplyUsernamePolicy(); |
564 | 562 |
565 if (state_ == HOST_STARTED) { | 563 // TODO(sergeyu): Here we assume that PIN is the only part of the config |
566 // TODO(sergeyu): Here we assume that PIN is the only part of the config | 564 // that may change while the service is running. Change ApplyConfig() to |
567 // that may change while the service is running. Change ApplyConfig() to | 565 // detect other changes in the config and restart host if necessary here. |
568 // detect other changes in the config and restart host if necessary here. | 566 CreateAuthenticatorFactory(); |
569 CreateAuthenticatorFactory(); | |
570 } | |
571 } | 567 } |
572 } | 568 } |
573 | 569 |
574 void HostProcess::OnConfigWatcherError() { | 570 void HostProcess::OnConfigWatcherError() { |
575 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 571 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
576 ShutdownHost(kInvalidHostConfigurationExitCode); | 572 ShutdownHost(kInvalidHostConfigurationExitCode); |
577 } | 573 } |
578 | 574 |
579 void HostProcess::StartOnNetworkThread() { | 575 void HostProcess::StartOnNetworkThread() { |
580 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 576 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 713 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
718 | 714 |
719 if (!InitWithCommandLine(base::CommandLine::ForCurrentProcess())) { | 715 if (!InitWithCommandLine(base::CommandLine::ForCurrentProcess())) { |
720 // Shutdown the host if the command line is invalid. | 716 // Shutdown the host if the command line is invalid. |
721 context_->network_task_runner()->PostTask( | 717 context_->network_task_runner()->PostTask( |
722 FROM_HERE, base::Bind(&HostProcess::ShutdownHost, this, | 718 FROM_HERE, base::Bind(&HostProcess::ShutdownHost, this, |
723 kUsageExitCode)); | 719 kUsageExitCode)); |
724 return; | 720 return; |
725 } | 721 } |
726 | 722 |
723 policy_watcher_ = | |
724 PolicyWatcher::Create(nullptr, context_->file_task_runner()); | |
725 policy_watcher_->StartWatching( | |
726 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)), | |
727 base::Bind(&HostProcess::OnPolicyError, base::Unretained(this))); | |
728 | |
727 #if defined(OS_LINUX) | 729 #if defined(OS_LINUX) |
728 // If an audio pipe is specific on the command-line then initialize | 730 // If an audio pipe is specific on the command-line then initialize |
729 // AudioCapturerLinux to capture from it. | 731 // AudioCapturerLinux to capture from it. |
730 base::FilePath audio_pipe_name = base::CommandLine::ForCurrentProcess()-> | 732 base::FilePath audio_pipe_name = base::CommandLine::ForCurrentProcess()-> |
731 GetSwitchValuePath(kAudioPipeSwitchName); | 733 GetSwitchValuePath(kAudioPipeSwitchName); |
732 if (!audio_pipe_name.empty()) { | 734 if (!audio_pipe_name.empty()) { |
733 remoting::AudioCapturerLinux::InitializePipeReader( | 735 remoting::AudioCapturerLinux::InitializePipeReader( |
734 context_->audio_task_runner(), audio_pipe_name); | 736 context_->audio_task_runner(), audio_pipe_name); |
735 } | 737 } |
736 | 738 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 base::Bind(&HostProcess::StartOnNetworkThread, this)); | 779 base::Bind(&HostProcess::StartOnNetworkThread, this)); |
778 } | 780 } |
779 | 781 |
780 void HostProcess::ShutdownOnUiThread() { | 782 void HostProcess::ShutdownOnUiThread() { |
781 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 783 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
782 | 784 |
783 // Tear down resources that need to be torn down on the UI thread. | 785 // Tear down resources that need to be torn down on the UI thread. |
784 daemon_channel_.reset(); | 786 daemon_channel_.reset(); |
785 desktop_environment_factory_.reset(); | 787 desktop_environment_factory_.reset(); |
786 | 788 |
789 policy_watcher_.reset(); | |
790 | |
787 // It is now safe for the HostProcess to be deleted. | 791 // It is now safe for the HostProcess to be deleted. |
788 self_ = nullptr; | 792 self_ = nullptr; |
789 | 793 |
790 #if defined(OS_LINUX) | 794 #if defined(OS_LINUX) |
791 // Cause the global AudioPipeReader to be freed, otherwise the audio | 795 // Cause the global AudioPipeReader to be freed, otherwise the audio |
792 // thread will remain in-use and prevent the process from exiting. | 796 // thread will remain in-use and prevent the process from exiting. |
793 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 797 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
794 // See crbug.com/161373 and crbug.com/104544. | 798 // See crbug.com/161373 and crbug.com/104544. |
795 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); | 799 AudioCapturerLinux::InitializePipeReader(nullptr, base::FilePath()); |
796 #endif | 800 #endif |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
949 &frame_recorder_buffer_kb); | 953 &frame_recorder_buffer_kb); |
950 } | 954 } |
951 if (frame_recorder_buffer_kb > 0) { | 955 if (frame_recorder_buffer_kb > 0) { |
952 frame_recorder_buffer_size_ = 1024LL * frame_recorder_buffer_kb; | 956 frame_recorder_buffer_size_ = 1024LL * frame_recorder_buffer_kb; |
953 } | 957 } |
954 | 958 |
955 return true; | 959 return true; |
956 } | 960 } |
957 | 961 |
958 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 962 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
959 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 963 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
964 context_->network_task_runner()->PostTask( | |
965 FROM_HERE, base::Bind(&HostProcess::OnPolicyUpdate, this, | |
966 base::Passed(&policies))); | |
967 return; | |
968 } | |
960 | 969 |
961 bool restart_required = false; | 970 bool restart_required = false; |
962 restart_required |= OnHostDomainPolicyUpdate(policies.get()); | 971 restart_required |= OnHostDomainPolicyUpdate(policies.get()); |
963 restart_required |= OnCurtainPolicyUpdate(policies.get()); | 972 restart_required |= OnCurtainPolicyUpdate(policies.get()); |
964 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate. | 973 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate. |
965 restart_required |= OnUsernamePolicyUpdate(policies.get()); | 974 restart_required |= OnUsernamePolicyUpdate(policies.get()); |
966 restart_required |= OnNatPolicyUpdate(policies.get()); | 975 restart_required |= OnNatPolicyUpdate(policies.get()); |
967 restart_required |= OnRelayPolicyUpdate(policies.get()); | 976 restart_required |= OnRelayPolicyUpdate(policies.get()); |
968 restart_required |= OnUdpPortPolicyUpdate(policies.get()); | 977 restart_required |= OnUdpPortPolicyUpdate(policies.get()); |
969 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get()); | 978 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get()); |
970 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get()); | 979 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get()); |
971 restart_required |= OnPairingPolicyUpdate(policies.get()); | 980 restart_required |= OnPairingPolicyUpdate(policies.get()); |
972 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); | 981 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); |
973 | 982 |
983 policies_loaded_ = true; | |
984 | |
974 if (state_ == HOST_INITIALIZING) { | 985 if (state_ == HOST_INITIALIZING) { |
975 StartHost(); | 986 StartHostIfReady(); |
976 } else if (state_ == HOST_STARTED && restart_required) { | 987 } else if (state_ == HOST_STARTED) { |
977 RestartHost(); | 988 if (restart_required) |
989 RestartHost(); | |
978 } | 990 } |
979 } | 991 } |
980 | 992 |
981 void HostProcess::OnPolicyError() { | 993 void HostProcess::OnPolicyError() { |
982 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 994 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
995 context_->network_task_runner()->PostTask( | |
996 FROM_HERE, base::Bind(&HostProcess::OnPolicyError, this)); | |
997 return; | |
998 } | |
983 | 999 |
984 ShutdownHost(kInvalidHostConfigurationExitCode); | 1000 ShutdownHost(kInvalidHostConfigurationExitCode); |
985 } | 1001 } |
986 | 1002 |
987 void HostProcess::ApplyHostDomainPolicy() { | 1003 void HostProcess::ApplyHostDomainPolicy() { |
1004 if (state_ != HOST_STARTED) | |
1005 return; | |
1006 | |
988 HOST_LOG << "Policy sets host domain: " << host_domain_; | 1007 HOST_LOG << "Policy sets host domain: " << host_domain_; |
989 | 1008 |
990 if (!host_domain_.empty()) { | 1009 if (!host_domain_.empty()) { |
991 // If the user does not have a Google email, their client JID will not be | 1010 // If the user does not have a Google email, their client JID will not be |
992 // based on their email. In that case, the username/host domain policies | 1011 // based on their email. In that case, the username/host domain policies |
993 // would be meaningless, since there is no way to check that the JID | 1012 // would be meaningless, since there is no way to check that the JID |
994 // trying to connect actually corresponds to the owner email in question. | 1013 // trying to connect actually corresponds to the owner email in question. |
995 if (host_owner_ != host_owner_email_) { | 1014 if (host_owner_ != host_owner_email_) { |
996 LOG(ERROR) << "The username and host domain policies cannot be enabled " | 1015 LOG(ERROR) << "The username and host domain policies cannot be enabled " |
997 << "for accounts with a non-Google email."; | 1016 << "for accounts with a non-Google email."; |
(...skipping 14 matching lines...) Expand all Loading... | |
1012 if (!policies->GetString(policy::key::kRemoteAccessHostDomain, | 1031 if (!policies->GetString(policy::key::kRemoteAccessHostDomain, |
1013 &host_domain_)) { | 1032 &host_domain_)) { |
1014 return false; | 1033 return false; |
1015 } | 1034 } |
1016 | 1035 |
1017 ApplyHostDomainPolicy(); | 1036 ApplyHostDomainPolicy(); |
1018 return false; | 1037 return false; |
1019 } | 1038 } |
1020 | 1039 |
1021 void HostProcess::ApplyUsernamePolicy() { | 1040 void HostProcess::ApplyUsernamePolicy() { |
1041 if (state_ != HOST_STARTED) | |
1042 return; | |
1043 | |
1022 if (host_username_match_required_) { | 1044 if (host_username_match_required_) { |
1023 HOST_LOG << "Policy requires host username match."; | 1045 HOST_LOG << "Policy requires host username match."; |
1024 | 1046 |
1025 // See comment in ApplyHostDomainPolicy. | 1047 // See comment in ApplyHostDomainPolicy. |
1026 if (host_owner_ != host_owner_email_) { | 1048 if (host_owner_ != host_owner_email_) { |
1027 LOG(ERROR) << "The username and host domain policies cannot be enabled " | 1049 LOG(ERROR) << "The username and host domain policies cannot be enabled " |
1028 << "for accounts with a non-Google email."; | 1050 << "for accounts with a non-Google email."; |
1029 ShutdownHost(kUsernameMismatchExitCode); | 1051 ShutdownHost(kUsernameMismatchExitCode); |
1030 } | 1052 } |
1031 | 1053 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 oauth_refresh_token_, | 1299 oauth_refresh_token_, |
1278 use_service_account_)); | 1300 use_service_account_)); |
1279 | 1301 |
1280 return HostSignalingManager::Create(this, context_->network_task_runner(), | 1302 return HostSignalingManager::Create(this, context_->network_task_runner(), |
1281 context_->url_request_context_getter(), | 1303 context_->url_request_context_getter(), |
1282 xmpp_server_config_, talkgadget_prefix_, | 1304 xmpp_server_config_, talkgadget_prefix_, |
1283 host_id_, key_pair_, directory_bot_jid_, | 1305 host_id_, key_pair_, directory_bot_jid_, |
1284 oauth_credentials.Pass()); | 1306 oauth_credentials.Pass()); |
1285 } | 1307 } |
1286 | 1308 |
1309 void HostProcess::StartHostIfReady() { | |
1310 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
1311 DCHECK_EQ(state_, HOST_INITIALIZING); | |
1312 | |
1313 // Start the host if both the config and the policies are loaded. | |
1314 if (!serialized_config_.empty() && policies_loaded_) | |
1315 StartHost(); | |
1316 } | |
1317 | |
1287 void HostProcess::StartHost() { | 1318 void HostProcess::StartHost() { |
1288 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1319 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1289 DCHECK(!host_); | 1320 DCHECK(!host_); |
1290 DCHECK(!host_signaling_manager_); | 1321 DCHECK(!host_signaling_manager_); |
1291 | 1322 |
1292 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1323 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
1293 state_ == HOST_STOPPED) | 1324 state_ == HOST_STOPPED) |
1294 << "state_ = " << state_; | 1325 << "state_ = " << state_; |
1295 state_ = HOST_STARTED; | 1326 state_ = HOST_STARTED; |
1296 | 1327 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1361 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); | 1392 new IpcHostEventLogger(host_->AsWeakPtr(), daemon_channel_.get())); |
1362 #else // !defined(REMOTING_MULTI_PROCESS) | 1393 #else // !defined(REMOTING_MULTI_PROCESS) |
1363 host_event_logger_ = | 1394 host_event_logger_ = |
1364 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); | 1395 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); |
1365 #endif // !defined(REMOTING_MULTI_PROCESS) | 1396 #endif // !defined(REMOTING_MULTI_PROCESS) |
1366 | 1397 |
1367 host_->SetEnableCurtaining(curtain_required_); | 1398 host_->SetEnableCurtaining(curtain_required_); |
1368 host_->Start(host_owner_email_); | 1399 host_->Start(host_owner_email_); |
1369 | 1400 |
1370 CreateAuthenticatorFactory(); | 1401 CreateAuthenticatorFactory(); |
1402 | |
1403 ApplyHostDomainPolicy(); | |
1404 ApplyUsernamePolicy(); | |
1371 } | 1405 } |
1372 | 1406 |
1373 void HostProcess::OnAuthFailed() { | 1407 void HostProcess::OnAuthFailed() { |
1374 ShutdownHost(kInvalidOauthCredentialsExitCode); | 1408 ShutdownHost(kInvalidOauthCredentialsExitCode); |
1375 } | 1409 } |
1376 | 1410 |
1377 void HostProcess::RestartHost() { | 1411 void HostProcess::RestartHost() { |
1378 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1412 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
1379 DCHECK_EQ(state_, HOST_STARTED); | 1413 DCHECK_EQ(state_, HOST_STARTED); |
1380 | 1414 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1432 | 1466 |
1433 if (state_ == HOST_STOPPING_TO_RESTART) { | 1467 if (state_ == HOST_STOPPING_TO_RESTART) { |
1434 StartHost(); | 1468 StartHost(); |
1435 } else if (state_ == HOST_STOPPING) { | 1469 } else if (state_ == HOST_STOPPING) { |
1436 state_ = HOST_STOPPED; | 1470 state_ = HOST_STOPPED; |
1437 | 1471 |
1438 shutdown_watchdog_->SetExitCode(*exit_code_out_); | 1472 shutdown_watchdog_->SetExitCode(*exit_code_out_); |
1439 shutdown_watchdog_->Arm(); | 1473 shutdown_watchdog_->Arm(); |
1440 | 1474 |
1441 config_watcher_.reset(); | 1475 config_watcher_.reset(); |
1442 policy_watcher_.reset(); | |
1443 | 1476 |
1444 // Complete the rest of shutdown on the main thread. | 1477 // Complete the rest of shutdown on the main thread. |
1445 context_->ui_task_runner()->PostTask( | 1478 context_->ui_task_runner()->PostTask( |
1446 FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this)); | 1479 FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this)); |
1447 } else { | 1480 } else { |
1448 // This method is only called in STOPPING_TO_RESTART and STOPPING states. | 1481 // This method is only called in STOPPING_TO_RESTART and STOPPING states. |
1449 NOTREACHED(); | 1482 NOTREACHED(); |
1450 } | 1483 } |
1451 } | 1484 } |
1452 | 1485 |
(...skipping 21 matching lines...) Expand all Loading... | |
1474 gtk_init(nullptr, nullptr); | 1507 gtk_init(nullptr, nullptr); |
1475 #endif | 1508 #endif |
1476 | 1509 |
1477 // Enable support for SSL server sockets, which must be done while still | 1510 // Enable support for SSL server sockets, which must be done while still |
1478 // single-threaded. | 1511 // single-threaded. |
1479 net::EnableSSLServerSockets(); | 1512 net::EnableSSLServerSockets(); |
1480 | 1513 |
1481 // Ensures runtime specific CPU features are initialized. | 1514 // Ensures runtime specific CPU features are initialized. |
1482 media::InitializeCPUSpecificMediaFeatures(); | 1515 media::InitializeCPUSpecificMediaFeatures(); |
1483 | 1516 |
1517 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | |
rmsousa
2015/01/31 01:34:34
I don't see any object registering observers for t
Sergey Ulanov
2015/01/31 01:38:39
This is a singleton that is used by code that need
| |
1518 net::NetworkChangeNotifier::Create()); | |
1519 | |
1484 // Create the main message loop and start helper threads. | 1520 // Create the main message loop and start helper threads. |
1485 base::MessageLoopForUI message_loop; | 1521 base::MessageLoopForUI message_loop; |
1486 scoped_ptr<ChromotingHostContext> context = | 1522 scoped_ptr<ChromotingHostContext> context = |
1487 ChromotingHostContext::Create(new AutoThreadTaskRunner( | 1523 ChromotingHostContext::Create(new AutoThreadTaskRunner( |
1488 message_loop.message_loop_proxy(), base::MessageLoop::QuitClosure())); | 1524 message_loop.message_loop_proxy(), base::MessageLoop::QuitClosure())); |
1489 if (!context) | 1525 if (!context) |
1490 return kInitializationFailed; | 1526 return kInitializationFailed; |
1491 | 1527 |
1528 // BasicURLRequestContext holds references to threads, so it needs to be | |
1529 // dereferences on UI threads. Store the reference to the URLRequestGetter to | |
1530 // make sure it's not destroyed on other threads. | |
1531 // TODO(sergeyu): Consider fixing it in BasicURLRequestContext. | |
1532 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | |
1533 context->url_request_context_getter(); | |
1534 | |
1492 // Create & start the HostProcess using these threads. | 1535 // Create & start the HostProcess using these threads. |
1493 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). | 1536 // TODO(wez): The HostProcess holds a reference to itself until Shutdown(). |
1494 // Remove this hack as part of the multi-process refactoring. | 1537 // Remove this hack as part of the multi-process refactoring. |
1495 int exit_code = kSuccessExitCode; | 1538 int exit_code = kSuccessExitCode; |
1496 ShutdownWatchdog shutdown_watchdog( | 1539 ShutdownWatchdog shutdown_watchdog( |
1497 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1540 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
1498 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1541 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); |
1499 | 1542 |
1500 // Run the main (also UI) message loop until the host no longer needs it. | 1543 // Run the main (also UI) message loop until the host no longer needs it. |
1501 message_loop.Run(); | 1544 message_loop.Run(); |
1502 | 1545 |
1503 return exit_code; | 1546 return exit_code; |
1504 } | 1547 } |
1505 | 1548 |
1506 } // namespace remoting | 1549 } // namespace remoting |
OLD | NEW |