| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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/browser/system_monitor/disk_info_mac.h" |
| 6 |
| 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
| 11 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 |
| 14 namespace chrome { |
| 15 namespace { |
| 16 |
| 17 string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) { |
| 18 CFStringRef value = |
| 19 base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key); |
| 20 return base::SysCFStringRefToUTF16(value); |
| 21 } |
| 22 |
| 23 string16 JoinName(const string16& name, const string16& addition) { |
| 24 if (addition.empty()) |
| 25 return name; |
| 26 if (name.empty()) |
| 27 return addition; |
| 28 return name + ASCIIToUTF16(" ") + addition; |
| 29 } |
| 30 |
| 31 MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) { |
| 32 if (!is_removable) |
| 33 return MediaStorageUtil::FIXED_MASS_STORAGE; |
| 34 if (has_dcim) |
| 35 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
| 36 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 DiskInfoMac::DiskInfoMac() { |
| 42 } |
| 43 |
| 44 DiskInfoMac::~DiskInfoMac() { |
| 45 } |
| 46 |
| 47 // static |
| 48 DiskInfoMac DiskInfoMac::BuildDiskInfoOnFileThread(CFDictionaryRef dict) { |
| 49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 50 DiskInfoMac info; |
| 51 |
| 52 CFStringRef bsd_name = base::mac::GetValueFromDictionary<CFStringRef>( |
| 53 dict, kDADiskDescriptionMediaBSDNameKey); |
| 54 info.bsd_name_ = base::SysCFStringRefToUTF8(bsd_name); |
| 55 |
| 56 CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>( |
| 57 dict, kDADiskDescriptionVolumePathKey); |
| 58 NSURL* nsurl = base::mac::CFToNSCast(url); |
| 59 info.mount_point_ = base::mac::NSStringToFilePath([nsurl path]); |
| 60 |
| 61 string16 vendor_name = GetUTF16FromDictionary( |
| 62 dict, kDADiskDescriptionDeviceVendorKey); |
| 63 string16 model_name = GetUTF16FromDictionary( |
| 64 dict, kDADiskDescriptionDeviceModelKey); |
| 65 string16 volume_name = GetUTF16FromDictionary( |
| 66 dict, kDADiskDescriptionVolumeNameKey); |
| 67 info.display_name_ = vendor_name; |
| 68 info.display_name_ = JoinName(info.display_name_, model_name); |
| 69 info.display_name_ = JoinName(info.display_name_, volume_name); |
| 70 |
| 71 CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( |
| 72 dict, kDADiskDescriptionVolumeUUIDKey); |
| 73 std::string unique_id; |
| 74 if (uuid) { |
| 75 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( |
| 76 CFUUIDCreateString(NULL, uuid)); |
| 77 unique_id = base::SysCFStringRefToUTF8(uuid_string); |
| 78 } |
| 79 if (unique_id.empty()) { |
| 80 string16 revision = GetUTF16FromDictionary( |
| 81 dict, kDADiskDescriptionDeviceRevisionKey); |
| 82 string16 unique_id2 = vendor_name; |
| 83 unique_id2 = JoinName(unique_id2, model_name); |
| 84 unique_id2 = JoinName(unique_id2, revision); |
| 85 unique_id = UTF16ToUTF8(unique_id2); |
| 86 } |
| 87 |
| 88 CFBooleanRef is_removable_ref = |
| 89 base::mac::GetValueFromDictionary<CFBooleanRef>( |
| 90 dict, kDADiskDescriptionMediaRemovableKey); |
| 91 bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref); |
| 92 // Checking for DCIM only matters on removable devices. |
| 93 bool has_dcim = is_removable && IsMediaDevice(info.mount_point_.value()); |
| 94 info.type_ = GetDeviceType(is_removable, has_dcim); |
| 95 info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id); |
| 96 |
| 97 return info; |
| 98 } |
| 99 |
| 100 } // chrome |
| OLD | NEW |