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

Side by Side Diff: base/process_util_win.cc

Issue 3781009: Move the windows-specific scoped_* stuff from base to base/win and in the bas... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/process_util.h" 5 #include "base/process_util.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <io.h> 8 #include <io.h>
9 #include <windows.h> 9 #include <windows.h>
10 #include <userenv.h> 10 #include <userenv.h>
11 #include <psapi.h> 11 #include <psapi.h>
12 12
13 #include <ios> 13 #include <ios>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/debug_util.h" 16 #include "base/debug_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/scoped_handle_win.h"
20 #include "base/scoped_ptr.h" 19 #include "base/scoped_ptr.h"
20 #include "base/win/scoped_handle.h"
21 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
22 22
23 // userenv.dll is required for CreateEnvironmentBlock(). 23 // userenv.dll is required for CreateEnvironmentBlock().
24 #pragma comment(lib, "userenv.lib") 24 #pragma comment(lib, "userenv.lib")
25 25
26 namespace base { 26 namespace base {
27 27
28 namespace { 28 namespace {
29 29
30 // System pagesize. This value remains constant on x86/64 architectures. 30 // System pagesize. This value remains constant on x86/64 architectures.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return false; 156 return false;
157 157
158 if (base::win::GetVersion() < base::win::VERSION_VISTA) 158 if (base::win::GetVersion() < base::win::VERSION_VISTA)
159 return false; 159 return false;
160 160
161 HANDLE process_token; 161 HANDLE process_token;
162 if (!OpenProcessToken(process, TOKEN_QUERY | TOKEN_QUERY_SOURCE, 162 if (!OpenProcessToken(process, TOKEN_QUERY | TOKEN_QUERY_SOURCE,
163 &process_token)) 163 &process_token))
164 return false; 164 return false;
165 165
166 ScopedHandle scoped_process_token(process_token); 166 base::win::ScopedHandle scoped_process_token(process_token);
167 167
168 DWORD token_info_length = 0; 168 DWORD token_info_length = 0;
169 if (GetTokenInformation(process_token, TokenIntegrityLevel, NULL, 0, 169 if (GetTokenInformation(process_token, TokenIntegrityLevel, NULL, 0,
170 &token_info_length) || 170 &token_info_length) ||
171 GetLastError() != ERROR_INSUFFICIENT_BUFFER) 171 GetLastError() != ERROR_INSUFFICIENT_BUFFER)
172 return false; 172 return false;
173 173
174 scoped_array<char> token_label_bytes(new char[token_info_length]); 174 scoped_array<char> token_label_bytes(new char[token_info_length]);
175 if (!token_label_bytes.get()) 175 if (!token_label_bytes.get())
176 return false; 176 return false;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 sa_attr.bInheritHandle = TRUE; 319 sa_attr.bInheritHandle = TRUE;
320 sa_attr.lpSecurityDescriptor = NULL; 320 sa_attr.lpSecurityDescriptor = NULL;
321 321
322 // Create the pipe for the child process's STDOUT. 322 // Create the pipe for the child process's STDOUT.
323 if (!CreatePipe(&out_read, &out_write, &sa_attr, 0)) { 323 if (!CreatePipe(&out_read, &out_write, &sa_attr, 0)) {
324 NOTREACHED() << "Failed to create pipe"; 324 NOTREACHED() << "Failed to create pipe";
325 return false; 325 return false;
326 } 326 }
327 327
328 // Ensure we don't leak the handles. 328 // Ensure we don't leak the handles.
329 ScopedHandle scoped_out_read(out_read); 329 base::win::ScopedHandle scoped_out_read(out_read);
330 ScopedHandle scoped_out_write(out_write); 330 base::win::ScopedHandle scoped_out_write(out_write);
331 331
332 // Ensure the read handle to the pipe for STDOUT is not inherited. 332 // Ensure the read handle to the pipe for STDOUT is not inherited.
333 if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) { 333 if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) {
334 NOTREACHED() << "Failed to disabled pipe inheritance"; 334 NOTREACHED() << "Failed to disabled pipe inheritance";
335 return false; 335 return false;
336 } 336 }
337 337
338 // Now create the child process 338 // Now create the child process
339 PROCESS_INFORMATION proc_info = { 0 }; 339 PROCESS_INFORMATION proc_info = { 0 };
340 STARTUPINFO start_info = { 0 }; 340 STARTUPINFO start_info = { 0 };
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 887
888 PERFORMANCE_INFORMATION info; 888 PERFORMANCE_INFORMATION info;
889 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { 889 if (!InternalGetPerformanceInfo(&info, sizeof(info))) {
890 LOG(ERROR) << "Failed to fetch internal performance info."; 890 LOG(ERROR) << "Failed to fetch internal performance info.";
891 return 0; 891 return 0;
892 } 892 }
893 return (info.CommitTotal * system_info.dwPageSize) / 1024; 893 return (info.CommitTotal * system_info.dwPageSize) / 1024;
894 } 894 }
895 895
896 } // namespace base 896 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_win.cc ('k') | base/scoped_bstr_win.h » ('j') | base/win/scoped_comptr.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698