X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Futility%2Fimage_writer%2Fimage_writer_mac.cc;h=c572d1427c318505f737125e20d7c9ad0572205f;hb=4a1a0bdd01eef90b0826a0e761d3379d3715c10f;hp=0935a5a2516e3d7ac7c52e43221fef833a2fbd7b;hpb=b1be5ca53587d23e7aeb77b26861fdc0a181ffd8;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/utility/image_writer/image_writer_mac.cc b/src/chrome/utility/image_writer/image_writer_mac.cc index 0935a5a..c572d14 100644 --- a/src/chrome/utility/image_writer/image_writer_mac.cc +++ b/src/chrome/utility/image_writer/image_writer_mac.cc @@ -2,15 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include +#include +#include +#include +#include #include #include #include "base/command_line.h" #include "base/files/scoped_file.h" +#include "base/mac/scoped_cftyperef.h" +#include "base/mac/scoped_ioobject.h" #include "base/posix/eintr_wrapper.h" #include "base/process/kill.h" #include "base/process/launch.h" #include "base/strings/stringprintf.h" +#include "base/strings/sys_string_conversions.h" +#include "chrome/common/extensions/image_writer/image_writer_util_mac.h" #include "chrome/utility/image_writer/disk_unmounter_mac.h" #include "chrome/utility/image_writer/error_messages.h" #include "chrome/utility/image_writer/image_writer.h" @@ -20,37 +29,36 @@ namespace image_writer { static const char kAuthOpenPath[] = "/usr/libexec/authopen"; bool ImageWriter::IsValidDevice() { - base::ScopedCFTypeRef session(DASessionCreate(NULL)); - base::ScopedCFTypeRef disk(DADiskCreateFromBSDName( - kCFAllocatorDefault, session, device_path_.value().c_str())); + base::ScopedCFTypeRef cf_bsd_name( + base::SysUTF8ToCFStringRef(device_path_.value())); + CFMutableDictionaryRef matching = IOServiceMatching(kIOMediaClass); + CFDictionaryAddValue(matching, CFSTR(kIOMediaWholeKey), kCFBooleanTrue); + CFDictionaryAddValue(matching, CFSTR(kIOMediaWritableKey), kCFBooleanTrue); + CFDictionaryAddValue(matching, CFSTR(kIOBSDNameKey), cf_bsd_name); + + io_service_t disk_obj = + IOServiceGetMatchingService(kIOMasterPortDefault, matching); + base::mac::ScopedIOObject iterator_ref(disk_obj); + + if (disk_obj) { + CFMutableDictionaryRef dict; + if (IORegistryEntryCreateCFProperties( + disk_obj, &dict, kCFAllocatorDefault, 0) != KERN_SUCCESS) { + LOG(ERROR) << "Unable to get properties of disk object."; + return false; + } + base::ScopedCFTypeRef dict_ref(dict); - if (!disk) - return false; + CFBooleanRef cf_removable = base::mac::GetValueFromDictionary( + dict, CFSTR(kIOMediaRemovableKey)); + bool removable = CFBooleanGetValue(cf_removable); + + bool is_usb = extensions::IsUsbDevice(disk_obj); + + return removable || is_usb; + } - base::ScopedCFTypeRef disk_description( - DADiskCopyDescription(disk)); - - CFBooleanRef ejectable = base::mac::GetValueFromDictionary( - disk_description, kDADiskDescriptionMediaEjectableKey); - CFBooleanRef removable = base::mac::GetValueFromDictionary( - disk_description, kDADiskDescriptionMediaRemovableKey); - CFBooleanRef writable = base::mac::GetValueFromDictionary( - disk_description, kDADiskDescriptionMediaWritableKey); - CFBooleanRef whole = base::mac::GetValueFromDictionary( - disk_description, kDADiskDescriptionMediaWholeKey); - CFStringRef kind = base::mac::GetValueFromDictionary( - disk_description, kDADiskDescriptionMediaKindKey); - - // A drive is valid if it is - // - ejectable - // - removable - // - writable - // - a whole drive - // - it is of type IOMedia (external DVD drives and the like are IOCDMedia or - // IODVDMedia) - return CFBooleanGetValue(ejectable) && CFBooleanGetValue(removable) && - CFBooleanGetValue(writable) && CFBooleanGetValue(whole) && - CFStringCompare(kind, CFSTR("IOMedia"), 0) == kCFCompareEqualTo; + return false; } void ImageWriter::UnmountVolumes(const base::Closure& continuation) {