Chromium Code Reviews| 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/string_number_conversions.h" | |
| 9 #include "base/sys_string_conversions.h" | |
| 10 #include "base/utf_string_conversions.h" | |
| 11 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" | |
| 12 #include "chrome/browser/system_monitor/media_storage_util.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 | |
| 15 namespace chrome { | |
| 16 namespace { | |
| 17 | |
| 18 string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) { | |
| 19 CFStringRef value = | |
| 20 base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key); | |
| 21 return base::SysCFStringRefToUTF16(value); | |
| 22 } | |
| 23 | |
| 24 string16 JoinName(const string16& name, const string16& addition) { | |
| 25 if (addition.empty()) | |
| 26 return name; | |
| 27 if (name.empty()) | |
| 28 return addition; | |
| 29 return name + ASCIIToUTF16(" ") + addition; | |
| 30 } | |
| 31 | |
| 32 MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) { | |
| 33 if (!is_removable) | |
| 34 return MediaStorageUtil::FIXED_MASS_STORAGE; | |
| 35 if (has_dcim) | |
| 36 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; | |
| 37 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 DiskInfoMac::DiskInfoMac() { | |
| 43 } | |
| 44 | |
| 45 DiskInfoMac::~DiskInfoMac() { | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 DiskInfoMac DiskInfoMac::BuildDiskInfoOnFileThread(CFDictionaryRef dict) { | |
| 50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
| 51 DiskInfoMac info; | |
| 52 | |
| 53 CFStringRef bsd_name = base::mac::GetValueFromDictionary<CFStringRef>( | |
| 54 dict, kDADiskDescriptionMediaBSDNameKey); | |
| 55 info.bsd_name_ = base::SysCFStringRefToUTF8(bsd_name); | |
| 56 | |
| 57 CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>( | |
| 58 dict, kDADiskDescriptionVolumePathKey); | |
| 59 NSURL* nsurl = base::mac::CFToNSCast(url); | |
| 60 info.mount_point_ = base::mac::NSStringToFilePath([nsurl path]); | |
| 61 | |
| 62 string16 vendor_name = GetUTF16FromDictionary( | |
| 63 dict, kDADiskDescriptionDeviceVendorKey); | |
| 64 string16 model_name = GetUTF16FromDictionary( | |
| 65 dict, kDADiskDescriptionDeviceModelKey); | |
| 66 string16 volume_name = GetUTF16FromDictionary( | |
| 67 dict, kDADiskDescriptionVolumeNameKey); | |
| 68 info.display_name_ = vendor_name; | |
| 69 info.display_name_ = JoinName(info.display_name_, model_name); | |
| 70 info.display_name_ = JoinName(info.display_name_, volume_name); | |
| 71 | |
| 72 CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( | |
| 73 dict, kDADiskDescriptionVolumeUUIDKey); | |
| 74 std::string unique_id; | |
| 75 if (uuid) { | |
| 76 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( | |
| 77 CFUUIDCreateString(NULL, uuid)); | |
| 78 unique_id = base::SysCFStringRefToUTF8(uuid_string); | |
| 79 } | |
| 80 if (unique_id.empty()) { | |
| 81 string16 revision = GetUTF16FromDictionary( | |
| 82 dict, kDADiskDescriptionDeviceRevisionKey); | |
| 83 CFNumberRef unit_number = base::mac::GetValueFromDictionary<CFNumberRef>( | |
| 84 dict, kDADiskDescriptionDeviceUnitKey); | |
| 85 string16 unique_id2 = vendor_name; | |
| 86 unique_id2 = JoinName(unique_id2, model_name); | |
| 87 unique_id2 = JoinName(unique_id2, revision); | |
| 88 if (unit_number) { | |
|
vandebo (ex-Chrome)
2012/09/11 00:45:50
Did you figure out what this is? I'm not sure. I
sail
2012/09/11 03:02:00
Oops, you're right. This changes when you plugin t
| |
| 89 int unit = [base::mac::CFToNSCast(unit_number) intValue]; | |
| 90 unique_id2 = JoinName(unique_id2, base::IntToString16(unit)); | |
| 91 } | |
| 92 unique_id = UTF16ToUTF8(unique_id2); | |
| 93 } | |
| 94 | |
| 95 CFBooleanRef is_removable_ref = | |
| 96 base::mac::GetValueFromDictionary<CFBooleanRef>( | |
| 97 dict, kDADiskDescriptionMediaRemovableKey); | |
| 98 bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref); | |
| 99 bool has_dcim = IsMediaDevice(info.mount_point_.value()); | |
| 100 info.type_ = GetDeviceType(is_removable, has_dcim); | |
| 101 info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id); | |
| 102 | |
| 103 return info; | |
| 104 } | |
| 105 | |
| 106 } // chrome | |
| OLD | NEW |