OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "remoting/host/setup/me2me_native_messaging_host_main.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host_main.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 DCHECK(command_line->HasSwitch(kInputSwitchName)); | 144 DCHECK(command_line->HasSwitch(kInputSwitchName)); |
145 DCHECK(command_line->HasSwitch(kOutputSwitchName)); | 145 DCHECK(command_line->HasSwitch(kOutputSwitchName)); |
146 | 146 |
147 // presubmit: allow wstring | 147 // presubmit: allow wstring |
148 std::wstring input_pipe_name = | 148 std::wstring input_pipe_name = |
149 command_line->GetSwitchValueNative(kInputSwitchName); | 149 command_line->GetSwitchValueNative(kInputSwitchName); |
150 // presubmit: allow wstring | 150 // presubmit: allow wstring |
151 std::wstring output_pipe_name = | 151 std::wstring output_pipe_name = |
152 command_line->GetSwitchValueNative(kOutputSwitchName); | 152 command_line->GetSwitchValueNative(kOutputSwitchName); |
153 | 153 |
154 // A NULL SECURITY_ATTRIBUTES signifies that the handle can't be inherited | 154 // A NULL SECURITY_ATTRIBUTES signifies that the handle can't be inherited. |
155 read_file = base::File(CreateFile( | 155 read_file = |
156 input_pipe_name.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, | 156 base::File(CreateFile(input_pipe_name.c_str(), GENERIC_READ, 0, nullptr, |
157 FILE_ATTRIBUTE_NORMAL, NULL)); | 157 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)); |
158 if (!read_file.IsValid()) { | 158 if (!read_file.IsValid()) { |
159 PLOG(ERROR) << "CreateFile failed on '" << input_pipe_name << "'"; | 159 PLOG(ERROR) << "CreateFile failed on '" << input_pipe_name << "'"; |
160 return kInitializationFailed; | 160 return kInitializationFailed; |
161 } | 161 } |
162 | 162 |
163 write_file = base::File(CreateFile( | 163 write_file = base::File(CreateFile( |
164 output_pipe_name.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, | 164 output_pipe_name.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, |
165 FILE_ATTRIBUTE_NORMAL, NULL)); | 165 FILE_ATTRIBUTE_NORMAL, nullptr)); |
166 if (!write_file.IsValid()) { | 166 if (!write_file.IsValid()) { |
167 PLOG(ERROR) << "CreateFile failed on '" << output_pipe_name << "'"; | 167 PLOG(ERROR) << "CreateFile failed on '" << output_pipe_name << "'"; |
168 return kInitializationFailed; | 168 return kInitializationFailed; |
169 } | 169 } |
170 } else { | 170 } else { |
171 // GetStdHandle() returns pseudo-handles for stdin and stdout even if | 171 // GetStdHandle() returns pseudo-handles for stdin and stdout even if |
172 // the hosting executable specifies "Windows" subsystem. However the | 172 // the hosting executable specifies "Windows" subsystem. However the |
173 // returned handles are invalid in that case unless standard input and | 173 // returned handles are invalid in that case unless standard input and |
174 // output are redirected to a pipe or file. | 174 // output are redirected to a pipe or file. |
175 read_file = base::File(GetStdHandle(STD_INPUT_HANDLE)); | 175 read_file = base::File(GetStdHandle(STD_INPUT_HANDLE)); |
176 write_file = base::File(GetStdHandle(STD_OUTPUT_HANDLE)); | 176 write_file = base::File(GetStdHandle(STD_OUTPUT_HANDLE)); |
177 | 177 |
178 // After the native messaging channel starts the native messaging reader | 178 // After the native messaging channel starts the native messaging reader |
179 // will keep doing blocking read operations on the input named pipe. | 179 // will keep doing blocking read operations on the input named pipe. |
180 // If any other thread tries to perform any operation on STDIN, it will also | 180 // If any other thread tries to perform any operation on STDIN, it will also |
181 // block because the input named pipe is synchronous (non-overlapped). | 181 // block because the input named pipe is synchronous (non-overlapped). |
182 // It is pretty common for a DLL to query the device info (GetFileType) of | 182 // It is pretty common for a DLL to query the device info (GetFileType) of |
183 // the STD* handles at startup. So any LoadLibrary request can potentially | 183 // the STD* handles at startup. So any LoadLibrary request can potentially |
184 // be blocked. To prevent that from happening we close STDIN and STDOUT | 184 // be blocked. To prevent that from happening we close STDIN and STDOUT |
185 // handles as soon as we retrieve the corresponding file handles. | 185 // handles as soon as we retrieve the corresponding file handles. |
186 SetStdHandle(STD_INPUT_HANDLE, NULL); | 186 SetStdHandle(STD_INPUT_HANDLE, nullptr); |
187 SetStdHandle(STD_OUTPUT_HANDLE, NULL); | 187 SetStdHandle(STD_OUTPUT_HANDLE, nullptr); |
188 } | 188 } |
189 #elif defined(OS_POSIX) | 189 #elif defined(OS_POSIX) |
190 // The files will be automatically closed. | 190 // The files will be automatically closed. |
191 read_file = base::File(STDIN_FILENO); | 191 read_file = base::File(STDIN_FILENO); |
192 write_file = base::File(STDOUT_FILENO); | 192 write_file = base::File(STDOUT_FILENO); |
193 #else | 193 #else |
194 #error Not implemented. | 194 #error Not implemented. |
195 #endif | 195 #endif |
196 | 196 |
197 // OAuth client (for credential requests). IO thread is used for blocking | 197 // OAuth client (for credential requests). IO thread is used for blocking |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // This object instance is required by Chrome code (such as MessageLoop). | 276 // This object instance is required by Chrome code (such as MessageLoop). |
277 base::AtExitManager exit_manager; | 277 base::AtExitManager exit_manager; |
278 | 278 |
279 base::CommandLine::Init(argc, argv); | 279 base::CommandLine::Init(argc, argv); |
280 remoting::InitHostLogging(); | 280 remoting::InitHostLogging(); |
281 | 281 |
282 return StartMe2MeNativeMessagingHost(); | 282 return StartMe2MeNativeMessagingHost(); |
283 } | 283 } |
284 | 284 |
285 } // namespace remoting | 285 } // namespace remoting |
OLD | NEW |