Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/prefs/tracked/device_id.h" | |
| 6 | |
| 7 #include <cstddef> | |
| 8 #include <cwchar> | |
|
gab
2015/01/20 15:34:12
I don't think you need these two headers.
alito
2015/01/26 16:32:48
<cstddef> was for NULL. But probably also defined
gab
2015/01/26 19:40:46
I've never seen anyone include <cwchar>, from what
alito
2015/01/26 21:01:10
I've removed <cwchar>. It is not normally included
grt (UTC plus 2)
2015/01/27 17:06:22
New code should use nullptr.
gab
2015/01/27 18:27:40
Yes, but in this case it's using Windows APIs whos
grt (UTC plus 2)
2015/01/27 19:48:59
Yup, use nullptr rather than NULL when calling a W
alito
2015/01/27 20:56:55
Done.
| |
| 9 | |
| 10 #include <intSafe.h> // For DWORD. | |
|
gab
2015/01/20 15:34:12
DWORD implicitly comes with windows.h AFAIK (I've
alito
2015/01/26 16:32:48
Done.
| |
| 11 #include <sddl.h> // For ConvertSidToStringSidW. | |
|
gab
2015/01/20 15:34:12
s/ConvertSidToStringSidW/ConvertSidToStringSidA
alito
2015/01/26 16:32:48
Done.
| |
| 12 #include <windows.h> | |
|
gab
2015/01/20 15:34:12
We always put windows.h first (this is more or les
alito
2015/01/26 16:32:48
Done.
| |
| 13 | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 | |
| 17 bool GetDeterministicMachineSpecificId(std::string* machine_id) { | |
|
gab
2015/01/20 15:34:13
Looks like there is a GetUserSidString() method in
alito
2015/01/26 16:32:48
As we discussed offline, we will wait with this re
| |
| 18 if (!machine_id) | |
| 19 return false; | |
|
gab
2015/01/20 15:34:13
Instead do:
DCHECK(machine_id);
to enforce the con
alito
2015/01/26 16:32:48
Done.
| |
| 20 | |
| 21 wchar_t computer_name[MAX_COMPUTERNAME_LENGTH + 1] = {0}; | |
|
gab
2015/01/20 15:34:12
{0} is the same as {} except that you explicitly s
alito
2015/01/26 16:32:48
Done.
grt (UTC plus 2)
2015/01/27 17:06:22
It's still my preference.
alito
2015/01/27 20:56:55
Acknowledged.
| |
| 22 DWORD computer_name_size = arraysize(computer_name); | |
| 23 | |
| 24 if (!::GetComputerNameW(computer_name, &computer_name_size)) | |
| 25 return false; | |
| 26 | |
| 27 DWORD sid_size = SECURITY_MAX_SID_SIZE; | |
| 28 char sid_buffer[SECURITY_MAX_SID_SIZE]; | |
| 29 SID* sid = reinterpret_cast<SID*>(sid_buffer); | |
| 30 DWORD domain_size = 128; // Will expand if needed. | |
| 31 scoped_ptr<wchar_t[]> domain_buffer(new wchar_t[domain_size]); | |
| 32 SID_NAME_USE sid_name_use; | |
| 33 | |
| 34 if (!::LookupAccountNameW(NULL, computer_name, sid, &sid_size, | |
| 35 domain_buffer.get(), &domain_size, | |
| 36 &sid_name_use)) { | |
| 37 // If the initial size of domain_buffer was too small, the | |
| 38 // required size is now found in domain_size. Resize and try | |
| 39 // again. | |
| 40 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) | |
| 41 return false; | |
| 42 | |
| 43 domain_buffer.reset(new wchar_t[domain_size]); | |
| 44 if (!::LookupAccountNameW(NULL, computer_name, sid, &sid_size, | |
| 45 domain_buffer.get(), &domain_size, | |
|
gab
2015/01/20 15:34:12
|domain_buffer| is optional and we don't use its v
alito
2015/01/26 16:32:48
The documentation does not mention this explicitly
gab
2015/01/26 19:40:45
I see, please add comments to that effect to avoid
alito
2015/01/26 21:01:10
Done.
| |
| 46 &sid_name_use)) | |
| 47 return false; | |
|
gab
2015/01/20 15:34:12
Wrap in {}
(always wrap in {} unless both the con
alito
2015/01/26 16:32:48
Done.
| |
| 48 } | |
| 49 | |
|
gab
2015/01/20 15:34:12
DCHECK_EQ(SID_NAME_USE::SidTypeComputer, sid_name_
alito
2015/01/26 16:32:48
As we discussed offline, this actually fails consi
| |
| 50 char* sid_string = NULL; | |
| 51 if (!::ConvertSidToStringSidA(sid, &sid_string)) | |
| 52 return false; | |
| 53 | |
| 54 *machine_id = sid_string; | |
| 55 ::LocalFree(sid_string); | |
| 56 | |
| 57 return true; | |
| 58 } | |
| OLD | NEW |