OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 common entry point shared by all Chromoting Host | 5 // This file implements the common entry point shared by all Chromoting Host |
6 // processes. | 6 // processes. |
7 | 7 |
8 #include "remoting/host/host_main.h" | 8 #include "remoting/host/host_main.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 " --version - Prints the host version and exits.\n"; | 79 " --version - Prints the host version and exits.\n"; |
80 | 80 |
81 void Usage(const base::FilePath& program_name) { | 81 void Usage(const base::FilePath& program_name) { |
82 printf(kUsageMessage, program_name.MaybeAsASCII().c_str()); | 82 printf(kUsageMessage, program_name.MaybeAsASCII().c_str()); |
83 } | 83 } |
84 | 84 |
85 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
86 | 86 |
87 // Runs the binary specified by the command line, elevated. | 87 // Runs the binary specified by the command line, elevated. |
88 int RunElevated() { | 88 int RunElevated() { |
89 const CommandLine::SwitchMap& switches = | 89 const base::CommandLine::SwitchMap& switches = |
90 CommandLine::ForCurrentProcess()->GetSwitches(); | 90 base::CommandLine::ForCurrentProcess()->GetSwitches(); |
91 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); | 91 base::CommandLine::StringVector args = |
| 92 base::CommandLine::ForCurrentProcess()->GetArgs(); |
92 | 93 |
93 // Create the child process command line by copying switches from the current | 94 // Create the child process command line by copying switches from the current |
94 // command line. | 95 // command line. |
95 CommandLine command_line(CommandLine::NO_PROGRAM); | 96 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
96 for (CommandLine::SwitchMap::const_iterator i = switches.begin(); | 97 for (base::CommandLine::SwitchMap::const_iterator i = switches.begin(); |
97 i != switches.end(); ++i) { | 98 i != switches.end(); ++i) { |
98 if (i->first != kElevateSwitchName) | 99 if (i->first != kElevateSwitchName) |
99 command_line.AppendSwitchNative(i->first, i->second); | 100 command_line.AppendSwitchNative(i->first, i->second); |
100 } | 101 } |
101 for (CommandLine::StringVector::const_iterator i = args.begin(); | 102 for (base::CommandLine::StringVector::const_iterator i = args.begin(); |
102 i != args.end(); ++i) { | 103 i != args.end(); ++i) { |
103 command_line.AppendArgNative(*i); | 104 command_line.AppendArgNative(*i); |
104 } | 105 } |
105 | 106 |
106 // Get the name of the binary to launch. | 107 // Get the name of the binary to launch. |
107 base::FilePath binary = | 108 base::FilePath binary = |
108 CommandLine::ForCurrentProcess()->GetSwitchValuePath(kElevateSwitchName); | 109 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
109 CommandLine::StringType parameters = command_line.GetCommandLineString(); | 110 kElevateSwitchName); |
| 111 base::CommandLine::StringType parameters = |
| 112 command_line.GetCommandLineString(); |
110 | 113 |
111 // Launch the child process requesting elevation. | 114 // Launch the child process requesting elevation. |
112 SHELLEXECUTEINFO info; | 115 SHELLEXECUTEINFO info; |
113 memset(&info, 0, sizeof(info)); | 116 memset(&info, 0, sizeof(info)); |
114 info.cbSize = sizeof(info); | 117 info.cbSize = sizeof(info); |
115 info.lpVerb = L"runas"; | 118 info.lpVerb = L"runas"; |
116 info.lpFile = binary.value().c_str(); | 119 info.lpFile = binary.value().c_str(); |
117 info.lpParameters = parameters.c_str(); | 120 info.lpParameters = parameters.c_str(); |
118 info.nShow = SW_SHOWNORMAL; | 121 info.nShow = SW_SHOWNORMAL; |
119 | 122 |
(...skipping 30 matching lines...) Expand all Loading... |
150 } | 153 } |
151 | 154 |
152 } // namespace | 155 } // namespace |
153 | 156 |
154 int HostMain(int argc, char** argv) { | 157 int HostMain(int argc, char** argv) { |
155 #if defined(OS_MACOSX) | 158 #if defined(OS_MACOSX) |
156 // Needed so we don't leak objects when threads are created. | 159 // Needed so we don't leak objects when threads are created. |
157 base::mac::ScopedNSAutoreleasePool pool; | 160 base::mac::ScopedNSAutoreleasePool pool; |
158 #endif | 161 #endif |
159 | 162 |
160 CommandLine::Init(argc, argv); | 163 base::CommandLine::Init(argc, argv); |
161 | 164 |
162 // Initialize Breakpad as early as possible. On Mac the command-line needs to | 165 // Initialize Breakpad as early as possible. On Mac the command-line needs to |
163 // be initialized first, so that the preference for crash-reporting can be | 166 // be initialized first, so that the preference for crash-reporting can be |
164 // looked up in the config file. | 167 // looked up in the config file. |
165 #if defined(REMOTING_ENABLE_BREAKPAD) | 168 #if defined(REMOTING_ENABLE_BREAKPAD) |
166 if (IsUsageStatsAllowed()) { | 169 if (IsUsageStatsAllowed()) { |
167 InitializeCrashReporting(); | 170 InitializeCrashReporting(); |
168 } | 171 } |
169 #endif // defined(REMOTING_ENABLE_BREAKPAD) | 172 #endif // defined(REMOTING_ENABLE_BREAKPAD) |
170 | 173 |
171 // This object instance is required by Chrome code (for example, | 174 // This object instance is required by Chrome code (for example, |
172 // LazyInstance, MessageLoop). | 175 // LazyInstance, MessageLoop). |
173 base::AtExitManager exit_manager; | 176 base::AtExitManager exit_manager; |
174 | 177 |
175 // Enable debug logs. | 178 // Enable debug logs. |
176 InitHostLogging(); | 179 InitHostLogging(); |
177 | 180 |
178 // Register and initialize common controls. | 181 // Register and initialize common controls. |
179 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
180 INITCOMMONCONTROLSEX info; | 183 INITCOMMONCONTROLSEX info; |
181 info.dwSize = sizeof(info); | 184 info.dwSize = sizeof(info); |
182 info.dwICC = ICC_STANDARD_CLASSES; | 185 info.dwICC = ICC_STANDARD_CLASSES; |
183 InitCommonControlsEx(&info); | 186 InitCommonControlsEx(&info); |
184 #endif // defined(OS_WIN) | 187 #endif // defined(OS_WIN) |
185 | 188 |
186 // Parse the command line. | 189 // Parse the command line. |
187 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 190 const base::CommandLine* command_line = |
| 191 base::CommandLine::ForCurrentProcess(); |
188 if (command_line->HasSwitch(kHelpSwitchName) || | 192 if (command_line->HasSwitch(kHelpSwitchName) || |
189 command_line->HasSwitch(kQuestionSwitchName)) { | 193 command_line->HasSwitch(kQuestionSwitchName)) { |
190 Usage(command_line->GetProgram()); | 194 Usage(command_line->GetProgram()); |
191 return kSuccessExitCode; | 195 return kSuccessExitCode; |
192 } | 196 } |
193 | 197 |
194 if (command_line->HasSwitch(kVersionSwitchName)) { | 198 if (command_line->HasSwitch(kVersionSwitchName)) { |
195 printf("%s\n", STRINGIZE(VERSION)); | 199 printf("%s\n", STRINGIZE(VERSION)); |
196 return kSuccessExitCode; | 200 return kSuccessExitCode; |
197 } | 201 } |
(...skipping 28 matching lines...) Expand all Loading... |
226 if (exit_code == kUsageExitCode) { | 230 if (exit_code == kUsageExitCode) { |
227 Usage(command_line->GetProgram()); | 231 Usage(command_line->GetProgram()); |
228 } | 232 } |
229 | 233 |
230 remoting::UnloadResources(); | 234 remoting::UnloadResources(); |
231 | 235 |
232 return exit_code; | 236 return exit_code; |
233 } | 237 } |
234 | 238 |
235 } // namespace remoting | 239 } // namespace remoting |
OLD | NEW |