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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 206 |
207 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 207 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
208 bool OnHostDomainPolicyUpdate(const std::string& host_domain); | 208 bool OnHostDomainPolicyUpdate(const std::string& host_domain); |
209 bool OnUsernamePolicyUpdate(bool curtain_required, | 209 bool OnUsernamePolicyUpdate(bool curtain_required, |
210 bool username_match_required); | 210 bool username_match_required); |
211 bool OnNatPolicyUpdate(bool nat_traversal_enabled); | 211 bool OnNatPolicyUpdate(bool nat_traversal_enabled); |
212 void OnCurtainPolicyUpdate(bool curtain_required); | 212 void OnCurtainPolicyUpdate(bool curtain_required); |
213 bool OnHostTalkGadgetPrefixPolicyUpdate(const std::string& talkgadget_prefix); | 213 bool OnHostTalkGadgetPrefixPolicyUpdate(const std::string& talkgadget_prefix); |
214 bool OnHostTokenUrlPolicyUpdate(const GURL& token_url, | 214 bool OnHostTokenUrlPolicyUpdate(const GURL& token_url, |
215 const GURL& token_validation_url); | 215 const GURL& token_validation_url); |
| 216 bool OnPairingPolicyUpdate(bool pairing_enabled); |
216 | 217 |
217 void StartHost(); | 218 void StartHost(); |
218 | 219 |
219 void OnAuthFailed(); | 220 void OnAuthFailed(); |
220 | 221 |
221 void RestartHost(); | 222 void RestartHost(); |
222 | 223 |
223 // Stops the host and shuts down the process with the specified |exit_code|. | 224 // Stops the host and shuts down the process with the specified |exit_code|. |
224 void ShutdownHost(HostExitCodes exit_code); | 225 void ShutdownHost(HostExitCodes exit_code); |
225 | 226 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 protocol::SharedSecretHash host_secret_hash_; | 260 protocol::SharedSecretHash host_secret_hash_; |
260 scoped_refptr<RsaKeyPair> key_pair_; | 261 scoped_refptr<RsaKeyPair> key_pair_; |
261 std::string oauth_refresh_token_; | 262 std::string oauth_refresh_token_; |
262 std::string serialized_config_; | 263 std::string serialized_config_; |
263 std::string xmpp_login_; | 264 std::string xmpp_login_; |
264 std::string xmpp_auth_token_; | 265 std::string xmpp_auth_token_; |
265 std::string xmpp_auth_service_; | 266 std::string xmpp_auth_service_; |
266 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 267 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
267 bool allow_nat_traversal_; | 268 bool allow_nat_traversal_; |
268 std::string talkgadget_prefix_; | 269 std::string talkgadget_prefix_; |
| 270 bool allow_pairing_; |
269 | 271 |
270 bool curtain_required_; | 272 bool curtain_required_; |
271 GURL token_url_; | 273 GURL token_url_; |
272 GURL token_validation_url_; | 274 GURL token_validation_url_; |
273 | 275 |
274 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 276 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
275 scoped_ptr<SignalingConnector> signaling_connector_; | 277 scoped_ptr<SignalingConnector> signaling_connector_; |
276 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 278 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
277 scoped_ptr<HostStatusSender> host_status_sender_; | 279 scoped_ptr<HostStatusSender> host_status_sender_; |
278 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 280 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
(...skipping 11 matching lines...) Expand all Loading... |
290 | 292 |
291 int* exit_code_out_; | 293 int* exit_code_out_; |
292 bool signal_parent_; | 294 bool signal_parent_; |
293 }; | 295 }; |
294 | 296 |
295 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 297 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
296 int* exit_code_out) | 298 int* exit_code_out) |
297 : context_(context.Pass()), | 299 : context_(context.Pass()), |
298 state_(HOST_INITIALIZING), | 300 state_(HOST_INITIALIZING), |
299 allow_nat_traversal_(true), | 301 allow_nat_traversal_(true), |
| 302 allow_pairing_(true), |
300 curtain_required_(false), | 303 curtain_required_(false), |
301 #if defined(REMOTING_MULTI_PROCESS) | 304 #if defined(REMOTING_MULTI_PROCESS) |
302 desktop_session_connector_(NULL), | 305 desktop_session_connector_(NULL), |
303 #endif // defined(REMOTING_MULTI_PROCESS) | 306 #endif // defined(REMOTING_MULTI_PROCESS) |
304 self_(this), | 307 self_(this), |
305 exit_code_out_(exit_code_out), | 308 exit_code_out_(exit_code_out), |
306 signal_parent_(false) { | 309 signal_parent_(false) { |
307 StartOnUiThread(); | 310 StartOnUiThread(); |
308 } | 311 } |
309 | 312 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 if (state_ != HOST_STARTED) | 478 if (state_ != HOST_STARTED) |
476 return; | 479 return; |
477 | 480 |
478 std::string local_certificate = key_pair_->GenerateCertificate(); | 481 std::string local_certificate = key_pair_->GenerateCertificate(); |
479 if (local_certificate.empty()) { | 482 if (local_certificate.empty()) { |
480 LOG(ERROR) << "Failed to generate host certificate."; | 483 LOG(ERROR) << "Failed to generate host certificate."; |
481 ShutdownHost(kInitializationFailed); | 484 ShutdownHost(kInitializationFailed); |
482 return; | 485 return; |
483 } | 486 } |
484 | 487 |
485 scoped_refptr<protocol::PairingRegistry> pairing_registry = | 488 scoped_refptr<protocol::PairingRegistry> pairing_registry = NULL; |
486 CreatePairingRegistry(context_->file_task_runner()); | 489 if (allow_pairing_) { |
| 490 pairing_registry = CreatePairingRegistry(context_->file_task_runner()); |
| 491 } |
487 | 492 |
488 scoped_ptr<protocol::AuthenticatorFactory> factory; | 493 scoped_ptr<protocol::AuthenticatorFactory> factory; |
489 | 494 |
490 if (token_url_.is_empty() && token_validation_url_.is_empty()) { | 495 if (token_url_.is_empty() && token_validation_url_.is_empty()) { |
491 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( | 496 factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( |
492 local_certificate, key_pair_, host_secret_hash_, pairing_registry); | 497 local_certificate, key_pair_, host_secret_hash_, pairing_registry); |
493 | 498 |
494 } else if (token_url_.is_valid() && token_validation_url_.is_valid()) { | 499 } else if (token_url_.is_valid() && token_validation_url_.is_valid()) { |
495 scoped_ptr<protocol::ThirdPartyHostAuthenticator::TokenValidatorFactory> | 500 scoped_ptr<protocol::ThirdPartyHostAuthenticator::TokenValidatorFactory> |
496 token_validator_factory(new TokenValidatorFactoryImpl( | 501 token_validator_factory(new TokenValidatorFactoryImpl( |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 std::string token_url_string, token_validation_url_string; | 746 std::string token_url_string, token_validation_url_string; |
742 if (policies->GetString( | 747 if (policies->GetString( |
743 policy_hack::PolicyWatcher::kHostTokenUrlPolicyName, | 748 policy_hack::PolicyWatcher::kHostTokenUrlPolicyName, |
744 &token_url_string) && | 749 &token_url_string) && |
745 policies->GetString( | 750 policies->GetString( |
746 policy_hack::PolicyWatcher::kHostTokenValidationUrlPolicyName, | 751 policy_hack::PolicyWatcher::kHostTokenValidationUrlPolicyName, |
747 &token_validation_url_string)) { | 752 &token_validation_url_string)) { |
748 restart_required |= OnHostTokenUrlPolicyUpdate( | 753 restart_required |= OnHostTokenUrlPolicyUpdate( |
749 GURL(token_url_string), GURL(token_validation_url_string)); | 754 GURL(token_url_string), GURL(token_validation_url_string)); |
750 } | 755 } |
| 756 if (policies->GetBoolean( |
| 757 policy_hack::PolicyWatcher::kHostAllowClientPairing, |
| 758 &bool_value)) { |
| 759 restart_required |= OnPairingPolicyUpdate(bool_value); |
| 760 } |
751 | 761 |
752 if (state_ == HOST_INITIALIZING) { | 762 if (state_ == HOST_INITIALIZING) { |
753 StartHost(); | 763 StartHost(); |
754 } else if (state_ == HOST_STARTED && restart_required) { | 764 } else if (state_ == HOST_STARTED && restart_required) { |
755 RestartHost(); | 765 RestartHost(); |
756 } | 766 } |
757 } | 767 } |
758 | 768 |
759 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { | 769 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { |
760 // Returns true if the host has to be restarted after this policy update. | 770 // Returns true if the host has to be restarted after this policy update. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 << "TokenValidationUrl: " << token_validation_url; | 896 << "TokenValidationUrl: " << token_validation_url; |
887 | 897 |
888 token_url_ = token_url; | 898 token_url_ = token_url; |
889 token_validation_url_ = token_validation_url; | 899 token_validation_url_ = token_validation_url; |
890 return true; | 900 return true; |
891 } | 901 } |
892 | 902 |
893 return false; | 903 return false; |
894 } | 904 } |
895 | 905 |
| 906 bool HostProcess::OnPairingPolicyUpdate(bool allow_pairing) { |
| 907 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 908 |
| 909 if (allow_pairing_ == allow_pairing) |
| 910 return false; |
| 911 |
| 912 if (allow_pairing) |
| 913 LOG(INFO) << "Policy enables client pairing."; |
| 914 else |
| 915 LOG(INFO) << "Policy disables client pairing."; |
| 916 allow_pairing_ = allow_pairing; |
| 917 return true; |
| 918 } |
| 919 |
896 void HostProcess::StartHost() { | 920 void HostProcess::StartHost() { |
897 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 921 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
898 DCHECK(!host_); | 922 DCHECK(!host_); |
899 DCHECK(!signal_strategy_.get()); | 923 DCHECK(!signal_strategy_.get()); |
900 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 924 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
901 state_ == HOST_STOPPED) << state_; | 925 state_ == HOST_STOPPED) << state_; |
902 state_ = HOST_STARTED; | 926 state_ = HOST_STARTED; |
903 | 927 |
904 signal_strategy_.reset( | 928 signal_strategy_.reset( |
905 new XmppSignalStrategy(context_->url_request_context_getter(), | 929 new XmppSignalStrategy(context_->url_request_context_getter(), |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 return exit_code; | 1140 return exit_code; |
1117 } | 1141 } |
1118 | 1142 |
1119 } // namespace remoting | 1143 } // namespace remoting |
1120 | 1144 |
1121 #if !defined(OS_WIN) | 1145 #if !defined(OS_WIN) |
1122 int main(int argc, char** argv) { | 1146 int main(int argc, char** argv) { |
1123 return remoting::HostMain(argc, argv); | 1147 return remoting::HostMain(argc, argv); |
1124 } | 1148 } |
1125 #endif // !defined(OS_WIN) | 1149 #endif // !defined(OS_WIN) |
OLD | NEW |