OLD | NEW |
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 "services/preferences/tracked/device_id.h" |
6 | 6 |
7 #include <IOKit/IOKitLib.h> | 7 #include <IOKit/IOKitLib.h> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #include "base/mac/scoped_ioobject.h" | 11 #include "base/mac/scoped_ioobject.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 | 13 |
14 MachineIdStatus GetDeterministicMachineSpecificId(std::string* machine_id) { | 14 MachineIdStatus GetDeterministicMachineSpecificId(std::string* machine_id) { |
15 base::mac::ScopedIOObject<io_service_t> platform_expert( | 15 base::mac::ScopedIOObject<io_service_t> platform_expert( |
16 IOServiceGetMatchingService(kIOMasterPortDefault, | 16 IOServiceGetMatchingService(kIOMasterPortDefault, |
17 IOServiceMatching("IOPlatformExpertDevice"))); | 17 IOServiceMatching("IOPlatformExpertDevice"))); |
18 if (!platform_expert.get()) | 18 if (!platform_expert.get()) |
19 return MachineIdStatus::FAILURE; | 19 return MachineIdStatus::FAILURE; |
20 | 20 |
21 base::ScopedCFTypeRef<CFTypeRef> uuid(IORegistryEntryCreateCFProperty( | 21 base::ScopedCFTypeRef<CFTypeRef> uuid(IORegistryEntryCreateCFProperty( |
22 platform_expert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0)); | 22 platform_expert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0)); |
23 if (!uuid.get()) | 23 if (!uuid.get()) |
24 return MachineIdStatus::FAILURE; | 24 return MachineIdStatus::FAILURE; |
25 | 25 |
26 CFStringRef uuid_string = base::mac::CFCast<CFStringRef>(uuid); | 26 CFStringRef uuid_string = base::mac::CFCast<CFStringRef>(uuid); |
27 if (!uuid_string) | 27 if (!uuid_string) |
28 return MachineIdStatus::FAILURE; | 28 return MachineIdStatus::FAILURE; |
29 | 29 |
30 *machine_id = base::SysCFStringRefToUTF8(uuid_string); | 30 *machine_id = base::SysCFStringRefToUTF8(uuid_string); |
31 return MachineIdStatus::SUCCESS; | 31 return MachineIdStatus::SUCCESS; |
32 } | 32 } |
OLD | NEW |