Chromium Code Reviews| Index: chrome/browser/system_monitor/disk_info_mac.mm |
| diff --git a/chrome/browser/system_monitor/disk_info_mac.mm b/chrome/browser/system_monitor/disk_info_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b47d3546bc0407c5b50cd800829c51cc3710277b |
| --- /dev/null |
| +++ b/chrome/browser/system_monitor/disk_info_mac.mm |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2012 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/browser/system_monitor/disk_info_mac.h" |
| + |
| +#include "base/mac/foundation_util.h" |
| +#include "base/sys_string_conversions.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
| +#include "chrome/browser/system_monitor/media_storage_util.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace chrome { |
| +namespace { |
| + |
| +string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) { |
| + CFStringRef value = |
| + base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key); |
| + return base::SysCFStringRefToUTF16(value); |
| +} |
| + |
| +string16 JoinName(const string16& name, const string16& addition) { |
| + if (addition.empty()) |
| + return name; |
| + if (name.empty()) |
| + return addition; |
| + return name + ASCIIToUTF16(" ") + addition; |
| +} |
| + |
| +MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) { |
| + if (is_removable) { |
| + if (has_dcim) { |
| + return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
| + } else { |
| + return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
| + } |
| + } else { |
| + return MediaStorageUtil::FIXED_MASS_STORAGE; |
| + } |
|
Nico
2012/09/10 07:02:34
nit: gets a bit shorter with early outs:
if (!is_
sail
2012/09/10 21:58:43
Done.
|
| +} |
| + |
| +} // namespace |
| + |
| +DiskInfoMac::DiskInfoMac() { |
| +} |
| + |
| +DiskInfoMac::~DiskInfoMac() { |
| +} |
| + |
| +// static |
| +DiskInfoMac DiskInfoMac::BuildDiskInfoOnFileThread(CFDictionaryRef dict) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| + DiskInfoMac info; |
| + |
| + CFStringRef bsd_name = base::mac::GetValueFromDictionary<CFStringRef>( |
| + dict, kDADiskDescriptionMediaBSDNameKey); |
| + info.bsd_name_ = base::SysCFStringRefToUTF8(bsd_name); |
|
Nico
2012/09/10 07:02:34
I'd do the null checking here instead of changing
sail
2012/09/10 21:58:43
Unless you feel strongly about this I'd prefer to
|
| + |
| + CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>( |
| + dict, kDADiskDescriptionVolumePathKey); |
| + NSURL* nsurl = base::mac::CFToNSCast(url); |
| + info.mount_point_ = base::mac::NSStringToFilePath([nsurl path]); |
| + |
| + string16 vendor_name = GetUTF16FromDictionary( |
| + dict, kDADiskDescriptionDeviceVendorKey); |
| + string16 model_name = GetUTF16FromDictionary( |
| + dict, kDADiskDescriptionDeviceModelKey); |
| + string16 volume_name = GetUTF16FromDictionary( |
| + dict, kDADiskDescriptionVolumeNameKey); |
| + info.display_name_ = vendor_name; |
| + info.display_name_ = JoinName(info.display_name_, model_name); |
| + info.display_name_ = JoinName(info.display_name_, volume_name); |
| + |
| + CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( |
| + dict, kDADiskDescriptionVolumeUUIDKey); |
| + std::string unique_id; |
| + if (uuid) { |
| + base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( |
| + CFUUIDCreateString(NULL, uuid)); |
| + unique_id = base::SysCFStringRefToUTF8(uuid_string); |
| + } |
| + if (unique_id.empty()) |
| + unique_id = info.bsd_name_; |
|
vandebo (ex-Chrome)
2012/09/10 18:45:03
This is ok for non-removable devices, but not for
sail
2012/09/10 21:58:43
Unfortunately I couldn't find a better solution. M
vandebo (ex-Chrome)
2012/09/10 22:53:05
Fair, though bsd_name isn't helpful....
The Disk
sail
2012/09/11 00:14:06
Done. Changed to use "vendor model revision unit"
|
| + |
| + CFBooleanRef is_removable_ref = |
| + base::mac::GetValueFromDictionary<CFBooleanRef>( |
| + dict, kDADiskDescriptionMediaRemovableKey); |
| + bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref); |
| + bool has_dcim = IsMediaDevice(info.mount_point_.value()); |
| + info.type_ = GetDeviceType(is_removable, has_dcim); |
| + info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id); |
| + |
| + return info; |
| +} |
| + |
| +} // chrome |