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

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

Issue 10384127: Chromoting: the Me2me host now presents a notification on the console allowing a user to disconnect… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
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 #if defined(OS_WIN)
8 #include <windows.h>
9 #endif
10
11 #include <string> 7 #include <string>
12 8
13 #include "base/at_exit.h" 9 #include "base/at_exit.h"
14 #include "base/bind.h" 10 #include "base/bind.h"
15 #include "base/callback.h" 11 #include "base/callback.h"
16 #include "base/command_line.h" 12 #include "base/command_line.h"
17 #include "base/file_path.h" 13 #include "base/file_path.h"
18 #include "base/file_util.h" 14 #include "base/file_util.h"
19 #include "base/files/file_path_watcher.h" 15 #include "base/files/file_path_watcher.h"
20 #include "base/logging.h" 16 #include "base/logging.h"
21 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
22 #include "base/message_loop.h" 18 #include "base/message_loop.h"
23 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
24 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
25 #include "build/build_config.h" 21 #include "build/build_config.h"
26 #include "crypto/nss_util.h" 22 #include "crypto/nss_util.h"
27 #include "net/base/network_change_notifier.h" 23 #include "net/base/network_change_notifier.h"
28 #include "remoting/base/constants.h" 24 #include "remoting/base/constants.h"
29 #include "remoting/host/branding.h" 25 #include "remoting/host/branding.h"
30 #include "remoting/host/constants.h" 26 #include "remoting/host/constants.h"
31 #include "remoting/host/capturer.h" 27 #include "remoting/host/capturer.h"
32 #include "remoting/host/chromoting_host.h" 28 #include "remoting/host/chromoting_host.h"
33 #include "remoting/host/chromoting_host_context.h" 29 #include "remoting/host/chromoting_host_context.h"
34 #include "remoting/host/desktop_environment.h" 30 #include "remoting/host/desktop_environment.h"
35 #include "remoting/host/event_executor.h" 31 #include "remoting/host/event_executor.h"
36 #include "remoting/host/heartbeat_sender.h" 32 #include "remoting/host/heartbeat_sender.h"
37 #include "remoting/host/host_config.h" 33 #include "remoting/host/host_config.h"
38 #include "remoting/host/host_event_logger.h" 34 #include "remoting/host/host_event_logger.h"
35 #include "remoting/host/host_user_interface.h"
39 #include "remoting/host/json_host_config.h" 36 #include "remoting/host/json_host_config.h"
40 #include "remoting/host/log_to_server.h" 37 #include "remoting/host/log_to_server.h"
41 #include "remoting/host/policy_hack/nat_policy.h" 38 #include "remoting/host/policy_hack/nat_policy.h"
42 #include "remoting/host/signaling_connector.h" 39 #include "remoting/host/signaling_connector.h"
43 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 40 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
44 #include "remoting/protocol/me2me_host_authenticator_factory.h" 41 #include "remoting/protocol/me2me_host_authenticator_factory.h"
45 42
46 #if defined(OS_MACOSX) 43 #if defined(OS_MACOSX)
47 #include "remoting/host/sighup_listener_mac.h" 44 #include "remoting/host/sighup_listener_mac.h"
48 #endif 45 #endif
46 // N.B. OS_WIN is defined by including src/base headers.
47 #if defined(OS_WIN)
48 #include <commctrl.h>
49 #endif
49 #if defined(TOOLKIT_GTK) 50 #if defined(TOOLKIT_GTK)
50 #include "ui/gfx/gtk_util.h" 51 #include "ui/gfx/gtk_util.h"
51 #endif 52 #endif
52 53
53 namespace { 54 namespace {
54 55
55 // This is used for tagging system event logs. 56 // This is used for tagging system event logs.
56 const char kApplicationName[] = "chromoting"; 57 const char kApplicationName[] = "chromoting";
57 58
58 // These are used for parsing the config-file locations from the command line, 59 // These are used for parsing the config-file locations from the command line,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 xmpp_login_, key_pair_.GenerateCertificate(), 192 xmpp_login_, key_pair_.GenerateCertificate(),
192 *key_pair_.private_key(), host_secret_hash_)); 193 *key_pair_.private_key(), host_secret_hash_));
193 host_->SetAuthenticatorFactory(factory.Pass()); 194 host_->SetAuthenticatorFactory(factory.Pass());
194 } 195 }
195 196
196 int Run() { 197 int Run() {
197 if (!LoadConfig()) { 198 if (!LoadConfig()) {
198 return kInvalidHostConfigurationExitCode; 199 return kInvalidHostConfigurationExitCode;
199 } 200 }
200 201
202 #if defined(OS_WIN)
203 host_user_interface_.reset(new HostUserInterface(context_.get()));
204 #endif
205
201 StartWatchingNatPolicy(); 206 StartWatchingNatPolicy();
202 207
203 #if defined(OS_MACOSX) || defined(OS_WIN) 208 #if defined(OS_MACOSX) || defined(OS_WIN)
204 context_->file_message_loop()->PostTask( 209 context_->file_message_loop()->PostTask(
205 FROM_HERE, 210 FROM_HERE,
206 base::Bind(&HostProcess::ListenForConfigChanges, 211 base::Bind(&HostProcess::ListenForConfigChanges,
207 base::Unretained(this))); 212 base::Unretained(this)));
208 #endif 213 #endif
209 message_loop_.Run(); 214 message_loop_.Run();
210 215
216 #if defined(OS_WIN)
217 host_user_interface_.reset();
218 #endif
219
211 base::WaitableEvent done_event(true, false); 220 base::WaitableEvent done_event(true, false);
212 nat_policy_->StopWatching(&done_event); 221 nat_policy_->StopWatching(&done_event);
213 done_event.Wait(); 222 done_event.Wait();
214 nat_policy_.reset(); 223 nat_policy_.reset();
215 224
216 return exit_code_; 225 return exit_code_;
217 } 226 }
218 227
219 // Overridden from HeartbeatSender::Listener 228 // Overridden from HeartbeatSender::Listener
220 virtual void OnUnknownHostIdError() OVERRIDE { 229 virtual void OnUnknownHostIdError() OVERRIDE {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 context_.get(), signal_strategy_.get(), desktop_environment_.get(), 383 context_.get(), signal_strategy_.get(), desktop_environment_.get(),
375 network_settings); 384 network_settings);
376 385
377 heartbeat_sender_.reset(new HeartbeatSender( 386 heartbeat_sender_.reset(new HeartbeatSender(
378 this, host_id_, signal_strategy_.get(), &key_pair_)); 387 this, host_id_, signal_strategy_.get(), &key_pair_));
379 388
380 log_to_server_.reset( 389 log_to_server_.reset(
381 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); 390 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get()));
382 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 391 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
383 392
393 #if defined(OS_WIN)
394 host_user_interface_->Start(
395 host_,
396 base::Bind(&HostProcess::OnRestartHostRequest, base::Unretained(this)));
397 #endif
398
384 host_->Start(); 399 host_->Start();
385 400
386 CreateAuthenticatorFactory(); 401 CreateAuthenticatorFactory();
387 } 402 }
388 403
389 void OnOAuthFailed() { 404 void OnOAuthFailed() {
390 Shutdown(kInvalidOauthCredentialsExitCode); 405 Shutdown(kInvalidOauthCredentialsExitCode);
391 } 406 }
392 407
408 // Invoked from when the user uses the Disconnect windows to terminate
409 // the sessions.
410 void OnRestartHostRequest() {
411 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
412
413 context_->network_message_loop()->PostTask(
414 FROM_HERE,
415 base::Bind(&HostProcess::RestartHost, base::Unretained(this)));
416 }
417
393 void RestartHost() { 418 void RestartHost() {
394 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); 419 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
395 420
396 if (restarting_ || shutting_down_) 421 if (restarting_ || shutting_down_)
397 return; 422 return;
398 423
399 restarting_ = true; 424 restarting_ = true;
400 host_->Shutdown(base::Bind( 425 host_->Shutdown(base::Bind(
401 &HostProcess::RestartOnHostShutdown, base::Unretained(this))); 426 &HostProcess::RestartOnHostShutdown, base::Unretained(this)));
402 } 427 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 491
467 bool restarting_; 492 bool restarting_;
468 bool shutting_down_; 493 bool shutting_down_;
469 494
470 scoped_ptr<XmppSignalStrategy> signal_strategy_; 495 scoped_ptr<XmppSignalStrategy> signal_strategy_;
471 scoped_ptr<SignalingConnector> signaling_connector_; 496 scoped_ptr<SignalingConnector> signaling_connector_;
472 scoped_ptr<DesktopEnvironment> desktop_environment_; 497 scoped_ptr<DesktopEnvironment> desktop_environment_;
473 scoped_ptr<HeartbeatSender> heartbeat_sender_; 498 scoped_ptr<HeartbeatSender> heartbeat_sender_;
474 scoped_ptr<LogToServer> log_to_server_; 499 scoped_ptr<LogToServer> log_to_server_;
475 scoped_ptr<HostEventLogger> host_event_logger_; 500 scoped_ptr<HostEventLogger> host_event_logger_;
501
502 #if defined(OS_WIN)
503 scoped_ptr<HostUserInterface> host_user_interface_;
504 #endif
505
476 scoped_refptr<ChromotingHost> host_; 506 scoped_refptr<ChromotingHost> host_;
477 507
478 int exit_code_; 508 int exit_code_;
479 }; 509 };
480 510
481 } // namespace remoting 511 } // namespace remoting
482 512
483 int main(int argc, char** argv) { 513 int main(int argc, char** argv) {
484 CommandLine::Init(argc, argv); 514 CommandLine::Init(argc, argv);
485 515
(...skipping 24 matching lines...) Expand all
510 gfx::GtkInitFromCommandLine(*cmd_line); 540 gfx::GtkInitFromCommandLine(*cmd_line);
511 #endif // TOOLKIT_GTK 541 #endif // TOOLKIT_GTK
512 542
513 remoting::HostProcess me2me_host; 543 remoting::HostProcess me2me_host;
514 me2me_host.InitWithCommandLine(cmd_line); 544 me2me_host.InitWithCommandLine(cmd_line);
515 545
516 return me2me_host.Run(); 546 return me2me_host.Run();
517 } 547 }
518 548
519 #if defined(OS_WIN) 549 #if defined(OS_WIN)
550 HMODULE g_hModule = NULL;
520 551
521 int CALLBACK WinMain(HINSTANCE instance, 552 int CALLBACK WinMain(HINSTANCE instance,
522 HINSTANCE previous_instance, 553 HINSTANCE previous_instance,
523 LPSTR command_line, 554 LPSTR command_line,
524 int show_command) { 555 int show_command) {
556 g_hModule = instance;
557
558 // Register and initialize common controls.
559 INITCOMMONCONTROLSEX info;
560 info.dwSize = sizeof(info);
561 info.dwICC = ICC_STANDARD_CLASSES;
562 InitCommonControlsEx(&info);
563
525 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 564 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
526 // the command line from GetCommandLineW(), so we can safely pass NULL here. 565 // the command line from GetCommandLineW(), so we can safely pass NULL here.
527 return main(0, NULL); 566 return main(0, NULL);
528 } 567 }
529 568
530 #endif // defined(OS_WIN) 569 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698