OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/common/extensions/image_writer/image_writer_util_mac.h" |
| 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 |
| 9 #include "base/mac/scoped_cftyperef.h" |
| 10 #include "base/mac/scoped_ioobject.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 bool IsUsbDevice(io_object_t disk_obj) { |
| 15 io_object_t current_obj = disk_obj; |
| 16 io_object_t parent_obj = 0; |
| 17 // Keep scoped object outside the loop so the object lives to the next |
| 18 // GetParentEntry. |
| 19 base::mac::ScopedIOObject<io_object_t> parent_obj_ref(parent_obj); |
| 20 |
| 21 while ((IORegistryEntryGetParentEntry( |
| 22 current_obj, kIOServicePlane, &parent_obj)) == KERN_SUCCESS) { |
| 23 current_obj = parent_obj; |
| 24 parent_obj_ref.reset(parent_obj); |
| 25 |
| 26 base::ScopedCFTypeRef<CFStringRef> class_name( |
| 27 IOObjectCopyClass(current_obj)); |
| 28 if (!class_name) { |
| 29 LOG(ERROR) << "Could not get object class of IO Registry Entry."; |
| 30 continue; |
| 31 } |
| 32 |
| 33 if (CFStringCompare(class_name.get(), CFSTR("IOUSBMassStorageClass"), 0) == |
| 34 kCFCompareEqualTo) { |
| 35 return true; |
| 36 } |
| 37 } |
| 38 |
| 39 return false; |
| 40 } |
| 41 |
| 42 } // namespace extensions |
OLD | NEW |