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 19 matching lines...) Expand all Loading... | |
30 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
31 #include "net/socket/ssl_server_socket.h" | 31 #include "net/socket/ssl_server_socket.h" |
32 #include "remoting/base/auto_thread_task_runner.h" | 32 #include "remoting/base/auto_thread_task_runner.h" |
33 #include "remoting/base/breakpad.h" | 33 #include "remoting/base/breakpad.h" |
34 #include "remoting/base/constants.h" | 34 #include "remoting/base/constants.h" |
35 #include "remoting/host/branding.h" | 35 #include "remoting/host/branding.h" |
36 #include "remoting/host/chromoting_host.h" | 36 #include "remoting/host/chromoting_host.h" |
37 #include "remoting/host/chromoting_host_context.h" | 37 #include "remoting/host/chromoting_host_context.h" |
38 #include "remoting/host/chromoting_messages.h" | 38 #include "remoting/host/chromoting_messages.h" |
39 #include "remoting/host/config_file_watcher.h" | 39 #include "remoting/host/config_file_watcher.h" |
40 #include "remoting/host/constants.h" | |
41 #include "remoting/host/config_file_watcher.h" | 40 #include "remoting/host/config_file_watcher.h" |
42 #include "remoting/host/desktop_environment_factory.h" | 41 #include "remoting/host/desktop_environment_factory.h" |
43 #include "remoting/host/dns_blackhole_checker.h" | 42 #include "remoting/host/dns_blackhole_checker.h" |
44 #include "remoting/host/event_executor.h" | 43 #include "remoting/host/event_executor.h" |
45 #include "remoting/host/heartbeat_sender.h" | 44 #include "remoting/host/heartbeat_sender.h" |
46 #include "remoting/host/host_config.h" | 45 #include "remoting/host/host_config.h" |
47 #include "remoting/host/host_event_logger.h" | 46 #include "remoting/host/host_event_logger.h" |
47 #include "remoting/host/host_exit_codes.h" | |
48 #include "remoting/host/host_user_interface.h" | 48 #include "remoting/host/host_user_interface.h" |
49 #include "remoting/host/json_host_config.h" | 49 #include "remoting/host/json_host_config.h" |
50 #include "remoting/host/log_to_server.h" | 50 #include "remoting/host/log_to_server.h" |
51 #include "remoting/host/network_settings.h" | 51 #include "remoting/host/network_settings.h" |
52 #include "remoting/host/policy_hack/policy_watcher.h" | 52 #include "remoting/host/policy_hack/policy_watcher.h" |
53 #include "remoting/host/session_manager_factory.h" | 53 #include "remoting/host/session_manager_factory.h" |
54 #include "remoting/host/signaling_connector.h" | 54 #include "remoting/host/signaling_connector.h" |
55 #include "remoting/host/usage_stats_consent.h" | 55 #include "remoting/host/usage_stats_consent.h" |
56 #include "remoting/host/video_frame_capturer.h" | 56 #include "remoting/host/video_frame_capturer.h" |
57 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 57 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
58 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 58 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
59 | 59 |
60 #if defined(OS_POSIX) | 60 #if defined(OS_POSIX) |
61 #include <signal.h> | 61 #include <signal.h> |
62 #include "remoting/host/posix/signal_handler.h" | 62 #include "remoting/host/posix/signal_handler.h" |
63 #endif // defined(OS_POSIX) | 63 #endif // defined(OS_POSIX) |
64 | 64 |
65 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
66 #include "base/mac/scoped_cftyperef.h" | 66 #include "base/mac/scoped_cftyperef.h" |
67 #include "base/mac/scoped_nsautorelease_pool.h" | 67 #include "base/mac/scoped_nsautorelease_pool.h" |
68 #include "remoting/host/curtain_mode_mac.h" | 68 #include "remoting/host/curtain_mode_mac.h" |
69 #endif // defined(OS_MACOSX) | 69 #endif // defined(OS_MACOSX) |
70 | 70 |
71 #if defined(OS_POSIX) | |
72 #include <signal.h> | |
73 #endif // defined(OS_POSIX) | |
74 | |
75 // N.B. OS_WIN is defined by including src/base headers. | 71 // N.B. OS_WIN is defined by including src/base headers. |
76 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
77 #include <commctrl.h> | 73 #include <commctrl.h> |
78 #include "remoting/host/win/session_desktop_environment_factory.h" | 74 #include "remoting/host/win/session_desktop_environment_factory.h" |
79 #endif // defined(OS_WIN) | 75 #endif // defined(OS_WIN) |
80 | 76 |
81 #if defined(TOOLKIT_GTK) | 77 #if defined(TOOLKIT_GTK) |
82 #include "ui/gfx/gtk_util.h" | 78 #include "ui/gfx/gtk_util.h" |
83 #endif // defined(TOOLKIT_GTK) | 79 #endif // defined(TOOLKIT_GTK) |
84 | 80 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 if (!ApplyConfig()) { | 183 if (!ApplyConfig()) { |
188 LOG(ERROR) << "Failed to apply the configuration."; | 184 LOG(ERROR) << "Failed to apply the configuration."; |
189 OnConfigWatcherError(); | 185 OnConfigWatcherError(); |
190 return; | 186 return; |
191 } | 187 } |
192 | 188 |
193 // Start watching the policy (and eventually start the host) if this is | 189 // Start watching the policy (and eventually start the host) if this is |
194 // the first configuration update. Otherwise, post a task to create new | 190 // the first configuration update. Otherwise, post a task to create new |
195 // authenticator factory in case PIN has changed. | 191 // authenticator factory in case PIN has changed. |
196 if (policy_watcher_.get() == NULL) { | 192 if (policy_watcher_.get() == NULL) { |
197 #if defined(OS_MACOSX) || defined(OS_WIN) | |
198 bool want_user_interface = true; | 193 bool want_user_interface = true; |
199 | 194 #if defined(OS_LINUX) |
200 #if defined(OS_MACOSX) | 195 want_user_interface = false; |
196 #elif defined(OS_MACOSX) | |
201 // Don't try to display any UI on top of the system's login screen as this | 197 // Don't try to display any UI on top of the system's login screen as this |
202 // is rejected by the Window Server on OS X 10.7.4, and prevents the | 198 // is rejected by the Window Server on OS X 10.7.4, and prevents the |
203 // capturer from working (http://crbug.com/140984). | 199 // capturer from working (http://crbug.com/140984). |
204 | 200 |
205 // TODO(lambroslambrou): Use a better technique of detecting whether we're | 201 // TODO(lambroslambrou): Use a better technique of detecting whether we're |
206 // running in the LoginWindow context, and refactor this into a separate | 202 // running in the LoginWindow context, and refactor this into a separate |
207 // function to be used here and in CurtainMode::ActivateCurtain(). | 203 // function to be used here and in CurtainMode::ActivateCurtain(). |
208 if (getuid() == 0) { | 204 want_user_interface = getuid() != 0; |
209 want_user_interface = false; | |
210 } | |
211 #endif // OS_MACOSX | 205 #endif // OS_MACOSX |
212 | 206 |
213 if (want_user_interface) { | 207 if (want_user_interface) { |
214 host_user_interface_.reset(new HostUserInterface(context_.get())); | 208 host_user_interface_.reset(new HostUserInterface(context_.get())); |
215 } | 209 } |
216 #endif // OS_MACOSX || OS_WIN | |
217 | 210 |
218 StartWatchingPolicy(); | 211 StartWatchingPolicy(); |
219 } else { | 212 } else { |
220 // PostTask to create new authenticator factory in case PIN has changed. | 213 // PostTask to create new authenticator factory in case PIN has changed. |
221 context_->network_task_runner()->PostTask( | 214 context_->network_task_runner()->PostTask( |
222 FROM_HERE, | 215 FROM_HERE, |
223 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 216 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
224 base::Unretained(this))); | 217 base::Unretained(this))); |
225 } | 218 } |
226 } | 219 } |
227 | 220 |
228 virtual void OnConfigWatcherError() OVERRIDE { | 221 virtual void OnConfigWatcherError() OVERRIDE { |
229 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 222 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
230 | 223 |
231 context_->network_task_runner()->PostTask( | 224 context_->network_task_runner()->PostTask( |
232 FROM_HERE, | 225 FROM_HERE, |
233 base::Bind(&HostProcess::Shutdown, base::Unretained(this), | 226 base::Bind(&HostProcess::Shutdown, base::Unretained(this), |
234 kInvalidHostConfigurationExitCode)); | 227 kInvalidHostConfigurationExitCode)); |
235 } | 228 } |
236 | 229 |
237 void StartWatchingConfigChanges() { | 230 void StartWatchingConfigChanges() { |
238 #if !defined(REMOTING_MULTI_PROCESS) | 231 #if !defined(REMOTING_MULTI_PROCESS) |
239 | |
240 // Start watching the host configuration file. | 232 // Start watching the host configuration file. |
241 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), | 233 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), |
242 context_->file_task_runner(), | 234 context_->file_task_runner(), |
243 this)); | 235 this)); |
244 config_watcher_->Watch(host_config_path_); | 236 config_watcher_->Watch(host_config_path_); |
245 #endif // !defined(REMOTING_MULTI_PROCESS) | 237 #endif // !defined(REMOTING_MULTI_PROCESS) |
246 } | 238 } |
247 | 239 |
240 void ListenForShutdownSignal() { | |
248 #if defined(OS_POSIX) | 241 #if defined(OS_POSIX) |
249 void ListenForShutdownSignal() { | |
250 remoting::RegisterSignalHandler( | 242 remoting::RegisterSignalHandler( |
251 SIGTERM, | 243 SIGTERM, |
252 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); | 244 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); |
245 #endif // OS_POSIX | |
253 } | 246 } |
254 #endif // OS_POSIX | |
255 | 247 |
256 void CreateAuthenticatorFactory() { | 248 void CreateAuthenticatorFactory() { |
257 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 249 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
258 | 250 |
259 std::string local_certificate = key_pair_.GenerateCertificate(); | 251 std::string local_certificate = key_pair_.GenerateCertificate(); |
260 if (local_certificate.empty()) { | 252 if (local_certificate.empty()) { |
261 LOG(ERROR) << "Failed to generate host certificate."; | 253 LOG(ERROR) << "Failed to generate host certificate."; |
262 Shutdown(kHostInitializationFailed); | 254 Shutdown(kHostInitializationFailed); |
263 return; | 255 return; |
264 } | 256 } |
(...skipping 22 matching lines...) Expand all Loading... | |
287 } | 279 } |
288 | 280 |
289 void StartHostProcess() { | 281 void StartHostProcess() { |
290 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 282 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
291 | 283 |
292 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 284 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
293 OnConfigWatcherError(); | 285 OnConfigWatcherError(); |
294 return; | 286 return; |
295 } | 287 } |
296 | 288 |
297 #if defined(OS_POSIX) | |
298 context_->network_task_runner()->PostTask( | 289 context_->network_task_runner()->PostTask( |
299 FROM_HERE, | 290 FROM_HERE, |
300 base::Bind(&HostProcess::ListenForShutdownSignal, | 291 base::Bind(&HostProcess::ListenForShutdownSignal, |
301 base::Unretained(this))); | 292 base::Unretained(this))); |
302 #endif // OS_POSIX | |
303 | 293 |
304 StartWatchingConfigChanges(); | 294 StartWatchingConfigChanges(); |
305 } | 295 } |
306 | 296 |
307 int get_exit_code() const { return exit_code_; } | 297 int get_exit_code() const { return exit_code_; } |
308 | 298 |
309 private: | 299 private: |
310 void ShutdownHostProcess() { | 300 void ShutdownHostProcess() { |
311 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 301 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
312 | 302 |
313 #if !defined(REMOTING_MULTI_PROCESS) | |
alexeypa (please no reviews)
2012/09/14 15:45:26
This #if should stay. It is needed for multi-proce
Sergey Ulanov
2012/09/14 17:35:02
Right, it's just we never create config_watcher_ a
| |
314 config_watcher_.reset(); | 303 config_watcher_.reset(); |
315 #endif // !defined(REMOTING_MULTI_PROCESS) | |
316 | 304 |
317 daemon_channel_.reset(); | 305 daemon_channel_.reset(); |
318 | |
319 #if defined(OS_MACOSX) || defined(OS_WIN) | |
320 host_user_interface_.reset(); | 306 host_user_interface_.reset(); |
321 #endif | |
322 | 307 |
323 if (policy_watcher_.get()) { | 308 if (policy_watcher_.get()) { |
324 base::WaitableEvent done_event(true, false); | 309 base::WaitableEvent done_event(true, false); |
325 policy_watcher_->StopWatching(&done_event); | 310 policy_watcher_->StopWatching(&done_event); |
326 done_event.Wait(); | 311 done_event.Wait(); |
327 policy_watcher_.reset(); | 312 policy_watcher_.reset(); |
328 } | 313 } |
329 | 314 |
330 context_.reset(); | 315 context_.reset(); |
331 } | 316 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); | 555 host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20)); |
571 #endif | 556 #endif |
572 | 557 |
573 heartbeat_sender_.reset(new HeartbeatSender( | 558 heartbeat_sender_.reset(new HeartbeatSender( |
574 this, host_id_, signal_strategy_.get(), &key_pair_)); | 559 this, host_id_, signal_strategy_.get(), &key_pair_)); |
575 | 560 |
576 log_to_server_.reset( | 561 log_to_server_.reset( |
577 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 562 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); |
578 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); | 563 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); |
579 | 564 |
580 #if defined(OS_MACOSX) || defined(OS_WIN) | |
581 if (host_user_interface_.get()) { | 565 if (host_user_interface_.get()) { |
582 host_user_interface_->Start( | 566 host_user_interface_->Start( |
583 host_, base::Bind(&HostProcess::OnDisconnectRequested, | 567 host_, base::Bind(&HostProcess::OnDisconnectRequested, |
584 base::Unretained(this))); | 568 base::Unretained(this))); |
585 } | 569 } |
586 #endif | |
587 | 570 |
588 host_->Start(xmpp_login_); | 571 host_->Start(xmpp_login_); |
589 | 572 |
590 CreateAuthenticatorFactory(); | 573 CreateAuthenticatorFactory(); |
591 } | 574 } |
592 | 575 |
593 void OnAuthFailed() { | 576 void OnAuthFailed() { |
594 Shutdown(kInvalidOauthCredentialsExitCode); | 577 Shutdown(kInvalidOauthCredentialsExitCode); |
595 } | 578 } |
596 | 579 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 heartbeat_sender_.reset(); | 647 heartbeat_sender_.reset(); |
665 signaling_connector_.reset(); | 648 signaling_connector_.reset(); |
666 signal_strategy_.reset(); | 649 signal_strategy_.reset(); |
667 } | 650 } |
668 | 651 |
669 scoped_ptr<ChromotingHostContext> context_; | 652 scoped_ptr<ChromotingHostContext> context_; |
670 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 653 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
671 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 654 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
672 | 655 |
673 JsonHostConfig config_; | 656 JsonHostConfig config_; |
674 #if !defined(REMOTING_MULTI_PROCESS) | |
alexeypa (please no reviews)
2012/09/14 15:45:26
This #if should stay. It is needed for multi-proce
Sergey Ulanov
2012/09/14 17:35:02
Same here. This change doesn't mean we actually wa
| |
675 FilePath host_config_path_; | 657 FilePath host_config_path_; |
676 scoped_ptr<ConfigFileWatcher> config_watcher_; | 658 scoped_ptr<ConfigFileWatcher> config_watcher_; |
677 #endif // !defined(REMOTING_MULTI_PROCESS) | |
678 | 659 |
679 std::string host_id_; | 660 std::string host_id_; |
680 HostKeyPair key_pair_; | 661 HostKeyPair key_pair_; |
681 protocol::SharedSecretHash host_secret_hash_; | 662 protocol::SharedSecretHash host_secret_hash_; |
682 std::string xmpp_login_; | 663 std::string xmpp_login_; |
683 std::string xmpp_auth_token_; | 664 std::string xmpp_auth_token_; |
684 std::string xmpp_auth_service_; | 665 std::string xmpp_auth_service_; |
685 | 666 |
686 std::string oauth_refresh_token_; | 667 std::string oauth_refresh_token_; |
687 bool oauth_use_official_client_id_; | 668 bool oauth_use_official_client_id_; |
688 | 669 |
689 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 670 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
690 bool allow_nat_traversal_; | 671 bool allow_nat_traversal_; |
691 std::string talkgadget_prefix_; | 672 std::string talkgadget_prefix_; |
692 | 673 |
693 bool restarting_; | 674 bool restarting_; |
694 bool shutting_down_; | 675 bool shutting_down_; |
695 | 676 |
696 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 677 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
697 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 678 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
698 scoped_ptr<SignalingConnector> signaling_connector_; | 679 scoped_ptr<SignalingConnector> signaling_connector_; |
699 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 680 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
700 scoped_ptr<LogToServer> log_to_server_; | 681 scoped_ptr<LogToServer> log_to_server_; |
701 scoped_ptr<HostEventLogger> host_event_logger_; | 682 scoped_ptr<HostEventLogger> host_event_logger_; |
702 | 683 |
703 #if defined(OS_MACOSX) || defined(OS_WIN) | |
704 scoped_ptr<HostUserInterface> host_user_interface_; | 684 scoped_ptr<HostUserInterface> host_user_interface_; |
705 #endif | |
706 | 685 |
707 scoped_refptr<ChromotingHost> host_; | 686 scoped_refptr<ChromotingHost> host_; |
708 | 687 |
709 int exit_code_; | 688 int exit_code_; |
710 | 689 |
711 #if defined(OS_MACOSX) | 690 #if defined(OS_MACOSX) |
712 remoting::CurtainMode curtain_; | 691 remoting::CurtainMode curtain_; |
713 #endif | 692 #endif |
714 }; | 693 }; |
715 | 694 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
813 user32.GetFunctionPointer("SetProcessDPIAware")); | 792 user32.GetFunctionPointer("SetProcessDPIAware")); |
814 set_process_dpi_aware(); | 793 set_process_dpi_aware(); |
815 } | 794 } |
816 | 795 |
817 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 796 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
818 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 797 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
819 return main(0, NULL); | 798 return main(0, NULL); |
820 } | 799 } |
821 | 800 |
822 #endif // defined(OS_WIN) | 801 #endif // defined(OS_WIN) |
OLD | NEW |