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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 void CreateAuthenticatorFactory(); | 226 void CreateAuthenticatorFactory(); |
227 | 227 |
228 // Tear down resources that run on the UI thread. | 228 // Tear down resources that run on the UI thread. |
229 void ShutdownOnUiThread(); | 229 void ShutdownOnUiThread(); |
230 | 230 |
231 // Applies the host config, returning true if successful. | 231 // Applies the host config, returning true if successful. |
232 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); | 232 bool ApplyConfig(scoped_ptr<JsonHostConfig> config); |
233 | 233 |
234 // Handles policy updates, by calling On*PolicyUpdate methods. | 234 // Handles policy updates, by calling On*PolicyUpdate methods. |
235 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 235 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
236 void OnPolicyError(); | |
237 void ApplyHostDomainPolicy(); | 236 void ApplyHostDomainPolicy(); |
238 void ApplyUsernamePolicy(); | 237 void ApplyUsernamePolicy(); |
239 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); | 238 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); |
240 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 239 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
241 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 240 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
242 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 241 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
243 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 242 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
244 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 243 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
245 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 244 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
246 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 245 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 521 } |
523 | 522 |
524 if (state_ == HOST_INITIALIZING) { | 523 if (state_ == HOST_INITIALIZING) { |
525 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is | 524 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is |
526 // already loaded so PolicyWatcher has to be started here. Separate policy | 525 // already loaded so PolicyWatcher has to be started here. Separate policy |
527 // loading from policy verifications and move |policy_watcher_| | 526 // loading from policy verifications and move |policy_watcher_| |
528 // initialization to StartOnNetworkThread(). | 527 // initialization to StartOnNetworkThread(). |
529 policy_watcher_ = policy_hack::PolicyWatcher::Create( | 528 policy_watcher_ = policy_hack::PolicyWatcher::Create( |
530 nullptr, context_->network_task_runner()); | 529 nullptr, context_->network_task_runner()); |
531 policy_watcher_->StartWatching( | 530 policy_watcher_->StartWatching( |
532 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)), | 531 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
533 base::Bind(&HostProcess::OnPolicyError, base::Unretained(this))); | |
534 } else { | 532 } else { |
535 // Reapply policies that could be affected by a new config. | 533 // Reapply policies that could be affected by a new config. |
536 ApplyHostDomainPolicy(); | 534 ApplyHostDomainPolicy(); |
537 ApplyUsernamePolicy(); | 535 ApplyUsernamePolicy(); |
538 | 536 |
539 if (state_ == HOST_STARTED) { | 537 if (state_ == HOST_STARTED) { |
540 // TODO(sergeyu): Here we assume that PIN is the only part of the config | 538 // TODO(sergeyu): Here we assume that PIN is the only part of the config |
541 // that may change while the service is running. Change ApplyConfig() to | 539 // that may change while the service is running. Change ApplyConfig() to |
542 // detect other changes in the config and restart host if necessary here. | 540 // detect other changes in the config and restart host if necessary here. |
543 CreateAuthenticatorFactory(); | 541 CreateAuthenticatorFactory(); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 restart_required |= OnPairingPolicyUpdate(policies.get()); | 926 restart_required |= OnPairingPolicyUpdate(policies.get()); |
929 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); | 927 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); |
930 | 928 |
931 if (state_ == HOST_INITIALIZING) { | 929 if (state_ == HOST_INITIALIZING) { |
932 StartHost(); | 930 StartHost(); |
933 } else if (state_ == HOST_STARTED && restart_required) { | 931 } else if (state_ == HOST_STARTED && restart_required) { |
934 RestartHost(); | 932 RestartHost(); |
935 } | 933 } |
936 } | 934 } |
937 | 935 |
938 void HostProcess::OnPolicyError() { | |
939 context_->network_task_runner()->PostTask( | |
940 FROM_HERE, | |
941 base::Bind( | |
942 &HostProcess::ShutdownHost, | |
943 this, | |
944 kInvalidHostConfigurationExitCode)); | |
945 } | |
946 | |
947 void HostProcess::ApplyHostDomainPolicy() { | 936 void HostProcess::ApplyHostDomainPolicy() { |
948 HOST_LOG << "Policy sets host domain: " << host_domain_; | 937 HOST_LOG << "Policy sets host domain: " << host_domain_; |
949 | 938 |
950 // If the user does not have a Google email, their client JID will not be | 939 // If the user does not have a Google email, their client JID will not be |
951 // based on their email. In that case, the username/host domain policies would | 940 // based on their email. In that case, the username/host domain policies would |
952 // be meaningless, since there is no way to check that the JID attempting to | 941 // be meaningless, since there is no way to check that the JID attempting to |
953 // connect actually corresponds to the owner email in question. | 942 // connect actually corresponds to the owner email in question. |
954 if (host_owner_ != host_owner_email_) { | 943 if (host_owner_ != host_owner_email_) { |
955 LOG(ERROR) << "The username and host domain policies cannot be enabled for " | 944 LOG(ERROR) << "The username and host domain policies cannot be enabled for " |
956 << "accounts with a non-Google email."; | 945 << "accounts with a non-Google email."; |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 int exit_code = kSuccessExitCode; | 1476 int exit_code = kSuccessExitCode; |
1488 new HostProcess(context.Pass(), &exit_code); | 1477 new HostProcess(context.Pass(), &exit_code); |
1489 | 1478 |
1490 // Run the main (also UI) message loop until the host no longer needs it. | 1479 // Run the main (also UI) message loop until the host no longer needs it. |
1491 message_loop.Run(); | 1480 message_loop.Run(); |
1492 | 1481 |
1493 return exit_code; | 1482 return exit_code; |
1494 } | 1483 } |
1495 | 1484 |
1496 } // namespace remoting | 1485 } // namespace remoting |
OLD | NEW |