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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 restart_required |= OnPairingPolicyUpdate(policies.get()); | 927 restart_required |= OnPairingPolicyUpdate(policies.get()); |
926 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); | 928 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); |
927 | 929 |
928 if (state_ == HOST_INITIALIZING) { | 930 if (state_ == HOST_INITIALIZING) { |
929 StartHost(); | 931 StartHost(); |
930 } else if (state_ == HOST_STARTED && restart_required) { | 932 } else if (state_ == HOST_STARTED && restart_required) { |
931 RestartHost(); | 933 RestartHost(); |
932 } | 934 } |
933 } | 935 } |
934 | 936 |
| 937 void HostProcess::OnPolicyError() { |
| 938 context_->network_task_runner()->PostTask( |
| 939 FROM_HERE, |
| 940 base::Bind( |
| 941 &HostProcess::ShutdownHost, |
| 942 this, |
| 943 kInvalidHostConfigurationExitCode)); |
| 944 } |
| 945 |
935 void HostProcess::ApplyHostDomainPolicy() { | 946 void HostProcess::ApplyHostDomainPolicy() { |
936 HOST_LOG << "Policy sets host domain: " << host_domain_; | 947 HOST_LOG << "Policy sets host domain: " << host_domain_; |
937 | 948 |
938 // If the user does not have a Google email, their client JID will not be | 949 // 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 | 950 // 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 | 951 // be meaningless, since there is no way to check that the JID attempting to |
941 // connect actually corresponds to the owner email in question. | 952 // connect actually corresponds to the owner email in question. |
942 if (host_owner_ != host_owner_email_) { | 953 if (host_owner_ != host_owner_email_) { |
943 LOG(ERROR) << "The username and host domain policies cannot be enabled for " | 954 LOG(ERROR) << "The username and host domain policies cannot be enabled for " |
944 << "accounts with a non-Google email."; | 955 << "accounts with a non-Google email."; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 int exit_code = kSuccessExitCode; | 1485 int exit_code = kSuccessExitCode; |
1475 new HostProcess(context.Pass(), &exit_code); | 1486 new HostProcess(context.Pass(), &exit_code); |
1476 | 1487 |
1477 // Run the main (also UI) message loop until the host no longer needs it. | 1488 // Run the main (also UI) message loop until the host no longer needs it. |
1478 message_loop.Run(); | 1489 message_loop.Run(); |
1479 | 1490 |
1480 return exit_code; | 1491 return exit_code; |
1481 } | 1492 } |
1482 | 1493 |
1483 } // namespace remoting | 1494 } // namespace remoting |
OLD | NEW |