Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/extensions/api/messaging/native_process_launcher_win.cc

Issue 1410333006: Enough hacks to make wstring printfs unneeded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" 5 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // CreateNamedPipeW(). 99 // CreateNamedPipeW().
100 const DWORD kBufferSize = 0; 100 const DWORD kBufferSize = 0;
101 101
102 if (!command_line.GetProgram().IsAbsolute()) { 102 if (!command_line.GetProgram().IsAbsolute()) {
103 LOG(ERROR) << "Native Messaging host path must be absolute."; 103 LOG(ERROR) << "Native Messaging host path must be absolute.";
104 return false; 104 return false;
105 } 105 }
106 106
107 uint64 pipe_name_token; 107 uint64 pipe_name_token;
108 crypto::RandBytes(&pipe_name_token, sizeof(pipe_name_token)); 108 crypto::RandBytes(&pipe_name_token, sizeof(pipe_name_token));
109 base::string16 out_pipe_name = base::StringPrintf( 109 base::string16 out_pipe_name = L"";/*base::StringPrintf(
110 L"\\\\.\\pipe\\chrome.nativeMessaging.out.%llx", pipe_name_token); 110 L"\\\\.\\pipe\\chrome.nativeMessaging.out.%llx", pipe_name_token);*/
111 base::string16 in_pipe_name = base::StringPrintf( 111 base::string16 in_pipe_name = L"";/* base::StringPrintf(
112 L"\\\\.\\pipe\\chrome.nativeMessaging.in.%llx", pipe_name_token); 112 L"\\\\.\\pipe\\chrome.nativeMessaging.in.%llx", pipe_name_token);*/
113 113
114 // Create the pipes to read and write from. 114 // Create the pipes to read and write from.
115 base::win::ScopedHandle stdout_pipe( 115 base::win::ScopedHandle stdout_pipe(
116 CreateNamedPipeW(out_pipe_name.c_str(), 116 CreateNamedPipeW(out_pipe_name.c_str(),
117 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED | 117 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED |
118 FILE_FLAG_FIRST_PIPE_INSTANCE, 118 FILE_FLAG_FIRST_PIPE_INSTANCE,
119 PIPE_TYPE_BYTE, 1, kBufferSize, kBufferSize, 119 PIPE_TYPE_BYTE, 1, kBufferSize, kBufferSize,
120 kTimeoutMs, NULL)); 120 kTimeoutMs, NULL));
121 if (!stdout_pipe.IsValid()) { 121 if (!stdout_pipe.IsValid()) {
122 LOG(ERROR) << "Failed to create pipe " << out_pipe_name; 122 LOG(ERROR) << "Failed to create pipe " << out_pipe_name;
(...skipping 14 matching lines...) Expand all
137 DWORD comspec_length = ::GetEnvironmentVariable(L"COMSPEC", NULL, 0); 137 DWORD comspec_length = ::GetEnvironmentVariable(L"COMSPEC", NULL, 0);
138 if (comspec_length == 0) { 138 if (comspec_length == 0) {
139 LOG(ERROR) << "COMSPEC is not set"; 139 LOG(ERROR) << "COMSPEC is not set";
140 return false; 140 return false;
141 } 141 }
142 scoped_ptr<wchar_t[]> comspec(new wchar_t[comspec_length]); 142 scoped_ptr<wchar_t[]> comspec(new wchar_t[comspec_length]);
143 ::GetEnvironmentVariable(L"COMSPEC", comspec.get(), comspec_length); 143 ::GetEnvironmentVariable(L"COMSPEC", comspec.get(), comspec_length);
144 144
145 base::string16 command_line_string = command_line.GetCommandLineString(); 145 base::string16 command_line_string = command_line.GetCommandLineString();
146 146
147 base::string16 command = base::StringPrintf( 147 base::string16 command = L"";/* base::StringPrintf(
148 L"%ls /c %ls < %ls > %ls", 148 L"%ls /c %ls < %ls > %ls",
149 comspec.get(), command_line_string.c_str(), 149 comspec.get(), command_line_string.c_str(),
150 in_pipe_name.c_str(), out_pipe_name.c_str()); 150 in_pipe_name.c_str(), out_pipe_name.c_str());*/
brucedawson 2015/10/20 21:43:00 String printing of %COMSPEC% and GetCommandLineStr
151 151
152 base::LaunchOptions options; 152 base::LaunchOptions options;
153 options.start_hidden = true; 153 options.start_hidden = true;
154 base::Process cmd_process = base::LaunchProcess(command.c_str(), options); 154 base::Process cmd_process = base::LaunchProcess(command.c_str(), options);
155 if (!cmd_process.IsValid()) { 155 if (!cmd_process.IsValid()) {
156 LOG(ERROR) << "Error launching process " 156 LOG(ERROR) << "Error launching process "
157 << command_line.GetProgram().MaybeAsASCII(); 157 << command_line.GetProgram().MaybeAsASCII();
158 return false; 158 return false;
159 } 159 }
160 160
161 bool stdout_connected = ConnectNamedPipe(stdout_pipe.Get(), NULL) ? 161 bool stdout_connected = ConnectNamedPipe(stdout_pipe.Get(), NULL) ?
162 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; 162 TRUE : GetLastError() == ERROR_PIPE_CONNECTED;
163 bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ? 163 bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ?
164 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; 164 TRUE : GetLastError() == ERROR_PIPE_CONNECTED;
165 if (!stdout_connected || !stdin_connected) { 165 if (!stdout_connected || !stdin_connected) {
166 cmd_process.Terminate(0, false); 166 cmd_process.Terminate(0, false);
167 LOG(ERROR) << "Failed to connect IO pipes when starting " 167 LOG(ERROR) << "Failed to connect IO pipes when starting "
168 << command_line.GetProgram().MaybeAsASCII(); 168 << command_line.GetProgram().MaybeAsASCII();
169 return false; 169 return false;
170 } 170 }
171 171
172 *process = cmd_process.Pass(); 172 *process = cmd_process.Pass();
173 *read_file = base::File::CreateForAsyncHandle(stdout_pipe.Take()); 173 *read_file = base::File::CreateForAsyncHandle(stdout_pipe.Take());
174 *write_file = base::File::CreateForAsyncHandle(stdin_pipe.Take()); 174 *write_file = base::File::CreateForAsyncHandle(stdin_pipe.Take());
175 175
176 return true; 176 return true;
177 } 177 }
178 178
179 } // namespace extensions 179 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698