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

Side by Side Diff: base/win/win_util.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/win/scoped_comptr_unittest.cc ('k') | base/win/windows_version.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/win/win_util.h" 5 #include "base/win/win_util.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <cfgmgr32.h> 8 #include <cfgmgr32.h>
9 #include <lm.h> 9 #include <lm.h>
10 #include <powrprof.h> 10 #include <powrprof.h>
11 #include <shellapi.h> 11 #include <shellapi.h>
12 #include <shlobj.h> 12 #include <shlobj.h>
13 #include <shobjidl.h> // Must be before propkey. 13 #include <shobjidl.h> // Must be before propkey.
14 #include <initguid.h> 14 #include <initguid.h>
15 #include <inspectable.h> 15 #include <inspectable.h>
16 #include <propkey.h> 16 #include <propkey.h>
17 #include <propvarutil.h> 17 #include <propvarutil.h>
18 #include <psapi.h> 18 #include <psapi.h>
19 #include <roapi.h> 19 #include <roapi.h>
20 #include <sddl.h> 20 #include <sddl.h>
21 #include <setupapi.h> 21 #include <setupapi.h>
22 #include <signal.h> 22 #include <signal.h>
23 #include <stddef.h> 23 #include <stddef.h>
24 #include <stdlib.h> 24 #include <stdlib.h>
25 #include <uiviewsettingsinterop.h> 25 #include <uiviewsettingsinterop.h>
26 #include <windows.ui.viewmanagement.h> 26 #include <windows.ui.viewmanagement.h>
27 #include <winstring.h> 27 #include <winstring.h>
28 #include <wrl/wrappers/corewrappers.h> 28 #include <wrl/wrappers/corewrappers.h>
29 29
30 #include <memory>
31
30 #include "base/base_switches.h" 32 #include "base/base_switches.h"
31 #include "base/command_line.h" 33 #include "base/command_line.h"
32 #include "base/lazy_instance.h" 34 #include "base/lazy_instance.h"
33 #include "base/logging.h" 35 #include "base/logging.h"
34 #include "base/macros.h" 36 #include "base/macros.h"
35 #include "base/memory/scoped_ptr.h"
36 #include "base/strings/string_util.h" 37 #include "base/strings/string_util.h"
37 #include "base/strings/stringprintf.h" 38 #include "base/strings/stringprintf.h"
38 #include "base/strings/utf_string_conversions.h" 39 #include "base/strings/utf_string_conversions.h"
39 #include "base/threading/thread_restrictions.h" 40 #include "base/threading/thread_restrictions.h"
40 #include "base/win/registry.h" 41 #include "base/win/registry.h"
41 #include "base/win/scoped_co_mem.h" 42 #include "base/win/scoped_co_mem.h"
42 #include "base/win/scoped_comptr.h" 43 #include "base/win/scoped_comptr.h"
43 #include "base/win/scoped_handle.h" 44 #include "base/win/scoped_handle.h"
44 #include "base/win/scoped_propvariant.h" 45 #include "base/win/scoped_propvariant.h"
45 #include "base/win/windows_version.h" 46 #include "base/win/windows_version.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 341 }
341 342
342 bool GetUserSidString(std::wstring* user_sid) { 343 bool GetUserSidString(std::wstring* user_sid) {
343 // Get the current token. 344 // Get the current token.
344 HANDLE token = NULL; 345 HANDLE token = NULL;
345 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) 346 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token))
346 return false; 347 return false;
347 ScopedHandle token_scoped(token); 348 ScopedHandle token_scoped(token);
348 349
349 DWORD size = sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE; 350 DWORD size = sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE;
350 scoped_ptr<BYTE[]> user_bytes(new BYTE[size]); 351 std::unique_ptr<BYTE[]> user_bytes(new BYTE[size]);
351 TOKEN_USER* user = reinterpret_cast<TOKEN_USER*>(user_bytes.get()); 352 TOKEN_USER* user = reinterpret_cast<TOKEN_USER*>(user_bytes.get());
352 353
353 if (!::GetTokenInformation(token, TokenUser, user, size, &size)) 354 if (!::GetTokenInformation(token, TokenUser, user, size, &size))
354 return false; 355 return false;
355 356
356 if (!user->User.Sid) 357 if (!user->User.Sid)
357 return false; 358 return false;
358 359
359 // Convert the data to a string. 360 // Convert the data to a string.
360 wchar_t* sid_string; 361 wchar_t* sid_string;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // environment variable prefix. On 64 bit Windows the SHGetKnownFolderPath 567 // environment variable prefix. On 64 bit Windows the SHGetKnownFolderPath
567 // function returns the common program files path with the X86 suffix for 568 // function returns the common program files path with the X86 suffix for
568 // the FOLDERID_ProgramFilesCommon value. 569 // the FOLDERID_ProgramFilesCommon value.
569 // To get the correct path to TabTip.exe we first read the environment 570 // To get the correct path to TabTip.exe we first read the environment
570 // variable CommonProgramW6432 which points to the desired common 571 // variable CommonProgramW6432 which points to the desired common
571 // files path. Failing that we fallback to the SHGetKnownFolderPath API. 572 // files path. Failing that we fallback to the SHGetKnownFolderPath API.
572 573
573 // We then replace the %CommonProgramFiles% value with the actual common 574 // We then replace the %CommonProgramFiles% value with the actual common
574 // files path found in the process. 575 // files path found in the process.
575 string16 common_program_files_path; 576 string16 common_program_files_path;
576 scoped_ptr<wchar_t[]> common_program_files_wow6432; 577 std::unique_ptr<wchar_t[]> common_program_files_wow6432;
577 DWORD buffer_size = 578 DWORD buffer_size =
578 GetEnvironmentVariable(L"CommonProgramW6432", NULL, 0); 579 GetEnvironmentVariable(L"CommonProgramW6432", NULL, 0);
579 if (buffer_size) { 580 if (buffer_size) {
580 common_program_files_wow6432.reset(new wchar_t[buffer_size]); 581 common_program_files_wow6432.reset(new wchar_t[buffer_size]);
581 GetEnvironmentVariable(L"CommonProgramW6432", 582 GetEnvironmentVariable(L"CommonProgramW6432",
582 common_program_files_wow6432.get(), 583 common_program_files_wow6432.get(),
583 buffer_size); 584 buffer_size);
584 common_program_files_path = common_program_files_wow6432.get(); 585 common_program_files_path = common_program_files_wow6432.get();
585 DCHECK(!common_program_files_path.empty()); 586 DCHECK(!common_program_files_path.empty());
586 } else { 587 } else {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 snapshot->resize(num_modules + 8, NULL); 690 snapshot->resize(num_modules + 8, NULL);
690 } 691 }
691 } while (--retries_remaining); 692 } while (--retries_remaining);
692 693
693 DLOG(ERROR) << "Failed to enumerate modules."; 694 DLOG(ERROR) << "Failed to enumerate modules.";
694 return false; 695 return false;
695 } 696 }
696 697
697 } // namespace win 698 } // namespace win
698 } // namespace base 699 } // namespace base
OLDNEW
« no previous file with comments | « base/win/scoped_comptr_unittest.cc ('k') | base/win/windows_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698