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" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 void CreateAuthenticatorFactory(); | 227 void CreateAuthenticatorFactory(); |
228 | 228 |
229 // Tear down resources that run on the UI thread. | 229 // Tear down resources that run on the UI thread. |
230 void ShutdownOnUiThread(); | 230 void ShutdownOnUiThread(); |
231 | 231 |
232 // Applies the host config, returning true if successful. | 232 // Applies the host config, returning true if successful. |
233 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); | 233 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); |
234 | 234 |
235 // Handles policy updates, by calling On*PolicyUpdate methods. | 235 // Handles policy updates, by calling On*PolicyUpdate methods. |
236 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 236 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
237 void OnPolicyError(); | |
237 void ApplyHostDomainPolicy(); | 238 void ApplyHostDomainPolicy(); |
238 void ApplyUsernamePolicy(); | 239 void ApplyUsernamePolicy(); |
239 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); | 240 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); |
240 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 241 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
241 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 242 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
242 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 243 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
243 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 244 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
244 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 245 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
245 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 246 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
246 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 247 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 } | 521 } |
521 | 522 |
522 if (state_ == HOST_INITIALIZING) { | 523 if (state_ == HOST_INITIALIZING) { |
523 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is | 524 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is |
524 // already loaded so PolicyWatcher has to be started here. Separate policy | 525 // already loaded so PolicyWatcher has to be started here. Separate policy |
525 // loading from policy verifications and move |policy_watcher_| | 526 // loading from policy verifications and move |policy_watcher_| |
526 // initialization to StartOnNetworkThread(). | 527 // initialization to StartOnNetworkThread(). |
527 policy_watcher_.reset( | 528 policy_watcher_.reset( |
528 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 529 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
529 policy_watcher_->StartWatching( | 530 policy_watcher_->StartWatching( |
530 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 531 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)), |
532 base::Bind(&HostProcess::OnPolicyError, base::Unretained(this))); | |
531 } else { | 533 } else { |
532 // Reapply policies that could be affected by a new config. | 534 // Reapply policies that could be affected by a new config. |
533 ApplyHostDomainPolicy(); | 535 ApplyHostDomainPolicy(); |
534 ApplyUsernamePolicy(); | 536 ApplyUsernamePolicy(); |
535 | 537 |
536 if (state_ == HOST_STARTED) { | 538 if (state_ == HOST_STARTED) { |
537 // TODO(sergeyu): Here we assume that PIN is the only part of the config | 539 // TODO(sergeyu): Here we assume that PIN is the only part of the config |
538 // that may change while the service is running. Change ApplyConfig() to | 540 // that may change while the service is running. Change ApplyConfig() to |
539 // detect other changes in the config and restart host if necessary here. | 541 // detect other changes in the config and restart host if necessary here. |
540 CreateAuthenticatorFactory(); | 542 CreateAuthenticatorFactory(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 third_party_auth_config_, | 618 third_party_auth_config_, |
617 key_pair_, context_->url_request_context_getter())); | 619 key_pair_, context_->url_request_context_getter())); |
618 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( | 620 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithThirdPartyAuth( |
619 use_service_account_, host_owner_, local_certificate, key_pair_, | 621 use_service_account_, host_owner_, local_certificate, key_pair_, |
620 token_validator_factory.Pass()); | 622 token_validator_factory.Pass()); |
621 | 623 |
622 } else { | 624 } else { |
623 // TODO(rmsousa): If the policy is bad the host should not go online. It | 625 // TODO(rmsousa): If the policy is bad the host should not go online. It |
624 // should keep running, but not connected, until the policies are fixed. | 626 // should keep running, but not connected, until the policies are fixed. |
625 // Having it show up as online and then reject all clients is misleading. | 627 // Having it show up as online and then reject all clients is misleading. |
628 // TODO(lukasza): code review please: the new ShutdownHost call below seems | |
Lambros
2014/11/13 00:30:27
Please remove this. When requesting a code review,
Łukasz Anforowicz
2014/11/13 17:48:09
Done.
| |
629 // to match the TODO from rmsousa above (at least in spirit) | |
630 // If this makes sense, then I can add this call in the next | |
631 // check-in. | |
626 LOG(ERROR) << "One of the third-party token URLs is empty or invalid. " | 632 LOG(ERROR) << "One of the third-party token URLs is empty or invalid. " |
627 << "Host will reject all clients until policies are corrected. " | 633 << "Host will reject all clients until policies are corrected. " |
628 << "TokenUrl: " << third_party_auth_config_.token_url << ", " | 634 << "TokenUrl: " << third_party_auth_config_.token_url << ", " |
629 << "TokenValidationUrl: " | 635 << "TokenValidationUrl: " |
630 << third_party_auth_config_.token_validation_url; | 636 << third_party_auth_config_.token_validation_url; |
631 factory = protocol::Me2MeHostAuthenticatorFactory::CreateRejecting(); | 637 factory = protocol::Me2MeHostAuthenticatorFactory::CreateRejecting(); |
632 } | 638 } |
633 | 639 |
634 #if defined(OS_POSIX) | 640 #if defined(OS_POSIX) |
635 // On Linux and Mac, perform a PAM authorization step after authentication. | 641 // On Linux and Mac, perform a PAM authorization step after authentication. |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 restart_required |= OnPairingPolicyUpdate(policies.get()); | 931 restart_required |= OnPairingPolicyUpdate(policies.get()); |
926 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); | 932 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); |
927 | 933 |
928 if (state_ == HOST_INITIALIZING) { | 934 if (state_ == HOST_INITIALIZING) { |
929 StartHost(); | 935 StartHost(); |
930 } else if (state_ == HOST_STARTED && restart_required) { | 936 } else if (state_ == HOST_STARTED && restart_required) { |
931 RestartHost(); | 937 RestartHost(); |
932 } | 938 } |
933 } | 939 } |
934 | 940 |
941 void HostProcess::OnPolicyError() { | |
942 context_->network_task_runner()->PostTask( | |
943 FROM_HERE, | |
944 base::Bind( | |
Lambros
2014/11/13 00:30:27
Formatting is a bit odd - see examples elsewhere,
Łukasz Anforowicz
2014/11/13 17:48:09
Ok to +4 rather than +2. Let's discuss the other
| |
945 &HostProcess::ShutdownHost, | |
946 this, | |
947 kInvalidHostConfigurationExitCode)); | |
948 } | |
949 | |
935 void HostProcess::ApplyHostDomainPolicy() { | 950 void HostProcess::ApplyHostDomainPolicy() { |
936 HOST_LOG << "Policy sets host domain: " << host_domain_; | 951 HOST_LOG << "Policy sets host domain: " << host_domain_; |
937 | 952 |
938 // If the user does not have a Google email, their client JID will not be | 953 // If the user does not have a Google email, their client JID will not be |
939 // based on their email. In that case, the username/host domain policies would | 954 // based on their email. In that case, the username/host domain policies would |
940 // be meaningless, since there is no way to check that the JID attempting to | 955 // be meaningless, since there is no way to check that the JID attempting to |
941 // connect actually corresponds to the owner email in question. | 956 // connect actually corresponds to the owner email in question. |
942 if (host_owner_ != host_owner_email_) { | 957 if (host_owner_ != host_owner_email_) { |
943 LOG(ERROR) << "The username and host domain policies cannot be enabled for " | 958 LOG(ERROR) << "The username and host domain policies cannot be enabled for " |
944 << "accounts with a non-Google email."; | 959 << "accounts with a non-Google email."; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1474 int exit_code = kSuccessExitCode; | 1489 int exit_code = kSuccessExitCode; |
1475 new HostProcess(context.Pass(), &exit_code); | 1490 new HostProcess(context.Pass(), &exit_code); |
1476 | 1491 |
1477 // Run the main (also UI) message loop until the host no longer needs it. | 1492 // Run the main (also UI) message loop until the host no longer needs it. |
1478 message_loop.Run(); | 1493 message_loop.Run(); |
1479 | 1494 |
1480 return exit_code; | 1495 return exit_code; |
1481 } | 1496 } |
1482 | 1497 |
1483 } // namespace remoting | 1498 } // namespace remoting |
OLD | NEW |