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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "remoting/host/network_settings.h" | 43 #include "remoting/host/network_settings.h" |
| 44 #include "remoting/host/policy_hack/policy_watcher.h" | 44 #include "remoting/host/policy_hack/policy_watcher.h" |
| 45 #include "remoting/host/session_manager_factory.h" | 45 #include "remoting/host/session_manager_factory.h" |
| 46 #include "remoting/host/signaling_connector.h" | 46 #include "remoting/host/signaling_connector.h" |
| 47 #include "remoting/host/usage_stats_consent.h" | 47 #include "remoting/host/usage_stats_consent.h" |
| 48 #include "remoting/host/video_frame_capturer.h" | 48 #include "remoting/host/video_frame_capturer.h" |
| 49 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 49 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 50 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 50 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
| 51 | 51 |
| 52 #if defined(OS_MACOSX) | 52 #if defined(OS_MACOSX) |
| 53 #include "base/mac/scoped_cftyperef.h" | |
| 53 #include "base/mac/scoped_nsautorelease_pool.h" | 54 #include "base/mac/scoped_nsautorelease_pool.h" |
| 54 #include "remoting/host/curtain_mode_mac.h" | 55 #include "remoting/host/curtain_mode_mac.h" |
| 55 #include "remoting/host/sighup_listener_mac.h" | 56 #include "remoting/host/sighup_listener_mac.h" |
| 56 #endif | 57 #endif |
| 57 // N.B. OS_WIN is defined by including src/base headers. | 58 // N.B. OS_WIN is defined by including src/base headers. |
| 58 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 59 #include <commctrl.h> | 60 #include <commctrl.h> |
| 60 #endif | 61 #endif |
| 61 #if defined(TOOLKIT_GTK) | 62 #if defined(TOOLKIT_GTK) |
| 62 #include "ui/gfx/gtk_util.h" | 63 #include "ui/gfx/gtk_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 HostProcess() | 97 HostProcess() |
| 97 : message_loop_(MessageLoop::TYPE_UI), | 98 : message_loop_(MessageLoop::TYPE_UI), |
| 98 #ifdef OFFICIAL_BUILD | 99 #ifdef OFFICIAL_BUILD |
| 99 oauth_use_official_client_id_(true), | 100 oauth_use_official_client_id_(true), |
| 100 #else | 101 #else |
| 101 oauth_use_official_client_id_(false), | 102 oauth_use_official_client_id_(false), |
| 102 #endif | 103 #endif |
| 103 allow_nat_traversal_(true), | 104 allow_nat_traversal_(true), |
| 104 restarting_(false), | 105 restarting_(false), |
| 105 shutting_down_(false), | 106 shutting_down_(false), |
| 106 exit_code_(kSuccessExitCode) { | 107 exit_code_(kSuccessExitCode) |
| 108 #if defined(OS_MACOSX) | |
| 109 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, | |
| 110 base::Unretained(this)), | |
| 111 base::Bind(&HostProcess::OnDisconnectRequested, | |
| 112 base::Unretained(this))) | |
| 113 #endif | |
| 114 { | |
| 107 context_.reset( | 115 context_.reset( |
| 108 new ChromotingHostContext(message_loop_.message_loop_proxy())); | 116 new ChromotingHostContext(message_loop_.message_loop_proxy())); |
| 109 context_->Start(); | 117 context_->Start(); |
| 110 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 118 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 111 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | 119 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( |
| 112 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | 120 FROM_HERE, base::TimeDelta::FromSeconds(2), this, |
| 113 &HostProcess::ConfigUpdatedDelayed)); | 121 &HostProcess::ConfigUpdatedDelayed)); |
| 114 } | 122 } |
| 115 | 123 |
| 116 bool InitWithCommandLine(const CommandLine* cmd_line) { | 124 bool InitWithCommandLine(const CommandLine* cmd_line) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 } | 320 } |
| 313 | 321 |
| 314 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 322 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
| 315 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 323 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 316 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 324 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 317 &HostProcess::OnPolicyUpdate, base::Unretained(this), | 325 &HostProcess::OnPolicyUpdate, base::Unretained(this), |
| 318 base::Passed(&policies))); | 326 base::Passed(&policies))); |
| 319 return; | 327 return; |
| 320 } | 328 } |
| 321 | 329 |
| 330 if (!host_) { | |
| 331 StartHost(); | |
| 332 } | |
| 333 | |
| 322 bool bool_value; | 334 bool bool_value; |
| 323 std::string string_value; | 335 std::string string_value; |
| 324 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, | 336 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, |
| 325 &string_value)) { | 337 &string_value)) { |
| 326 OnHostDomainPolicyUpdate(string_value); | 338 OnHostDomainPolicyUpdate(string_value); |
| 327 } | 339 } |
| 328 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 340 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
| 329 &bool_value)) { | 341 &bool_value)) { |
| 330 OnNatPolicyUpdate(bool_value); | 342 OnNatPolicyUpdate(bool_value); |
| 331 } | 343 } |
| 344 if (policies->GetBoolean( | |
| 345 policy_hack::PolicyWatcher::kHostRequireCurtainPolicyName, | |
| 346 &bool_value)) { | |
| 347 OnCurtainPolicyUpdate(bool_value); | |
| 348 } | |
| 332 } | 349 } |
| 333 | 350 |
| 334 void OnHostDomainPolicyUpdate(const std::string& host_domain) { | 351 void OnHostDomainPolicyUpdate(const std::string& host_domain) { |
| 335 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 352 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 336 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 353 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 337 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), | 354 &HostProcess::OnHostDomainPolicyUpdate, base::Unretained(this), |
| 338 host_domain)); | 355 host_domain)); |
| 339 return; | 356 return; |
| 340 } | 357 } |
| 341 | 358 |
| 342 if (!host_domain.empty() && | 359 if (!host_domain.empty() && |
| 343 !EndsWith(xmpp_login_, std::string("@") + host_domain, false)) { | 360 !EndsWith(xmpp_login_, std::string("@") + host_domain, false)) { |
| 344 Shutdown(kInvalidHostDomainExitCode); | 361 Shutdown(kInvalidHostDomainExitCode); |
| 345 } | 362 } |
| 346 } | 363 } |
| 347 | 364 |
| 348 void OnNatPolicyUpdate(bool nat_traversal_enabled) { | 365 void OnNatPolicyUpdate(bool nat_traversal_enabled) { |
| 349 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 366 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 350 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 367 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 351 &HostProcess::OnNatPolicyUpdate, base::Unretained(this), | 368 &HostProcess::OnNatPolicyUpdate, base::Unretained(this), |
| 352 nat_traversal_enabled)); | 369 nat_traversal_enabled)); |
| 353 return; | 370 return; |
| 354 } | 371 } |
| 355 | 372 |
| 356 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled; | 373 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled; |
| 357 allow_nat_traversal_ = nat_traversal_enabled; | 374 allow_nat_traversal_ = nat_traversal_enabled; |
| 358 | 375 |
| 359 if (host_) { | 376 if (policy_changed) { |
| 360 // Restart the host if the policy has changed while the host was | 377 RestartHost(); |
| 361 // online. | |
| 362 if (policy_changed) | |
| 363 RestartHost(); | |
| 364 } else { | |
| 365 // Just start the host otherwise. | |
| 366 StartHost(); | |
| 367 } | 378 } |
| 368 } | 379 } |
| 369 | 380 |
| 381 void OnCurtainPolicyUpdate(bool curtain_required) { | |
| 382 #if defined(OS_MACOSX) | |
| 383 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | |
| 384 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | |
| 385 &HostProcess::OnCurtainPolicyUpdate, base::Unretained(this), | |
| 386 curtain_required)); | |
| 387 return; | |
| 388 } | |
| 389 | |
| 390 if (curtain_required) { | |
| 391 // If curtain mode is required, then we can't currently support remoting | |
| 392 // the login screen. This is because the current daemon architecture means | |
| 393 // that the remote user is disconnected immediately after login, leaving | |
| 394 // the host system uncurtained. | |
|
Lambros
2012/08/14 20:21:06
I don't understand this. Why does disconnection i
Jamie
2012/08/14 22:04:22
If you connect while at the login screen, we don't
Lambros
2012/08/14 23:28:50
OK I get it now :) The missing piece here is that
Jamie
2012/08/15 18:22:56
Done.
| |
| 395 // | |
| 396 // TODO(jamiewalch): Fix this once we have implemented the multi-process | |
| 397 // daemon architecture | |
|
garykac
2012/08/14 19:58:48
Is there a bug tracking the multi-proc daemon work
Jamie
2012/08/15 18:22:56
Yes. I've added a reference to it here.
| |
| 398 base::mac::ScopedCFTypeRef<CFDictionaryRef> session( | |
| 399 CGSessionCopyCurrentDictionary()); | |
| 400 const void* logged_in = CFDictionaryGetValue(session, | |
| 401 kCGSessionLoginDoneKey); | |
| 402 if (logged_in != kCFBooleanTrue) { | |
| 403 Shutdown(kLoginScreenNotSupportedExitCode); | |
| 404 return; | |
| 405 } | |
| 406 | |
| 407 host_->AddStatusObserver(&curtain_); | |
| 408 curtain_.SetEnabled(true); | |
| 409 } else { | |
| 410 curtain_.SetEnabled(false); | |
| 411 host_->RemoveStatusObserver(&curtain_); | |
| 412 } | |
| 413 #endif | |
| 414 } | |
| 415 | |
| 370 void StartHost() { | 416 void StartHost() { |
| 371 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 417 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 372 DCHECK(!host_); | 418 DCHECK(!host_); |
| 373 | 419 |
| 374 if (shutting_down_) | 420 if (shutting_down_) |
| 375 return; | 421 return; |
| 376 | 422 |
| 377 if (!signal_strategy_.get()) { | 423 if (!signal_strategy_.get()) { |
| 378 signal_strategy_.reset( | 424 signal_strategy_.reset( |
| 379 new XmppSignalStrategy(context_->url_request_context_getter(), | 425 new XmppSignalStrategy(context_->url_request_context_getter(), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 log_to_server_.reset( | 486 log_to_server_.reset( |
| 441 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 487 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); |
| 442 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); | 488 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); |
| 443 | 489 |
| 444 #if defined(OS_MACOSX) || defined(OS_WIN) | 490 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 445 host_user_interface_->Start( | 491 host_user_interface_->Start( |
| 446 host_, base::Bind(&HostProcess::OnDisconnectRequested, | 492 host_, base::Bind(&HostProcess::OnDisconnectRequested, |
| 447 base::Unretained(this))); | 493 base::Unretained(this))); |
| 448 #endif | 494 #endif |
| 449 | 495 |
| 450 #if defined(OS_MACOSX) | |
| 451 curtain_.Init(base::Bind(&HostProcess::OnDisconnectRequested, | |
| 452 base::Unretained(this))); | |
| 453 host_->AddStatusObserver(&curtain_); | |
| 454 #endif | |
| 455 | |
| 456 host_->Start(); | 496 host_->Start(); |
| 457 | 497 |
| 458 CreateAuthenticatorFactory(); | 498 CreateAuthenticatorFactory(); |
| 459 } | 499 } |
| 460 | 500 |
| 461 void OnAuthFailed() { | 501 void OnAuthFailed() { |
| 462 Shutdown(kInvalidOauthCredentialsExitCode); | 502 Shutdown(kInvalidOauthCredentialsExitCode); |
| 463 } | 503 } |
| 464 | 504 |
| 465 // Invoked when the user uses the Disconnect windows to terminate | 505 // Invoked when the user uses the Disconnect windows to terminate |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 user32.GetFunctionPointer("SetProcessDPIAware")); | 698 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 659 set_process_dpi_aware(); | 699 set_process_dpi_aware(); |
| 660 } | 700 } |
| 661 | 701 |
| 662 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 702 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 663 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 703 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 664 return main(0, NULL); | 704 return main(0, NULL); |
| 665 } | 705 } |
| 666 | 706 |
| 667 #endif // defined(OS_WIN) | 707 #endif // defined(OS_WIN) |
| OLD | NEW |