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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 <IOKit/storage/IOStorageProtocolCharacteristics.h>
8
9 #include "base/mac/foundation_util.h"
10
11 namespace extensions {
12 namespace image_writer {
13
14 bool IsRemovableDevice(CFDictionaryRef disk_description) {
15 CFBooleanRef internal = base::mac::GetValueFromDictionary<CFBooleanRef>(
16 disk_description, kDADiskDescriptionDeviceInternalKey);
17 CFStringRef protocol = base::mac::GetValueFromDictionary<CFStringRef>(
18 disk_description, kDADiskDescriptionDeviceProtocolKey);
19 CFStringRef io_reg_path = base::mac::GetValueFromDictionary<CFStringRef>(
20 disk_description, kDADiskDescriptionDevicePathKey);
21 CFBooleanRef ejectable = base::mac::GetValueFromDictionary<CFBooleanRef>(
22 disk_description, kDADiskDescriptionMediaEjectableKey);
23 CFBooleanRef removable = base::mac::GetValueFromDictionary<CFBooleanRef>(
24 disk_description, kDADiskDescriptionMediaRemovableKey);
25 CFBooleanRef whole = base::mac::GetValueFromDictionary<CFBooleanRef>(
26 disk_description, kDADiskDescriptionMediaWholeKey);
27 CFStringRef kind = base::mac::GetValueFromDictionary<CFStringRef>(
28 disk_description, kDADiskDescriptionMediaKindKey);
29
30 // A drive is a USB stick iff:
31 // - it is not internal
32 // - it is attached to the USB bus
33 // - it is ejectable (because it will be ejected after written to)
34 // - it is removable
35 // - it is the whole drive (although the use of
36 // kDADiskDescriptionMatchMediaWhole should have ensured this)
37 // - it is of type IOMedia (external DVD drives and the like are IOCDMedia
38 // or
39 // IODVDMedia)
40 bool is_usb_stick =
41 !CFBooleanGetValue(internal) &&
42 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.
43 CFBooleanGetValue(ejectable) && CFBooleanGetValue(removable) &&
44 CFBooleanGetValue(whole) &&
45 CFStringCompare(kind, CFSTR("IOMedia"), 0) == kCFCompareEqualTo;
46
47 // A drive is an SD card iff:
48 // - it is attached to the USB bus
49 // - it is ejectable (because it will be ejected after written to)
50 // - it is removable
51 // - it is the whole drive (although the use of
52 // kDADiskDescriptionMatchMediaWhole should have ensured this)
53 // - it is of type IOMedia (external DVD drives and the like are IOCDMedia
54 // or
55 // IODVDMedia)
56 // - the IORegistry device path contains "AppleUSBCardReader"
57 bool is_sd_card =
58 CFEqual(protocol, CFSTR(kIOPropertyPhysicalInterconnectTypeUSB)) &&
59 CFBooleanGetValue(ejectable) && CFBooleanGetValue(removable) &&
60 CFBooleanGetValue(whole) &&
61 CFStringCompare(kind, CFSTR("IOMedia"), 0) == kCFCompareEqualTo &&
62 CFStringFind(io_reg_path, CFSTR("AppleUSBCardReader"), 0).location !=
63 kCFNotFound;
64
65 return is_usb_stick || is_sd_card;
66 }
67
68 } // image_writer
69 } // extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698