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 the Windows service controlling Me2Me host processes | 5 // This file implements the Windows service controlling Me2Me host processes |
6 // running within user sessions. | 6 // running within user sessions. |
7 | 7 |
8 #include "remoting/host/win/host_service.h" | 8 #include "remoting/host/win/host_service.h" |
9 | 9 |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <shellapi.h> | 11 #include <shellapi.h> |
12 #include <wtsapi32.h> | 12 #include <wtsapi32.h> |
13 | 13 |
| 14 #include "base/at_exit.h" |
14 #include "base/base_paths.h" | 15 #include "base/base_paths.h" |
15 #include "base/base_switches.h" | 16 #include "base/base_switches.h" |
16 #include "base/bind.h" | 17 #include "base/bind.h" |
17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
18 #include "base/file_path.h" | 19 #include "base/file_path.h" |
19 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
20 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
21 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/stringprintf.h" |
22 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 25 #include "base/utf_string_conversions.h" |
23 #include "base/win/wrapped_window_proc.h" | 26 #include "base/win/wrapped_window_proc.h" |
24 #include "remoting/base/auto_thread.h" | 27 #include "remoting/base/auto_thread.h" |
| 28 #include "remoting/base/breakpad.h" |
25 #include "remoting/base/scoped_sc_handle_win.h" | 29 #include "remoting/base/scoped_sc_handle_win.h" |
26 #include "remoting/base/stoppable.h" | 30 #include "remoting/base/stoppable.h" |
27 #include "remoting/host/branding.h" | 31 #include "remoting/host/branding.h" |
28 #include "remoting/host/host_exit_codes.h" | 32 #include "remoting/host/host_exit_codes.h" |
29 #include "remoting/host/logging.h" | 33 #include "remoting/host/logging.h" |
30 | 34 |
31 #if defined(REMOTING_MULTI_PROCESS) | 35 #if defined(REMOTING_MULTI_PROCESS) |
32 #include "remoting/host/daemon_process.h" | 36 #include "remoting/host/daemon_process.h" |
33 #endif // defined(REMOTING_MULTI_PROCESS) | 37 #endif // defined(REMOTING_MULTI_PROCESS) |
34 | 38 |
35 #include "remoting/host/win/core_resource.h" | 39 #include "remoting/host/usage_stats_consent.h" |
| 40 #include "remoting/host/win/host_service_resource.h" |
36 #include "remoting/host/win/wts_console_observer.h" | 41 #include "remoting/host/win/wts_console_observer.h" |
37 | 42 |
38 #if !defined(REMOTING_MULTI_PROCESS) | 43 #if !defined(REMOTING_MULTI_PROCESS) |
39 #include "remoting/host/win/wts_console_session_process_driver.h" | 44 #include "remoting/host/win/wts_console_session_process_driver.h" |
40 #endif // !defined(REMOTING_MULTI_PROCESS) | 45 #endif // !defined(REMOTING_MULTI_PROCESS) |
41 | 46 |
| 47 using base::StringPrintf; |
| 48 |
42 namespace { | 49 namespace { |
43 | 50 |
44 // Session id that does not represent any session. | 51 // Session id that does not represent any session. |
45 const uint32 kInvalidSessionId = 0xffffffffu; | 52 const uint32 kInvalidSessionId = 0xffffffffu; |
46 | 53 |
47 const char kIoThreadName[] = "I/O thread"; | 54 const char kIoThreadName[] = "I/O thread"; |
48 | 55 |
49 // A window class for the session change notifications window. | 56 // A window class for the session change notifications window. |
50 const wchar_t kSessionNotificationWindowClass[] = | 57 const wchar_t kSessionNotificationWindowClass[] = |
51 L"Chromoting_SessionNotificationWindow"; | 58 L"Chromoting_SessionNotificationWindow"; |
52 | 59 |
53 // Command line switches: | 60 // Command line switches: |
54 | 61 |
55 // "--console" runs the service interactively for debugging purposes. | 62 // "--console" runs the service interactively for debugging purposes. |
56 const char kConsoleSwitchName[] = "console"; | 63 const char kConsoleSwitchName[] = "console"; |
57 | 64 |
58 // "--elevate=<binary>" requests <binary> to be launched elevated, presenting | 65 // "--elevate=<binary>" requests <binary> to be launched elevated, presenting |
59 // a UAC prompt if necessary. | 66 // a UAC prompt if necessary. |
60 const char kElevateSwitchName[] = "elevate"; | 67 const char kElevateSwitchName[] = "elevate"; |
61 | 68 |
| 69 // "--help" or "--?" prints the usage message. |
| 70 const char kHelpSwitchName[] = "help"; |
| 71 const char kQuestionSwitchName[] = "?"; |
| 72 |
| 73 const wchar_t kUsageMessage[] = |
| 74 L"\n" |
| 75 L"Usage: %ls [options]\n" |
| 76 L"\n" |
| 77 L"Options:\n" |
| 78 L" --console - Run the service interactively for debugging purposes.\n" |
| 79 L" --elevate=<...> - Run <...> elevated.\n" |
| 80 L" --help, --? - Print this message.\n"; |
| 81 |
62 // The command line parameters that should be copied from the service's command | 82 // The command line parameters that should be copied from the service's command |
63 // line when launching an elevated child. | 83 // line when launching an elevated child. |
64 const char* kCopiedSwitchNames[] = { | 84 const char* kCopiedSwitchNames[] = { |
65 "host-config", "daemon-pipe", switches::kV, switches::kVModule }; | 85 "host-config", "daemon-pipe", switches::kV, switches::kVModule }; |
66 | 86 |
| 87 void usage(const base::FilePath& program_name) { |
| 88 LOG(INFO) << StringPrintf(kUsageMessage, |
| 89 UTF16ToWide(program_name.value()).c_str()); |
| 90 } |
| 91 |
67 } // namespace | 92 } // namespace |
68 | 93 |
69 namespace remoting { | 94 namespace remoting { |
70 | 95 |
71 HostService::HostService() : | 96 HostService::HostService() : |
72 console_session_id_(kInvalidSessionId), | 97 console_session_id_(kInvalidSessionId), |
73 run_routine_(&HostService::RunAsService), | 98 run_routine_(&HostService::RunAsService), |
74 service_status_handle_(0), | 99 service_status_handle_(0), |
75 stopped_event_(true, false) { | 100 stopped_event_(true, false) { |
76 } | 101 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 self->OnSessionChange(); | 450 self->OnSessionChange(); |
426 return 0; | 451 return 0; |
427 } | 452 } |
428 | 453 |
429 default: | 454 default: |
430 return DefWindowProc(hwnd, message, wparam, lparam); | 455 return DefWindowProc(hwnd, message, wparam, lparam); |
431 } | 456 } |
432 } | 457 } |
433 | 458 |
434 } // namespace remoting | 459 } // namespace remoting |
| 460 |
| 461 int CALLBACK WinMain(HINSTANCE instance, |
| 462 HINSTANCE previous_instance, |
| 463 LPSTR raw_command_line, |
| 464 int show_command) { |
| 465 #ifdef OFFICIAL_BUILD |
| 466 if (remoting::IsUsageStatsAllowed()) { |
| 467 remoting::InitializeCrashReporting(); |
| 468 } |
| 469 #endif // OFFICIAL_BUILD |
| 470 |
| 471 // This object instance is required by Chrome code (for example, |
| 472 // FilePath, LazyInstance, MessageLoop, Singleton, etc). |
| 473 base::AtExitManager exit_manager; |
| 474 |
| 475 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 476 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 477 CommandLine::Init(0, NULL); |
| 478 |
| 479 remoting::InitHostLogging(); |
| 480 |
| 481 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 482 if (command_line->HasSwitch(kHelpSwitchName) || |
| 483 command_line->HasSwitch(kQuestionSwitchName)) { |
| 484 usage(command_line->GetProgram()); |
| 485 return remoting::kSuccessExitCode; |
| 486 } |
| 487 |
| 488 remoting::HostService* service = remoting::HostService::GetInstance(); |
| 489 if (!service->InitWithCommandLine(command_line)) { |
| 490 usage(command_line->GetProgram()); |
| 491 return remoting::kUsageExitCode; |
| 492 } |
| 493 |
| 494 return service->Run(); |
| 495 } |
OLD | NEW |