OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // This file implements the Windows service controlling Me2Me host processes |
| 6 // running within user sessions. |
| 7 |
| 8 #include "remoting/host/win/daemon_process_main.h" |
| 9 |
| 10 #include "base/at_exit.h" |
| 11 #include "base/base_switches.h" |
| 12 #include "base/command_line.h" |
| 13 #include "base/file_path.h" |
| 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" |
| 16 #include "remoting/base/breakpad.h" |
| 17 #include "remoting/host/branding.h" |
| 18 #include "remoting/host/host_exit_codes.h" |
| 19 #include "remoting/host/logging.h" |
| 20 #include "remoting/host/usage_stats_consent.h" |
| 21 #include "remoting/host/win/host_service.h" |
| 22 |
| 23 using base::StringPrintf; |
| 24 |
| 25 namespace { |
| 26 |
| 27 // Command line switches: |
| 28 |
| 29 // "--help" or "--?" prints the usage message. |
| 30 const char kHelpSwitchName[] = "help"; |
| 31 const char kQuestionSwitchName[] = "?"; |
| 32 |
| 33 const wchar_t kUsageMessage[] = |
| 34 L"\n" |
| 35 L"Usage: %ls [options]\n" |
| 36 L"\n" |
| 37 L"Options:\n" |
| 38 L" --console - Run the service interactively for debugging purposes.\n" |
| 39 L" --elevate=<...> - Run <...> elevated.\n" |
| 40 L" --help, --? - Print this message.\n"; |
| 41 |
| 42 // The command line parameters that should be copied from the service's command |
| 43 // line when launching an elevated child. |
| 44 const char* kCopiedSwitchNames[] = { |
| 45 "host-config", "daemon-pipe", switches::kV, switches::kVModule }; |
| 46 |
| 47 void usage(const FilePath& program_name) { |
| 48 LOG(INFO) << StringPrintf(kUsageMessage, |
| 49 UTF16ToWide(program_name.value()).c_str()); |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 |
| 54 namespace remoting { |
| 55 |
| 56 int DaemonProcessMain() { |
| 57 #ifdef OFFICIAL_BUILD |
| 58 if (IsUsageStatsAllowed()) { |
| 59 InitializeCrashReporting(); |
| 60 } |
| 61 #endif // OFFICIAL_BUILD |
| 62 |
| 63 // This object instance is required by Chrome code (for example, |
| 64 // FilePath, LazyInstance, MessageLoop, Singleton, etc). |
| 65 base::AtExitManager exit_manager; |
| 66 |
| 67 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 68 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 69 CommandLine::Init(0, NULL); |
| 70 |
| 71 InitHostLogging(); |
| 72 |
| 73 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 74 if (command_line->HasSwitch(kHelpSwitchName) || |
| 75 command_line->HasSwitch(kQuestionSwitchName)) { |
| 76 usage(command_line->GetProgram()); |
| 77 return kSuccessExitCode; |
| 78 } |
| 79 |
| 80 HostService* service = HostService::GetInstance(); |
| 81 if (!service->InitWithCommandLine(command_line)) { |
| 82 usage(command_line->GetProgram()); |
| 83 return kUsageExitCode; |
| 84 } |
| 85 |
| 86 return service->Run(); |
| 87 } |
| 88 |
| 89 } // namespace remoting |
OLD | NEW |