| 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" | |
| 15 #include "base/base_paths.h" | 14 #include "base/base_paths.h" |
| 16 #include "base/base_switches.h" | 15 #include "base/base_switches.h" |
| 17 #include "base/bind.h" | 16 #include "base/bind.h" |
| 18 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 19 #include "base/file_path.h" | 18 #include "base/file_path.h" |
| 20 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 21 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 22 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 23 #include "base/stringprintf.h" | |
| 24 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 25 #include "base/utf_string_conversions.h" | |
| 26 #include "base/win/wrapped_window_proc.h" | 23 #include "base/win/wrapped_window_proc.h" |
| 27 #include "remoting/base/auto_thread.h" | 24 #include "remoting/base/auto_thread.h" |
| 28 #include "remoting/base/breakpad.h" | |
| 29 #include "remoting/base/scoped_sc_handle_win.h" | 25 #include "remoting/base/scoped_sc_handle_win.h" |
| 30 #include "remoting/base/stoppable.h" | 26 #include "remoting/base/stoppable.h" |
| 31 #include "remoting/host/branding.h" | 27 #include "remoting/host/branding.h" |
| 32 #include "remoting/host/host_exit_codes.h" | 28 #include "remoting/host/host_exit_codes.h" |
| 33 #include "remoting/host/logging.h" | 29 #include "remoting/host/logging.h" |
| 34 | 30 |
| 35 #if defined(REMOTING_MULTI_PROCESS) | 31 #if defined(REMOTING_MULTI_PROCESS) |
| 36 #include "remoting/host/daemon_process.h" | 32 #include "remoting/host/daemon_process.h" |
| 37 #endif // defined(REMOTING_MULTI_PROCESS) | 33 #endif // defined(REMOTING_MULTI_PROCESS) |
| 38 | 34 |
| 39 #include "remoting/host/usage_stats_consent.h" | 35 #include "remoting/host/win/core_resource.h" |
| 40 #include "remoting/host/win/host_service_resource.h" | |
| 41 #include "remoting/host/win/wts_console_observer.h" | 36 #include "remoting/host/win/wts_console_observer.h" |
| 42 | 37 |
| 43 #if !defined(REMOTING_MULTI_PROCESS) | 38 #if !defined(REMOTING_MULTI_PROCESS) |
| 44 #include "remoting/host/win/wts_console_session_process_driver.h" | 39 #include "remoting/host/win/wts_console_session_process_driver.h" |
| 45 #endif // !defined(REMOTING_MULTI_PROCESS) | 40 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 46 | 41 |
| 47 using base::StringPrintf; | |
| 48 | |
| 49 namespace { | 42 namespace { |
| 50 | 43 |
| 51 // Session id that does not represent any session. | 44 // Session id that does not represent any session. |
| 52 const uint32 kInvalidSessionId = 0xffffffffu; | 45 const uint32 kInvalidSessionId = 0xffffffffu; |
| 53 | 46 |
| 54 const char kIoThreadName[] = "I/O thread"; | 47 const char kIoThreadName[] = "I/O thread"; |
| 55 | 48 |
| 56 // A window class for the session change notifications window. | 49 // A window class for the session change notifications window. |
| 57 const wchar_t kSessionNotificationWindowClass[] = | 50 const wchar_t kSessionNotificationWindowClass[] = |
| 58 L"Chromoting_SessionNotificationWindow"; | 51 L"Chromoting_SessionNotificationWindow"; |
| 59 | 52 |
| 60 // Command line switches: | 53 // Command line switches: |
| 61 | 54 |
| 62 // "--console" runs the service interactively for debugging purposes. | 55 // "--console" runs the service interactively for debugging purposes. |
| 63 const char kConsoleSwitchName[] = "console"; | 56 const char kConsoleSwitchName[] = "console"; |
| 64 | 57 |
| 65 // "--elevate=<binary>" requests <binary> to be launched elevated, presenting | 58 // "--elevate=<binary>" requests <binary> to be launched elevated, presenting |
| 66 // a UAC prompt if necessary. | 59 // a UAC prompt if necessary. |
| 67 const char kElevateSwitchName[] = "elevate"; | 60 const char kElevateSwitchName[] = "elevate"; |
| 68 | 61 |
| 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 | |
| 82 // The command line parameters that should be copied from the service's command | 62 // The command line parameters that should be copied from the service's command |
| 83 // line when launching an elevated child. | 63 // line when launching an elevated child. |
| 84 const char* kCopiedSwitchNames[] = { | 64 const char* kCopiedSwitchNames[] = { |
| 85 "host-config", "daemon-pipe", switches::kV, switches::kVModule }; | 65 "host-config", "daemon-pipe", switches::kV, switches::kVModule }; |
| 86 | 66 |
| 87 void usage(const FilePath& program_name) { | |
| 88 LOG(INFO) << StringPrintf(kUsageMessage, | |
| 89 UTF16ToWide(program_name.value()).c_str()); | |
| 90 } | |
| 91 | |
| 92 } // namespace | 67 } // namespace |
| 93 | 68 |
| 94 namespace remoting { | 69 namespace remoting { |
| 95 | 70 |
| 96 HostService::HostService() : | 71 HostService::HostService() : |
| 97 console_session_id_(kInvalidSessionId), | 72 console_session_id_(kInvalidSessionId), |
| 98 run_routine_(&HostService::RunAsService), | 73 run_routine_(&HostService::RunAsService), |
| 99 service_status_handle_(0), | 74 service_status_handle_(0), |
| 100 stopped_event_(true, false) { | 75 stopped_event_(true, false) { |
| 101 } | 76 } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 self->OnSessionChange(); | 425 self->OnSessionChange(); |
| 451 return 0; | 426 return 0; |
| 452 } | 427 } |
| 453 | 428 |
| 454 default: | 429 default: |
| 455 return DefWindowProc(hwnd, message, wparam, lparam); | 430 return DefWindowProc(hwnd, message, wparam, lparam); |
| 456 } | 431 } |
| 457 } | 432 } |
| 458 | 433 |
| 459 } // namespace remoting | 434 } // 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 |