device_id_mac.cc 1.2 KB

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