Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 10913260: Cleanups in Chromoting Host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/plugin/daemon_installer_win.cc ('k') | remoting/host/signaling_connector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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/desktop_resizer.h" 42 #include "remoting/host/desktop_resizer.h"
44 #include "remoting/host/dns_blackhole_checker.h" 43 #include "remoting/host/dns_blackhole_checker.h"
45 #include "remoting/host/event_executor.h" 44 #include "remoting/host/event_executor.h"
46 #include "remoting/host/heartbeat_sender.h" 45 #include "remoting/host/heartbeat_sender.h"
47 #include "remoting/host/host_config.h" 46 #include "remoting/host/host_config.h"
48 #include "remoting/host/host_event_logger.h" 47 #include "remoting/host/host_event_logger.h"
48 #include "remoting/host/host_exit_codes.h"
49 #include "remoting/host/host_user_interface.h" 49 #include "remoting/host/host_user_interface.h"
50 #include "remoting/host/json_host_config.h" 50 #include "remoting/host/json_host_config.h"
51 #include "remoting/host/log_to_server.h" 51 #include "remoting/host/log_to_server.h"
52 #include "remoting/host/network_settings.h" 52 #include "remoting/host/network_settings.h"
53 #include "remoting/host/policy_hack/policy_watcher.h" 53 #include "remoting/host/policy_hack/policy_watcher.h"
54 #include "remoting/host/resizing_host_observer.h" 54 #include "remoting/host/resizing_host_observer.h"
55 #include "remoting/host/session_manager_factory.h" 55 #include "remoting/host/session_manager_factory.h"
56 #include "remoting/host/signaling_connector.h" 56 #include "remoting/host/signaling_connector.h"
57 #include "remoting/host/usage_stats_consent.h" 57 #include "remoting/host/usage_stats_consent.h"
58 #include "remoting/host/video_frame_capturer.h" 58 #include "remoting/host/video_frame_capturer.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if (!ApplyConfig()) { 194 if (!ApplyConfig()) {
195 LOG(ERROR) << "Failed to apply the configuration."; 195 LOG(ERROR) << "Failed to apply the configuration.";
196 OnConfigWatcherError(); 196 OnConfigWatcherError();
197 return; 197 return;
198 } 198 }
199 199
200 // Start watching the policy (and eventually start the host) if this is 200 // Start watching the policy (and eventually start the host) if this is
201 // the first configuration update. Otherwise, post a task to create new 201 // the first configuration update. Otherwise, post a task to create new
202 // authenticator factory in case PIN has changed. 202 // authenticator factory in case PIN has changed.
203 if (policy_watcher_.get() == NULL) { 203 if (policy_watcher_.get() == NULL) {
204 #if defined(OS_MACOSX) || defined(OS_WIN)
205 bool want_user_interface = true; 204 bool want_user_interface = true;
206 205 #if defined(OS_LINUX)
207 #if defined(OS_MACOSX) 206 want_user_interface = false;
207 #elif defined(OS_MACOSX)
208 // Don't try to display any UI on top of the system's login screen as this 208 // Don't try to display any UI on top of the system's login screen as this
209 // is rejected by the Window Server on OS X 10.7.4, and prevents the 209 // is rejected by the Window Server on OS X 10.7.4, and prevents the
210 // capturer from working (http://crbug.com/140984). 210 // capturer from working (http://crbug.com/140984).
211 211
212 // TODO(lambroslambrou): Use a better technique of detecting whether we're 212 // TODO(lambroslambrou): Use a better technique of detecting whether we're
213 // running in the LoginWindow context, and refactor this into a separate 213 // running in the LoginWindow context, and refactor this into a separate
214 // function to be used here and in CurtainMode::ActivateCurtain(). 214 // function to be used here and in CurtainMode::ActivateCurtain().
215 if (getuid() == 0) { 215 want_user_interface = getuid() != 0;
216 want_user_interface = false;
217 }
218 #endif // OS_MACOSX 216 #endif // OS_MACOSX
219 217
220 if (want_user_interface) { 218 if (want_user_interface) {
221 host_user_interface_.reset(new HostUserInterface(context_.get())); 219 host_user_interface_.reset(new HostUserInterface(context_.get()));
222 } 220 }
223 #endif // OS_MACOSX || OS_WIN
224 221
225 StartWatchingPolicy(); 222 StartWatchingPolicy();
226 } else { 223 } else {
227 // PostTask to create new authenticator factory in case PIN has changed. 224 // PostTask to create new authenticator factory in case PIN has changed.
228 context_->network_task_runner()->PostTask( 225 context_->network_task_runner()->PostTask(
229 FROM_HERE, 226 FROM_HERE,
230 base::Bind(&HostProcess::CreateAuthenticatorFactory, 227 base::Bind(&HostProcess::CreateAuthenticatorFactory,
231 base::Unretained(this))); 228 base::Unretained(this)));
232 } 229 }
233 } 230 }
234 231
235 virtual void OnConfigWatcherError() OVERRIDE { 232 virtual void OnConfigWatcherError() OVERRIDE {
236 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 233 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
237 234
238 context_->network_task_runner()->PostTask( 235 context_->network_task_runner()->PostTask(
239 FROM_HERE, 236 FROM_HERE,
240 base::Bind(&HostProcess::Shutdown, base::Unretained(this), 237 base::Bind(&HostProcess::Shutdown, base::Unretained(this),
241 kInvalidHostConfigurationExitCode)); 238 kInvalidHostConfigurationExitCode));
242 } 239 }
243 240
244 void StartWatchingConfigChanges() { 241 void StartWatchingConfigChanges() {
245 #if !defined(REMOTING_MULTI_PROCESS) 242 #if !defined(REMOTING_MULTI_PROCESS)
246
247 // Start watching the host configuration file. 243 // Start watching the host configuration file.
248 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(), 244 config_watcher_.reset(new ConfigFileWatcher(context_->ui_task_runner(),
249 context_->file_task_runner(), 245 context_->file_task_runner(),
250 this)); 246 this));
251 config_watcher_->Watch(host_config_path_); 247 config_watcher_->Watch(host_config_path_);
252 #endif // !defined(REMOTING_MULTI_PROCESS) 248 #endif // !defined(REMOTING_MULTI_PROCESS)
253 } 249 }
254 250
251 void ListenForShutdownSignal() {
255 #if defined(OS_POSIX) 252 #if defined(OS_POSIX)
256 void ListenForShutdownSignal() {
257 remoting::RegisterSignalHandler( 253 remoting::RegisterSignalHandler(
258 SIGTERM, 254 SIGTERM,
259 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this))); 255 base::Bind(&HostProcess::SigTermHandler, base::Unretained(this)));
256 #endif // OS_POSIX
260 } 257 }
261 #endif // OS_POSIX
262 258
263 void CreateAuthenticatorFactory() { 259 void CreateAuthenticatorFactory() {
264 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); 260 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
265 261
266 std::string local_certificate = key_pair_.GenerateCertificate(); 262 std::string local_certificate = key_pair_.GenerateCertificate();
267 if (local_certificate.empty()) { 263 if (local_certificate.empty()) {
268 LOG(ERROR) << "Failed to generate host certificate."; 264 LOG(ERROR) << "Failed to generate host certificate.";
269 Shutdown(kHostInitializationFailed); 265 Shutdown(kHostInitializationFailed);
270 return; 266 return;
271 } 267 }
(...skipping 22 matching lines...) Expand all
294 } 290 }
295 291
296 void StartHostProcess() { 292 void StartHostProcess() {
297 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 293 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
298 294
299 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { 295 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) {
300 OnConfigWatcherError(); 296 OnConfigWatcherError();
301 return; 297 return;
302 } 298 }
303 299
304 #if defined(OS_POSIX)
305 context_->network_task_runner()->PostTask( 300 context_->network_task_runner()->PostTask(
306 FROM_HERE, 301 FROM_HERE,
307 base::Bind(&HostProcess::ListenForShutdownSignal, 302 base::Bind(&HostProcess::ListenForShutdownSignal,
308 base::Unretained(this))); 303 base::Unretained(this)));
309 #endif // OS_POSIX
310 304
311 StartWatchingConfigChanges(); 305 StartWatchingConfigChanges();
312 } 306 }
313 307
314 int get_exit_code() const { return exit_code_; } 308 int get_exit_code() const { return exit_code_; }
315 309
316 private: 310 private:
317 void ShutdownHostProcess() { 311 void ShutdownHostProcess() {
318 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); 312 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
319 313
320 #if !defined(REMOTING_MULTI_PROCESS)
321 config_watcher_.reset(); 314 config_watcher_.reset();
322 #endif // !defined(REMOTING_MULTI_PROCESS)
323 315
324 daemon_channel_.reset(); 316 daemon_channel_.reset();
325
326 #if defined(OS_MACOSX) || defined(OS_WIN)
327 host_user_interface_.reset(); 317 host_user_interface_.reset();
328 #endif
329 318
330 if (policy_watcher_.get()) { 319 if (policy_watcher_.get()) {
331 base::WaitableEvent done_event(true, false); 320 base::WaitableEvent done_event(true, false);
332 policy_watcher_->StopWatching(&done_event); 321 policy_watcher_->StopWatching(&done_event);
333 done_event.Wait(); 322 done_event.Wait();
334 policy_watcher_.reset(); 323 policy_watcher_.reset();
335 } 324 }
336 325
337 context_.reset(); 326 context_.reset();
338 } 327 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 heartbeat_sender_.reset(new HeartbeatSender( 571 heartbeat_sender_.reset(new HeartbeatSender(
583 this, host_id_, signal_strategy_.get(), &key_pair_)); 572 this, host_id_, signal_strategy_.get(), &key_pair_));
584 573
585 log_to_server_.reset( 574 log_to_server_.reset(
586 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); 575 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get()));
587 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 576 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
588 577
589 resizing_host_observer_.reset( 578 resizing_host_observer_.reset(
590 new ResizingHostObserver(desktop_resizer_.get(), host_)); 579 new ResizingHostObserver(desktop_resizer_.get(), host_));
591 580
592 #if defined(OS_MACOSX) || defined(OS_WIN)
593 if (host_user_interface_.get()) { 581 if (host_user_interface_.get()) {
594 host_user_interface_->Start( 582 host_user_interface_->Start(
595 host_, base::Bind(&HostProcess::OnDisconnectRequested, 583 host_, base::Bind(&HostProcess::OnDisconnectRequested,
596 base::Unretained(this))); 584 base::Unretained(this)));
597 } 585 }
598 #endif
599 586
600 host_->Start(xmpp_login_); 587 host_->Start(xmpp_login_);
601 588
602 CreateAuthenticatorFactory(); 589 CreateAuthenticatorFactory();
603 } 590 }
604 591
605 void OnAuthFailed() { 592 void OnAuthFailed() {
606 Shutdown(kInvalidOauthCredentialsExitCode); 593 Shutdown(kInvalidOauthCredentialsExitCode);
607 } 594 }
608 595
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 signaling_connector_.reset(); 669 signaling_connector_.reset();
683 signal_strategy_.reset(); 670 signal_strategy_.reset();
684 resizing_host_observer_.reset(); 671 resizing_host_observer_.reset();
685 } 672 }
686 673
687 scoped_ptr<ChromotingHostContext> context_; 674 scoped_ptr<ChromotingHostContext> context_;
688 scoped_ptr<IPC::ChannelProxy> daemon_channel_; 675 scoped_ptr<IPC::ChannelProxy> daemon_channel_;
689 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 676 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
690 677
691 JsonHostConfig config_; 678 JsonHostConfig config_;
692 #if !defined(REMOTING_MULTI_PROCESS)
693 FilePath host_config_path_; 679 FilePath host_config_path_;
694 scoped_ptr<ConfigFileWatcher> config_watcher_; 680 scoped_ptr<ConfigFileWatcher> config_watcher_;
695 #endif // !defined(REMOTING_MULTI_PROCESS)
696 681
697 std::string host_id_; 682 std::string host_id_;
698 HostKeyPair key_pair_; 683 HostKeyPair key_pair_;
699 protocol::SharedSecretHash host_secret_hash_; 684 protocol::SharedSecretHash host_secret_hash_;
700 std::string xmpp_login_; 685 std::string xmpp_login_;
701 std::string xmpp_auth_token_; 686 std::string xmpp_auth_token_;
702 std::string xmpp_auth_service_; 687 std::string xmpp_auth_service_;
703 688
704 std::string oauth_refresh_token_; 689 std::string oauth_refresh_token_;
705 bool oauth_use_official_client_id_; 690 bool oauth_use_official_client_id_;
706 691
707 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; 692 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
708 bool allow_nat_traversal_; 693 bool allow_nat_traversal_;
709 std::string talkgadget_prefix_; 694 std::string talkgadget_prefix_;
710 695
711 bool restarting_; 696 bool restarting_;
712 bool shutting_down_; 697 bool shutting_down_;
713 698
714 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; 699 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
715 scoped_ptr<DesktopResizer> desktop_resizer_; 700 scoped_ptr<DesktopResizer> desktop_resizer_;
716 scoped_ptr<ResizingHostObserver> resizing_host_observer_; 701 scoped_ptr<ResizingHostObserver> resizing_host_observer_;
717 scoped_ptr<XmppSignalStrategy> signal_strategy_; 702 scoped_ptr<XmppSignalStrategy> signal_strategy_;
718 scoped_ptr<SignalingConnector> signaling_connector_; 703 scoped_ptr<SignalingConnector> signaling_connector_;
719 scoped_ptr<HeartbeatSender> heartbeat_sender_; 704 scoped_ptr<HeartbeatSender> heartbeat_sender_;
720 scoped_ptr<LogToServer> log_to_server_; 705 scoped_ptr<LogToServer> log_to_server_;
721 scoped_ptr<HostEventLogger> host_event_logger_; 706 scoped_ptr<HostEventLogger> host_event_logger_;
722 707
723 #if defined(OS_MACOSX) || defined(OS_WIN)
724 scoped_ptr<HostUserInterface> host_user_interface_; 708 scoped_ptr<HostUserInterface> host_user_interface_;
725 #endif
726 709
727 scoped_refptr<ChromotingHost> host_; 710 scoped_refptr<ChromotingHost> host_;
728 711
729 int exit_code_; 712 int exit_code_;
730 713
731 #if defined(OS_MACOSX) 714 #if defined(OS_MACOSX)
732 remoting::CurtainMode curtain_; 715 remoting::CurtainMode curtain_;
733 #endif // defined(OS_MACOSX) 716 #endif // defined(OS_MACOSX)
734 }; 717 };
735 718
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 user32.GetFunctionPointer("SetProcessDPIAware")); 821 user32.GetFunctionPointer("SetProcessDPIAware"));
839 set_process_dpi_aware(); 822 set_process_dpi_aware();
840 } 823 }
841 824
842 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 825 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
843 // the command line from GetCommandLineW(), so we can safely pass NULL here. 826 // the command line from GetCommandLineW(), so we can safely pass NULL here.
844 return main(0, NULL); 827 return main(0, NULL);
845 } 828 }
846 829
847 #endif // defined(OS_WIN) 830 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « remoting/host/plugin/daemon_installer_win.cc ('k') | remoting/host/signaling_connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698