Chromium Code Reviews| Index: chrome/common/extensions/image_writer/image_writer_util_mac.cc |
| diff --git a/chrome/common/extensions/image_writer/image_writer_util_mac.cc b/chrome/common/extensions/image_writer/image_writer_util_mac.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e149448768e8ef84acf652e2f3871f70357f025d |
| --- /dev/null |
| +++ b/chrome/common/extensions/image_writer/image_writer_util_mac.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/common/extensions/image_writer/image_writer_util_mac.h" |
| + |
| +#include <IOKit/storage/IOStorageProtocolCharacteristics.h> |
| + |
| +#include "base/mac/foundation_util.h" |
| + |
| +namespace extensions { |
| +namespace image_writer { |
| + |
| +bool IsRemovableDevice(CFDictionaryRef disk_description) { |
| + CFBooleanRef internal = base::mac::GetValueFromDictionary<CFBooleanRef>( |
| + disk_description, kDADiskDescriptionDeviceInternalKey); |
| + CFStringRef protocol = base::mac::GetValueFromDictionary<CFStringRef>( |
| + disk_description, kDADiskDescriptionDeviceProtocolKey); |
| + CFStringRef io_reg_path = base::mac::GetValueFromDictionary<CFStringRef>( |
| + disk_description, kDADiskDescriptionDevicePathKey); |
| + CFBooleanRef ejectable = base::mac::GetValueFromDictionary<CFBooleanRef>( |
| + disk_description, kDADiskDescriptionMediaEjectableKey); |
| + CFBooleanRef removable = base::mac::GetValueFromDictionary<CFBooleanRef>( |
| + disk_description, kDADiskDescriptionMediaRemovableKey); |
| + CFBooleanRef whole = base::mac::GetValueFromDictionary<CFBooleanRef>( |
| + disk_description, kDADiskDescriptionMediaWholeKey); |
| + CFStringRef kind = base::mac::GetValueFromDictionary<CFStringRef>( |
| + disk_description, kDADiskDescriptionMediaKindKey); |
| + |
| + // A drive is a USB stick iff: |
| + // - it is not internal |
| + // - it is attached to the USB bus |
| + // - it is ejectable (because it will be ejected after written to) |
| + // - it is removable |
| + // - it is the whole drive (although the use of |
| + // kDADiskDescriptionMatchMediaWhole should have ensured this) |
| + // - it is of type IOMedia (external DVD drives and the like are IOCDMedia |
| + // or |
| + // IODVDMedia) |
| + bool is_usb_stick = |
| + !CFBooleanGetValue(internal) && |
| + CFEqual(protocol, CFSTR(kIOPropertyPhysicalInterconnectTypeUSB)) && |
|
Robert Sesek
2014/06/10 19:47:46
Maybe pull out line 42, 43, and 44 into its own bo
Drew Haven
2014/06/12 02:24:26
Done.
|
| + CFBooleanGetValue(ejectable) && CFBooleanGetValue(removable) && |
| + CFBooleanGetValue(whole) && |
| + CFStringCompare(kind, CFSTR("IOMedia"), 0) == kCFCompareEqualTo; |
| + |
| + // A drive is an SD card iff: |
| + // - it is attached to the USB bus |
| + // - it is ejectable (because it will be ejected after written to) |
| + // - it is removable |
| + // - it is the whole drive (although the use of |
| + // kDADiskDescriptionMatchMediaWhole should have ensured this) |
| + // - it is of type IOMedia (external DVD drives and the like are IOCDMedia |
| + // or |
| + // IODVDMedia) |
| + // - the IORegistry device path contains "AppleUSBCardReader" |
| + bool is_sd_card = |
| + CFEqual(protocol, CFSTR(kIOPropertyPhysicalInterconnectTypeUSB)) && |
| + CFBooleanGetValue(ejectable) && CFBooleanGetValue(removable) && |
| + CFBooleanGetValue(whole) && |
| + CFStringCompare(kind, CFSTR("IOMedia"), 0) == kCFCompareEqualTo && |
| + CFStringFind(io_reg_path, CFSTR("AppleUSBCardReader"), 0).location != |
| + kCFNotFound; |
| + |
| + return is_usb_stick || is_sd_card; |
| +} |
| + |
| +} // image_writer |
| +} // extensions |