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

Side by Side Diff: components/user_prefs/tracked/device_id_win.cc

Issue 1908143002: Convert //components/user_prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the rightful glory of <windows.h> 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 | « no previous file | components/user_prefs/tracked/dictionary_hash_store_contents.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/user_prefs/tracked/device_id.h" 5 #include "components/user_prefs/tracked/device_id.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <sddl.h> // For ConvertSidToStringSidA. 8 #include <sddl.h> // For ConvertSidToStringSidA.
9 9
10 #include <memory>
11
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 14
14 MachineIdStatus GetDeterministicMachineSpecificId(std::string* machine_id) { 15 MachineIdStatus GetDeterministicMachineSpecificId(std::string* machine_id) {
15 DCHECK(machine_id); 16 DCHECK(machine_id);
16 17
17 wchar_t computer_name[MAX_COMPUTERNAME_LENGTH + 1] = {}; 18 wchar_t computer_name[MAX_COMPUTERNAME_LENGTH + 1] = {};
18 DWORD computer_name_size = arraysize(computer_name); 19 DWORD computer_name_size = arraysize(computer_name);
19 20
20 if (!::GetComputerNameW(computer_name, &computer_name_size)) 21 if (!::GetComputerNameW(computer_name, &computer_name_size))
21 return MachineIdStatus::FAILURE; 22 return MachineIdStatus::FAILURE;
22 23
23 DWORD sid_size = SECURITY_MAX_SID_SIZE; 24 DWORD sid_size = SECURITY_MAX_SID_SIZE;
24 char sid_buffer[SECURITY_MAX_SID_SIZE]; 25 char sid_buffer[SECURITY_MAX_SID_SIZE];
25 SID* sid = reinterpret_cast<SID*>(sid_buffer); 26 SID* sid = reinterpret_cast<SID*>(sid_buffer);
26 DWORD domain_size = 128; // Will expand below if needed. 27 DWORD domain_size = 128; // Will expand below if needed.
27 scoped_ptr<wchar_t[]> domain_buffer(new wchar_t[domain_size]); 28 std::unique_ptr<wchar_t[]> domain_buffer(new wchar_t[domain_size]);
28 SID_NAME_USE sid_name_use; 29 SID_NAME_USE sid_name_use;
29 30
30 // Although the fifth argument to |LookupAccountNameW()|, 31 // Although the fifth argument to |LookupAccountNameW()|,
31 // |ReferencedDomainName|, is annotated as |_Out_opt_|, if a null 32 // |ReferencedDomainName|, is annotated as |_Out_opt_|, if a null
32 // value is passed in, zero is returned and |GetLastError()| will 33 // value is passed in, zero is returned and |GetLastError()| will
33 // return |ERROR_INSUFFICIENT_BUFFER| (assuming that nothing else went 34 // return |ERROR_INSUFFICIENT_BUFFER| (assuming that nothing else went
34 // wrong). In order to ensure that the call to |LookupAccountNameW()| 35 // wrong). In order to ensure that the call to |LookupAccountNameW()|
35 // has succeeded, it is necessary to include the following logic and 36 // has succeeded, it is necessary to include the following logic and
36 // obtain the domain name. 37 // obtain the domain name.
37 if (!::LookupAccountNameW(nullptr, computer_name, sid, &sid_size, 38 if (!::LookupAccountNameW(nullptr, computer_name, sid, &sid_size,
(...skipping 24 matching lines...) Expand all
62 63
63 char* sid_string = nullptr; 64 char* sid_string = nullptr;
64 if (!::ConvertSidToStringSidA(sid, &sid_string)) 65 if (!::ConvertSidToStringSidA(sid, &sid_string))
65 return MachineIdStatus::FAILURE; 66 return MachineIdStatus::FAILURE;
66 67
67 *machine_id = sid_string; 68 *machine_id = sid_string;
68 ::LocalFree(sid_string); 69 ::LocalFree(sid_string);
69 70
70 return MachineIdStatus::SUCCESS; 71 return MachineIdStatus::SUCCESS;
71 } 72 }
OLDNEW
« no previous file with comments | « no previous file | components/user_prefs/tracked/dictionary_hash_store_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698