Chromium Code Reviews| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 virtual void OnChannelError() OVERRIDE; | 167 virtual void OnChannelError() OVERRIDE; |
| 168 | 168 |
| 169 // HeartbeatSender::Listener overrides. | 169 // HeartbeatSender::Listener overrides. |
| 170 virtual void OnUnknownHostIdError() OVERRIDE; | 170 virtual void OnUnknownHostIdError() OVERRIDE; |
| 171 | 171 |
| 172 void StartHostProcess(); | 172 void StartHostProcess(); |
| 173 | 173 |
| 174 int get_exit_code() const; | 174 int get_exit_code() const; |
| 175 | 175 |
| 176 private: | 176 private: |
| 177 enum HostState { | |
|
alexeypa (please no reviews)
2012/11/20 17:00:56
bootstrapping and restarting states are confusing.
Sergey Ulanov
2012/11/20 20:02:34
We don't really need Starting state because host s
alexeypa (please no reviews)
2012/11/20 21:18:30
I see you point but the state diagram still looks
| |
| 178 // Host process has just been started. | |
| 179 HOST_BOOTSTRAPPING, | |
|
Wez
2012/11/20 03:44:19
nit: HOST_STARTING
alexeypa (please no reviews)
2012/11/20 17:00:56
+1
Sergey Ulanov
2012/11/20 20:02:34
STARTING doesn't make sense because host can be st
| |
| 180 | |
| 181 // Host is started and running. | |
| 182 HOST_STARTED, | |
| 183 | |
| 184 // Host is being restarted. | |
| 185 HOST_RESTARTING, | |
|
Wez
2012/11/20 03:44:19
Could this re-use HOST_STARTING, and we allow STAR
Sergey Ulanov
2012/11/20 20:02:34
See my comments above.
| |
| 186 | |
| 187 // Host is being stopped. | |
| 188 HOST_STOPPING, | |
| 189 | |
| 190 // Host has been stopped. | |
| 191 HOST_STOPPED, | |
| 192 | |
| 193 // Allowed state transitions: | |
| 194 // BOOTSTRAPPING->STARTED | |
| 195 // BOOTSTRAPPING->STOPPED | |
| 196 // STARTED->RESTARTING | |
| 197 // STARTED->STOPPING | |
| 198 // RESTARTING->STOPPING | |
|
alexeypa (please no reviews)
2012/11/20 17:00:56
nit: RESTARTING->STARTED is missing
Sergey Ulanov
2012/11/20 20:02:34
Done.
| |
| 199 // STOPPING->STOPPED | |
| 200 // STOPPED->STARTED | |
| 201 // | |
| 202 // |host_| must be NULL in BOOTSTRAPPING and STOPPED states and not-NULL in | |
| 203 // all other states. | |
| 204 }; | |
| 205 | |
| 177 #if defined(OS_POSIX) | 206 #if defined(OS_POSIX) |
| 178 // Registers a SIGTERM handler on the network thread, to shutdown the host. | 207 // Registers a SIGTERM handler on the network thread, to shutdown the host. |
| 179 void ListenForShutdownSignal(); | 208 void ListenForShutdownSignal(); |
| 180 | 209 |
| 181 // Callback passed to RegisterSignalHandler() to handle SIGTERM events. | 210 // Callback passed to RegisterSignalHandler() to handle SIGTERM events. |
| 182 void SigTermHandler(int signal_number); | 211 void SigTermHandler(int signal_number); |
| 183 #endif | 212 #endif |
| 184 | 213 |
| 185 // Asks the daemon to inject Secure Attention Sequence to the console. | 214 // Asks the daemon to inject Secure Attention Sequence to the console. |
| 186 void SendSasToConsole(); | 215 void SendSasToConsole(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 204 void OnAuthFailed(); | 233 void OnAuthFailed(); |
| 205 | 234 |
| 206 void RejectAuthenticatingClient(); | 235 void RejectAuthenticatingClient(); |
| 207 | 236 |
| 208 // Invoked when the user uses the Disconnect windows to terminate | 237 // Invoked when the user uses the Disconnect windows to terminate |
| 209 // the sessions, or when the local session is activated in curtain mode. | 238 // the sessions, or when the local session is activated in curtain mode. |
| 210 void OnDisconnectRequested(); | 239 void OnDisconnectRequested(); |
| 211 | 240 |
| 212 void RestartHost(); | 241 void RestartHost(); |
| 213 | 242 |
| 214 void RestartOnHostShutdown(); | 243 // Stops the host and shuts down the process with the specified |exit_code|. |
| 215 | 244 void ShutdownHost(int exit_code); |
| 216 void Shutdown(int exit_code); | |
| 217 | 245 |
| 218 void OnShutdownFinished(); | 246 void OnShutdownFinished(); |
| 219 | 247 |
| 220 void ResetHost(); | |
| 221 | |
| 222 // Crashes the process in response to a daemon's request. The daemon passes | 248 // Crashes the process in response to a daemon's request. The daemon passes |
| 223 // the location of the code that detected the fatal error resulted in this | 249 // the location of the code that detected the fatal error resulted in this |
| 224 // request. | 250 // request. |
| 225 void OnCrash(const std::string& function_name, | 251 void OnCrash(const std::string& function_name, |
| 226 const std::string& file_name, | 252 const std::string& file_name, |
| 227 const int& line_number); | 253 const int& line_number); |
| 228 | 254 |
| 229 scoped_ptr<ChromotingHostContext> context_; | 255 scoped_ptr<ChromotingHostContext> context_; |
| 230 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 256 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 231 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 257 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 247 std::string xmpp_auth_service_; | 273 std::string xmpp_auth_service_; |
| 248 | 274 |
| 249 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 275 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 250 bool allow_nat_traversal_; | 276 bool allow_nat_traversal_; |
| 251 std::string talkgadget_prefix_; | 277 std::string talkgadget_prefix_; |
| 252 | 278 |
| 253 scoped_ptr<CurtainMode> curtain_; | 279 scoped_ptr<CurtainMode> curtain_; |
| 254 scoped_ptr<CurtainingHostObserver> curtaining_host_observer_; | 280 scoped_ptr<CurtainingHostObserver> curtaining_host_observer_; |
| 255 bool curtain_required_; | 281 bool curtain_required_; |
| 256 | 282 |
| 257 bool restarting_; | 283 HostState state_; |
| 258 bool shutting_down_; | |
| 259 | 284 |
| 260 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 285 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
| 261 scoped_ptr<DesktopResizer> desktop_resizer_; | 286 scoped_ptr<DesktopResizer> desktop_resizer_; |
| 262 scoped_ptr<ResizingHostObserver> resizing_host_observer_; | 287 scoped_ptr<ResizingHostObserver> resizing_host_observer_; |
| 263 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 288 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 264 scoped_ptr<SignalingConnector> signaling_connector_; | 289 scoped_ptr<SignalingConnector> signaling_connector_; |
| 265 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 290 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 266 scoped_ptr<LogToServer> log_to_server_; | 291 scoped_ptr<LogToServer> log_to_server_; |
| 267 scoped_ptr<HostEventLogger> host_event_logger_; | 292 scoped_ptr<HostEventLogger> host_event_logger_; |
| 268 | 293 |
| 269 scoped_ptr<HostUserInterface> host_user_interface_; | 294 scoped_ptr<HostUserInterface> host_user_interface_; |
| 270 | 295 |
| 271 scoped_refptr<ChromotingHost> host_; | 296 scoped_refptr<ChromotingHost> host_; |
| 272 | 297 |
| 273 #if defined(REMOTING_MULTI_PROCESS) | 298 #if defined(REMOTING_MULTI_PROCESS) |
| 274 DesktopSessionConnector* desktop_session_connector_; | 299 DesktopSessionConnector* desktop_session_connector_; |
| 275 #endif // defined(REMOTING_MULTI_PROCESS) | 300 #endif // defined(REMOTING_MULTI_PROCESS) |
| 276 | 301 |
| 277 int exit_code_; | 302 int exit_code_; |
| 278 }; | 303 }; |
| 279 | 304 |
| 280 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context) | 305 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context) |
| 281 : context_(context.Pass()), | 306 : context_(context.Pass()), |
| 282 allow_nat_traversal_(true), | 307 allow_nat_traversal_(true), |
| 283 curtain_required_(false), | 308 curtain_required_(false), |
| 284 restarting_(false), | 309 state_(HOST_BOOTSTRAPPING), |
| 285 shutting_down_(false), | |
| 286 desktop_resizer_(DesktopResizer::Create()), | 310 desktop_resizer_(DesktopResizer::Create()), |
| 287 #if defined(REMOTING_MULTI_PROCESS) | 311 #if defined(REMOTING_MULTI_PROCESS) |
| 288 desktop_session_connector_(NULL), | 312 desktop_session_connector_(NULL), |
| 289 #endif // defined(REMOTING_MULTI_PROCESS) | 313 #endif // defined(REMOTING_MULTI_PROCESS) |
| 290 exit_code_(kSuccessExitCode) { | 314 exit_code_(kSuccessExitCode) { |
| 291 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 315 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 292 curtain_ = CurtainMode::Create( | 316 curtain_ = CurtainMode::Create( |
| 293 base::Bind(&HostProcess::OnDisconnectRequested, | 317 base::Bind(&HostProcess::OnDisconnectRequested, |
| 294 base::Unretained(this)), | 318 base::Unretained(this)), |
| 295 base::Bind(&HostProcess::RejectAuthenticatingClient, | 319 base::Bind(&HostProcess::RejectAuthenticatingClient, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 // Filter out duplicates. | 380 // Filter out duplicates. |
| 357 if (serialized_config_ == serialized_config) | 381 if (serialized_config_ == serialized_config) |
| 358 return; | 382 return; |
| 359 | 383 |
| 360 LOG(INFO) << "Processing new host configuration."; | 384 LOG(INFO) << "Processing new host configuration."; |
| 361 | 385 |
| 362 serialized_config_ = serialized_config; | 386 serialized_config_ = serialized_config; |
| 363 scoped_ptr<JsonHostConfig> config(new JsonHostConfig(FilePath())); | 387 scoped_ptr<JsonHostConfig> config(new JsonHostConfig(FilePath())); |
| 364 if (!config->SetSerializedData(serialized_config)) { | 388 if (!config->SetSerializedData(serialized_config)) { |
| 365 LOG(ERROR) << "Invalid configuration."; | 389 LOG(ERROR) << "Invalid configuration."; |
| 366 Shutdown(kInvalidHostConfigurationExitCode); | 390 ShutdownHost(kInvalidHostConfigurationExitCode); |
| 367 return; | 391 return; |
| 368 } | 392 } |
| 369 | 393 |
| 370 if (!ApplyConfig(config.Pass())) { | 394 if (!ApplyConfig(config.Pass())) { |
| 371 LOG(ERROR) << "Failed to apply the configuration."; | 395 LOG(ERROR) << "Failed to apply the configuration."; |
| 372 Shutdown(kInvalidHostConfigurationExitCode); | 396 ShutdownHost(kInvalidHostConfigurationExitCode); |
| 373 return; | 397 return; |
| 374 } | 398 } |
| 375 | 399 |
| 376 // Start watching the policy (and eventually start the host) if this is | 400 // Start watching the policy (and eventually start the host) if this is |
| 377 // the first configuration update. Otherwise, create new authenticator | 401 // the first configuration update. Otherwise, create new authenticator |
| 378 // factory in case PIN has changed. | 402 // factory in case PIN has changed. |
| 379 if (!policy_watcher_) { | 403 if (!policy_watcher_) { |
| 380 policy_watcher_.reset( | 404 policy_watcher_.reset( |
| 381 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 405 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
| 382 policy_watcher_->StartWatching( | 406 policy_watcher_->StartWatching( |
| 383 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 407 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
| 384 } else { | 408 } else { |
| 385 CreateAuthenticatorFactory(); | 409 CreateAuthenticatorFactory(); |
| 386 } | 410 } |
| 387 } | 411 } |
| 388 | 412 |
| 389 void HostProcess::OnConfigWatcherError() { | 413 void HostProcess::OnConfigWatcherError() { |
| 390 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 414 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 391 | 415 |
| 392 context_->network_task_runner()->PostTask( | 416 context_->network_task_runner()->PostTask( |
| 393 FROM_HERE, | 417 FROM_HERE, |
| 394 base::Bind(&HostProcess::Shutdown, base::Unretained(this), | 418 base::Bind(&HostProcess::ShutdownHost, base::Unretained(this), |
| 395 kInvalidHostConfigurationExitCode)); | 419 kInvalidHostConfigurationExitCode)); |
| 396 } | 420 } |
| 397 | 421 |
| 398 void HostProcess::StartWatchingConfigChanges() { | 422 void HostProcess::StartWatchingConfigChanges() { |
| 399 #if !defined(REMOTING_MULTI_PROCESS) | 423 #if !defined(REMOTING_MULTI_PROCESS) |
| 400 // Start watching the host configuration file. | 424 // Start watching the host configuration file. |
| 401 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), | 425 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), |
| 402 context_->file_task_runner(), | 426 context_->file_task_runner(), |
| 403 this)); | 427 this)); |
| 404 config_watcher_->Watch(host_config_path_); | 428 config_watcher_->Watch(host_config_path_); |
| 405 #endif // !defined(REMOTING_MULTI_PROCESS) | 429 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 406 } | 430 } |
| 407 | 431 |
| 408 #if defined(OS_POSIX) | 432 #if defined(OS_POSIX) |
| 409 void HostProcess::ListenForShutdownSignal() { | 433 void HostProcess::ListenForShutdownSignal() { |
| 410 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 434 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 411 | 435 |
| 412 remoting::RegisterSignalHandler( | 436 remoting::RegisterSignalHandler( |
| 413 SIGTERM, | 437 SIGTERM, |
| 414 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); | 438 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); |
| 415 } | 439 } |
| 416 | 440 |
| 417 void HostProcess::SigTermHandler(int signal_number) { | 441 void HostProcess::SigTermHandler(int signal_number) { |
| 418 DCHECK(signal_number == SIGTERM); | 442 DCHECK(signal_number == SIGTERM); |
| 419 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 443 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 420 LOG(INFO) << "Caught SIGTERM: Shutting down..."; | 444 LOG(INFO) << "Caught SIGTERM: Shutting down..."; |
| 421 Shutdown(kSuccessExitCode); | 445 ShutdownHost(kSuccessExitCode); |
| 422 } | 446 } |
| 423 #endif // OS_POSIX | 447 #endif // OS_POSIX |
| 424 | 448 |
| 425 void HostProcess::CreateAuthenticatorFactory() { | 449 void HostProcess::CreateAuthenticatorFactory() { |
| 426 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 450 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 427 | 451 |
| 428 if (!host_ || shutting_down_) | 452 if (state_ != HOST_STARTED) |
| 429 return; | 453 return; |
| 430 | 454 |
| 431 std::string local_certificate = key_pair_.GenerateCertificate(); | 455 std::string local_certificate = key_pair_.GenerateCertificate(); |
| 432 if (local_certificate.empty()) { | 456 if (local_certificate.empty()) { |
| 433 LOG(ERROR) << "Failed to generate host certificate."; | 457 LOG(ERROR) << "Failed to generate host certificate."; |
| 434 Shutdown(kInitializationFailed); | 458 ShutdownHost(kInitializationFailed); |
| 435 return; | 459 return; |
| 436 } | 460 } |
| 437 | 461 |
| 438 scoped_ptr<protocol::AuthenticatorFactory> factory( | 462 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 439 new protocol::Me2MeHostAuthenticatorFactory( | 463 new protocol::Me2MeHostAuthenticatorFactory( |
| 440 local_certificate, *key_pair_.private_key(), host_secret_hash_)); | 464 local_certificate, *key_pair_.private_key(), host_secret_hash_)); |
| 441 #if defined(OS_LINUX) | 465 #if defined(OS_LINUX) |
| 442 // On Linux, perform a PAM authorization step after authentication. | 466 // On Linux, perform a PAM authorization step after authentication. |
| 443 factory.reset(new PamAuthorizationFactory(factory.Pass())); | 467 factory.reset(new PamAuthorizationFactory(factory.Pass())); |
| 444 #endif | 468 #endif |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 470 return false; | 494 return false; |
| 471 #endif // !defined(REMOTING_MULTI_PROCESS) | 495 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 472 } | 496 } |
| 473 | 497 |
| 474 void HostProcess::OnChannelError() { | 498 void HostProcess::OnChannelError() { |
| 475 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 499 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 476 | 500 |
| 477 // Shutdown the host if the daemon disconnected the channel. | 501 // Shutdown the host if the daemon disconnected the channel. |
| 478 context_->network_task_runner()->PostTask( | 502 context_->network_task_runner()->PostTask( |
| 479 FROM_HERE, | 503 FROM_HERE, |
| 480 base::Bind(&HostProcess::Shutdown, base::Unretained(this), | 504 base::Bind(&HostProcess::ShutdownHost, base::Unretained(this), |
| 481 kSuccessExitCode)); | 505 kSuccessExitCode)); |
| 482 } | 506 } |
| 483 | 507 |
| 484 void HostProcess::StartHostProcess() { | 508 void HostProcess::StartHostProcess() { |
| 485 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 509 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 486 | 510 |
| 487 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 511 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 488 OnConfigWatcherError(); | 512 OnConfigWatcherError(); |
| 489 return; | 513 return; |
| 490 } | 514 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 daemon_channel_.reset(); | 614 daemon_channel_.reset(); |
| 591 desktop_environment_factory_.reset(); | 615 desktop_environment_factory_.reset(); |
| 592 host_user_interface_.reset(); | 616 host_user_interface_.reset(); |
| 593 | 617 |
| 594 context_.reset(); | 618 context_.reset(); |
| 595 } | 619 } |
| 596 | 620 |
| 597 // Overridden from HeartbeatSender::Listener | 621 // Overridden from HeartbeatSender::Listener |
| 598 void HostProcess::OnUnknownHostIdError() { | 622 void HostProcess::OnUnknownHostIdError() { |
| 599 LOG(ERROR) << "Host ID not found."; | 623 LOG(ERROR) << "Host ID not found."; |
| 600 Shutdown(kInvalidHostIdExitCode); | 624 ShutdownHost(kInvalidHostIdExitCode); |
| 601 } | 625 } |
| 602 | 626 |
| 603 // Applies the host config, returning true if successful. | 627 // Applies the host config, returning true if successful. |
| 604 bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) { | 628 bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) { |
| 605 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 629 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 606 | 630 |
| 607 if (!config->GetString(kHostIdConfigPath, &host_id_)) { | 631 if (!config->GetString(kHostIdConfigPath, &host_id_)) { |
| 608 LOG(ERROR) << "host_id is not defined in the config."; | 632 LOG(ERROR) << "host_id is not defined in the config."; |
| 609 return false; | 633 return false; |
| 610 } | 634 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 if (policies->GetString( | 698 if (policies->GetString( |
| 675 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | 699 policy_hack::PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
| 676 &string_value)) { | 700 &string_value)) { |
| 677 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); | 701 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(string_value); |
| 678 } | 702 } |
| 679 if (policies->GetBoolean( | 703 if (policies->GetBoolean( |
| 680 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | 704 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, |
| 681 &bool_value)) { | 705 &bool_value)) { |
| 682 restart_required |= OnCurtainPolicyUpdate(bool_value); | 706 restart_required |= OnCurtainPolicyUpdate(bool_value); |
| 683 } | 707 } |
| 684 if (!host_) { | 708 |
| 709 if (state_ == HOST_BOOTSTRAPPING) { | |
| 685 StartHost(); | 710 StartHost(); |
| 686 } else if (restart_required) { | 711 } else if (state_ == HOST_STARTED) { |
| 687 RestartHost(); | 712 RestartHost(); |
| 688 } | 713 } |
| 689 } | 714 } |
| 690 | 715 |
| 691 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { | 716 bool HostProcess::OnHostDomainPolicyUpdate(const std::string& host_domain) { |
| 692 // Returns true if the host has to be restarted after this policy update. | 717 // Returns true if the host has to be restarted after this policy update. |
| 693 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 718 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 694 | 719 |
| 695 LOG(INFO) << "Policy sets host domain: " << host_domain; | 720 LOG(INFO) << "Policy sets host domain: " << host_domain; |
| 696 | 721 |
| 697 if (!host_domain.empty() && | 722 if (!host_domain.empty() && |
| 698 !EndsWith(xmpp_login_, std::string("@") + host_domain, false)) { | 723 !EndsWith(xmpp_login_, std::string("@") + host_domain, false)) { |
| 699 Shutdown(kInvalidHostDomainExitCode); | 724 ShutdownHost(kInvalidHostDomainExitCode); |
| 700 } | 725 } |
| 701 return false; | 726 return false; |
| 702 } | 727 } |
| 703 | 728 |
| 704 bool HostProcess::OnUsernamePolicyUpdate(bool host_username_match_required) { | 729 bool HostProcess::OnUsernamePolicyUpdate(bool host_username_match_required) { |
| 705 // Returns false: never restart the host after this policy update. | 730 // Returns false: never restart the host after this policy update. |
| 706 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 731 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 707 | 732 |
| 708 if (host_username_match_required) { | 733 if (host_username_match_required) { |
| 709 LOG(INFO) << "Policy requires host username match."; | 734 LOG(INFO) << "Policy requires host username match."; |
| 710 if (!CanGetUsername() || | 735 if (!CanGetUsername() || |
| 711 !StartsWithASCII(xmpp_login_, GetUsername() + std::string("@"), | 736 !StartsWithASCII(xmpp_login_, GetUsername() + std::string("@"), |
| 712 false)) { | 737 false)) { |
| 713 Shutdown(kUsernameMismatchExitCode); | 738 ShutdownHost(kUsernameMismatchExitCode); |
| 714 } | 739 } |
| 715 } else { | 740 } else { |
| 716 LOG(INFO) << "Policy does not require host username match."; | 741 LOG(INFO) << "Policy does not require host username match."; |
| 717 } | 742 } |
| 718 | 743 |
| 719 return false; | 744 return false; |
| 720 } | 745 } |
| 721 | 746 |
| 722 bool HostProcess::OnNatPolicyUpdate(bool nat_traversal_enabled) { | 747 bool HostProcess::OnNatPolicyUpdate(bool nat_traversal_enabled) { |
| 723 // Returns true if the host has to be restarted after this policy update. | 748 // Returns true if the host has to be restarted after this policy update. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 743 // When curtain mode is in effect on Mac, the host process runs in the | 768 // When curtain mode is in effect on Mac, the host process runs in the |
| 744 // user's switched-out session, but launchd will also run an instance at | 769 // user's switched-out session, but launchd will also run an instance at |
| 745 // the console login screen. Even if no user is currently logged-on, we | 770 // the console login screen. Even if no user is currently logged-on, we |
| 746 // can't support remote-access to the login screen because the current host | 771 // can't support remote-access to the login screen because the current host |
| 747 // process model disconnects the client during login, which would leave | 772 // process model disconnects the client during login, which would leave |
| 748 // the logged in session un-curtained on the console until they reconnect. | 773 // the logged in session un-curtained on the console until they reconnect. |
| 749 // | 774 // |
| 750 // TODO(jamiewalch): Fix this once we have implemented the multi-process | 775 // TODO(jamiewalch): Fix this once we have implemented the multi-process |
| 751 // daemon architecture (crbug.com/134894) | 776 // daemon architecture (crbug.com/134894) |
| 752 if (getuid() == 0) { | 777 if (getuid() == 0) { |
| 753 Shutdown(kLoginScreenNotSupportedExitCode); | 778 ShutdownHost(kLoginScreenNotSupportedExitCode); |
| 754 return false; | 779 return false; |
| 755 } | 780 } |
| 756 } | 781 } |
| 757 #endif | 782 #endif |
| 758 | 783 |
| 759 if (curtain_required_ != curtain_required) { | 784 if (curtain_required_ != curtain_required) { |
| 760 if (curtain_required) | 785 if (curtain_required) |
| 761 LOG(ERROR) << "Policy requires curtain-mode."; | 786 LOG(ERROR) << "Policy requires curtain-mode."; |
| 762 else | 787 else |
| 763 LOG(ERROR) << "Policy does not require curtain-mode."; | 788 LOG(ERROR) << "Policy does not require curtain-mode."; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 784 | 809 |
| 785 void HostProcess::StartHostStatusService() { | 810 void HostProcess::StartHostStatusService() { |
| 786 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 811 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 787 status_service_.reset(new HostStatusService()); | 812 status_service_.reset(new HostStatusService()); |
| 788 } | 813 } |
| 789 | 814 |
| 790 void HostProcess::StartHost() { | 815 void HostProcess::StartHost() { |
| 791 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 816 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 792 DCHECK(!host_); | 817 DCHECK(!host_); |
| 793 DCHECK(!signal_strategy_.get()); | 818 DCHECK(!signal_strategy_.get()); |
| 794 | 819 DCHECK(state_ == HOST_BOOTSTRAPPING || state_ == HOST_RESTARTING || |
| 795 if (shutting_down_) | 820 state_ == HOST_STOPPED) << state_; |
| 796 return; | 821 state_ = HOST_STARTED; |
| 797 | 822 |
| 798 signal_strategy_.reset( | 823 signal_strategy_.reset( |
| 799 new XmppSignalStrategy(context_->url_request_context_getter(), | 824 new XmppSignalStrategy(context_->url_request_context_getter(), |
| 800 xmpp_login_, xmpp_auth_token_, | 825 xmpp_login_, xmpp_auth_token_, |
| 801 xmpp_auth_service_)); | 826 xmpp_auth_service_)); |
| 802 | 827 |
| 803 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( | 828 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker( |
| 804 new DnsBlackholeChecker(context_->url_request_context_getter(), | 829 new DnsBlackholeChecker(context_->url_request_context_getter(), |
| 805 talkgadget_prefix_)); | 830 talkgadget_prefix_)); |
| 806 | 831 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 | 895 |
| 871 if (status_service_) | 896 if (status_service_) |
| 872 status_service_->SetHostIsUp(host_id_); | 897 status_service_->SetHostIsUp(host_id_); |
| 873 | 898 |
| 874 host_->Start(xmpp_login_); | 899 host_->Start(xmpp_login_); |
| 875 | 900 |
| 876 CreateAuthenticatorFactory(); | 901 CreateAuthenticatorFactory(); |
| 877 } | 902 } |
| 878 | 903 |
| 879 void HostProcess::OnAuthFailed() { | 904 void HostProcess::OnAuthFailed() { |
| 880 Shutdown(kInvalidOauthCredentialsExitCode); | 905 ShutdownHost(kInvalidOauthCredentialsExitCode); |
| 881 } | 906 } |
| 882 | 907 |
| 883 void HostProcess::RejectAuthenticatingClient() { | 908 void HostProcess::RejectAuthenticatingClient() { |
| 884 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 909 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 885 DCHECK(host_); | 910 DCHECK(host_); |
| 886 host_->RejectAuthenticatingClient(); | 911 host_->RejectAuthenticatingClient(); |
| 887 } | 912 } |
| 888 | 913 |
| 889 // Invoked when the user uses the Disconnect windows to terminate | 914 // Invoked when the user uses the Disconnect windows to terminate |
| 890 // the sessions, or when the local session is activated in curtain mode. | 915 // the sessions, or when the local session is activated in curtain mode. |
| 891 void HostProcess::OnDisconnectRequested() { | 916 void HostProcess::OnDisconnectRequested() { |
| 892 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 917 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 893 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 918 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 894 &HostProcess::OnDisconnectRequested, base::Unretained(this))); | 919 &HostProcess::OnDisconnectRequested, base::Unretained(this))); |
| 895 return; | 920 return; |
| 896 } | 921 } |
| 897 if (host_) { | 922 if (host_) { |
| 898 host_->DisconnectAllClients(); | 923 host_->DisconnectAllClients(); |
| 899 } | 924 } |
| 900 } | 925 } |
| 901 | 926 |
| 902 void HostProcess::RestartHost() { | 927 void HostProcess::RestartHost() { |
| 903 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 928 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 929 DCHECK_EQ(state_, HOST_STARTED) | |
| 904 | 930 |
| 905 if (restarting_ || shutting_down_) | 931 state_ = HOST_RESTARTING; |
| 906 return; | |
| 907 | |
| 908 restarting_ = true; | |
| 909 host_->Shutdown(base::Bind( | 932 host_->Shutdown(base::Bind( |
| 910 &HostProcess::RestartOnHostShutdown, base::Unretained(this))); | 933 &HostProcess::OnShutdownFinished, base::Unretained(this))); |
| 911 } | 934 } |
| 912 | 935 |
| 913 void HostProcess::RestartOnHostShutdown() { | 936 void HostProcess::ShutdownHost(int exit_code) { |
|
Wez
2012/11/20 03:44:19
nit: ShutdownHost -> Shutdown - this doesn't just
Sergey Ulanov
2012/11/20 20:02:34
See my previous comments about not shutting down t
| |
| 914 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 937 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 915 | 938 |
| 916 if (shutting_down_) | 939 exit_code_ = exit_code; |
| 917 return; | |
| 918 | 940 |
| 919 restarting_ = false; | 941 switch (state_) { |
| 920 host_ = NULL; | 942 case HOST_BOOTSTRAPPING: |
| 921 ResetHost(); | 943 state_ = HOST_STOPPED; |
| 944 OnShutdownFinished(); | |
| 945 break; | |
| 922 | 946 |
| 923 StartHost(); | 947 case HOST_STARTED: |
| 924 } | 948 if (status_service_) |
| 949 status_service_->SetHostIsDown(); | |
| 950 host_->Shutdown(base::Bind( | |
| 951 &HostProcess::OnShutdownFinished, base::Unretained(this))); | |
| 952 state_ = HOST_STOPPING; | |
| 953 break; | |
| 925 | 954 |
| 926 void HostProcess::Shutdown(int exit_code) { | 955 case HOST_RESTARTING: |
| 927 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 956 state_ = HOST_STOPPING; |
| 957 break; | |
| 928 | 958 |
| 929 if (shutting_down_) | 959 case HOST_STOPPING: |
| 930 return; | 960 case HOST_STOPPED: |
| 931 | 961 // Host is already stopped or being stopped. No action is required. |
| 932 if (status_service_) | 962 break; |
| 933 status_service_->SetHostIsDown(); | |
| 934 | |
| 935 shutting_down_ = true; | |
| 936 exit_code_ = exit_code; | |
| 937 if (host_) { | |
| 938 host_->Shutdown(base::Bind( | |
| 939 &HostProcess::OnShutdownFinished, base::Unretained(this))); | |
| 940 } else { | |
| 941 OnShutdownFinished(); | |
| 942 } | 963 } |
| 943 } | 964 } |
| 944 | 965 |
| 945 void HostProcess::OnShutdownFinished() { | 966 void HostProcess::OnShutdownFinished() { |
| 946 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 967 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 947 | 968 |
| 948 // Destroy networking objects while we are on the network thread. | |
| 949 host_ = NULL; | 969 host_ = NULL; |
| 950 ResetHost(); | |
| 951 | |
| 952 if (policy_watcher_.get()) { | |
| 953 base::WaitableEvent done_event(true, false); | |
| 954 policy_watcher_->StopWatching(&done_event); | |
| 955 done_event.Wait(); | |
| 956 policy_watcher_.reset(); | |
| 957 } | |
| 958 | |
| 959 status_service_.reset(); | |
| 960 | |
| 961 // Complete the rest of shutdown on the main thread. | |
| 962 context_->ui_task_runner()->PostTask( | |
| 963 FROM_HERE, | |
| 964 base::Bind(&HostProcess::ShutdownHostProcess, | |
| 965 base::Unretained(this))); | |
| 966 } | |
| 967 | |
| 968 void HostProcess::ResetHost() { | |
| 969 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 970 | |
| 971 curtaining_host_observer_.reset(); | 970 curtaining_host_observer_.reset(); |
| 972 host_event_logger_.reset(); | 971 host_event_logger_.reset(); |
| 973 log_to_server_.reset(); | 972 log_to_server_.reset(); |
| 974 heartbeat_sender_.reset(); | 973 heartbeat_sender_.reset(); |
| 975 signaling_connector_.reset(); | 974 signaling_connector_.reset(); |
| 976 signal_strategy_.reset(); | 975 signal_strategy_.reset(); |
| 977 resizing_host_observer_.reset(); | 976 resizing_host_observer_.reset(); |
| 977 | |
| 978 if (state_ == HOST_RESTARTING) { | |
| 979 StartHost(); | |
| 980 } else if (state_ == HOST_STOPPING) { | |
| 981 state_ = HOST_STOPPED; | |
| 982 | |
| 983 if (policy_watcher_.get()) { | |
| 984 base::WaitableEvent done_event(true, false); | |
| 985 policy_watcher_->StopWatching(&done_event); | |
| 986 done_event.Wait(); | |
| 987 policy_watcher_.reset(); | |
| 988 } | |
| 989 | |
| 990 status_service_.reset(); | |
| 991 | |
| 992 // Complete the rest of shutdown on the main thread. | |
| 993 context_->ui_task_runner()->PostTask( | |
| 994 FROM_HERE, | |
| 995 base::Bind(&HostProcess::ShutdownHostProcess, | |
| 996 base::Unretained(this))); | |
| 997 } else { | |
| 998 // This method is used as a callback for ChromotingHost::Shutdown() which is | |
| 999 // called only in RESTARTING and STOPPING states. | |
| 1000 NOTREACHED(); | |
| 1001 } | |
| 978 } | 1002 } |
| 979 | 1003 |
| 980 void HostProcess::OnCrash(const std::string& function_name, | 1004 void HostProcess::OnCrash(const std::string& function_name, |
| 981 const std::string& file_name, | 1005 const std::string& file_name, |
| 982 const int& line_number) { | 1006 const int& line_number) { |
| 983 CHECK(false); | 1007 CHECK(false); |
| 984 } | 1008 } |
| 985 | 1009 |
| 986 } // namespace remoting | 1010 } // namespace remoting |
| 987 | 1011 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1068 user32.GetFunctionPointer("SetProcessDPIAware")); | 1092 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 1069 set_process_dpi_aware(); | 1093 set_process_dpi_aware(); |
| 1070 } | 1094 } |
| 1071 | 1095 |
| 1072 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 1096 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 1073 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 1097 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 1074 return main(0, NULL); | 1098 return main(0, NULL); |
| 1075 } | 1099 } |
| 1076 | 1100 |
| 1077 #endif // defined(OS_WIN) | 1101 #endif // defined(OS_WIN) |
| OLD | NEW |