Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8309)

Unified Diff: chrome/common/extensions/image_writer/image_writer_util_mac.cc

Issue 294163008: Adds USB writing for OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@list-devices
Patch Set: Creates a location for code shared between browser and utility process. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698