Index: chrome/browser/system_monitor/removable_device_notifications_chromeos.cc |
diff --git a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc |
index c8b90e97872f17dad7717e83231faef5f8e2c8c0..28c0b82099b33556b9e58536118577ca346a64cb 100644 |
--- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc |
+++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc |
@@ -22,23 +22,53 @@ using base::SystemMonitor; |
namespace { |
-// Construct a device name using label or manufacturer (vendor and product) name |
-// details. |
-string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { |
- std::string device_name = disk.device_label(); |
- if (device_name.empty()) { |
- device_name = disk.vendor_name(); |
- const std::string& product_name = disk.product_name(); |
- if (!product_name.empty()) { |
- if (!device_name.empty()) |
- device_name += " "; |
- device_name += product_name; |
- } |
+// Returns a human readable device size string, e.g if the device total size |
+// is 2048 bytes, this function returns "2KB". |
+string16 GetDeviceSizeAsString(uint64 total_size_in_bytes) { |
Lei Zhang
2012/11/08 07:42:44
I think you have reinvented the unlocalized versio
kmadhusu
2012/11/08 18:50:35
oops.. I didn't know that. Fixed.
|
+ uint index = 0; |
+ double block_size = 1024.0; |
+ double size_in_bytes = static_cast<double>(total_size_in_bytes); |
+ for (; ((size_in_bytes / block_size > 1.0) && (index < 5)); ++index) |
+ size_in_bytes /= block_size; |
+ |
+ std::string block_name; |
+ switch (index) { |
+ case 0: |
+ block_name = "bytes"; |
+ break; |
+ case 1: |
+ block_name = "KB"; |
+ break; |
+ case 2: |
+ block_name = "MB"; |
+ break; |
+ case 3: |
+ block_name = "GB"; |
+ break; |
+ case 4: |
+ block_name = "TB"; |
+ break; |
+ case 5: |
+ block_name = "PB"; |
+ break; |
+ default: |
+ NOTREACHED(); |
} |
+ return base::UintToString16(static_cast<uint64>(size_in_bytes)) + |
+ ASCIIToUTF16(block_name); |
+} |
+ |
+// Constructs a device name using label or manufacturer (vendor and product) |
+// name details. |
+string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { |
+ std::string device_name = (disk.device_type() == DEVICE_TYPE_SD) ? |
+ "SD Card" : disk.device_label(); |
Lei Zhang
2012/11/08 07:42:44
Similarly, "SD Card" may not work well for other l
kmadhusu
2012/11/08 18:50:35
ChromeOS file manager is not localizing this text.
Lei Zhang
2012/11/09 01:12:18
Ok, can you add a comment for that?
kmadhusu
2012/11/09 21:59:40
As we discussed, we will be showing the base name
|
+ if (device_name.empty()) |
+ device_name = "{" + disk.vendor_name() + ", " + disk.product_name() + "}"; |
Lei Zhang
2012/11/08 07:42:44
Did you and Steve decide to use braces?
kmadhusu
2012/11/08 18:50:35
Yes (along with the PM's).
|
return UTF8ToUTF16(device_name); |
} |
-// Construct a device id using uuid or manufacturer (vendor and product) id |
+// Constructs a device id using uuid or manufacturer (vendor and product) id |
// details. |
std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { |
std::string uuid = disk.fs_uuid(); |
@@ -61,10 +91,12 @@ static RemovableDeviceNotificationsCros* |
g_removable_device_notifications_chromeos = NULL; |
// Returns true if the requested device is valid, else false. On success, fills |
-// in |unique_id| and |device_label| |
-bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, |
- string16* device_label) { |
- // Get the media device uuid and label if exists. |
+// in |unique_id|, |device_label| and |device_size|. |
+bool GetDeviceInfo(const std::string& source_path, |
+ std::string* unique_id, |
+ string16* device_label, |
+ string16* device_size) { |
+ DCHECK(device_size); |
const disks::DiskMountManager::Disk* disk = |
disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); |
if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN) |
@@ -75,12 +107,12 @@ bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, |
if (device_label) |
*device_label = GetDeviceName(*disk); |
+ *device_size = GetDeviceSizeAsString(disk->total_size_in_bytes()); |
return true; |
} |
} // namespace |
-using chrome::MediaStorageUtil; |
using content::BrowserThread; |
RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { |
@@ -164,7 +196,7 @@ void RemovableDeviceNotificationsCros::MountCompleted( |
if (it == mount_map_.end()) |
return; |
SystemMonitor::Get()->ProcessRemovableStorageDetached( |
- it->second.device_id); |
+ it->second.storage_info.device_id); |
mount_map_.erase(it); |
break; |
} |
@@ -188,10 +220,17 @@ bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath( |
return false; |
if (device_info) |
- *device_info = info_it->second; |
+ *device_info = info_it->second.storage_info; |
return true; |
} |
+string16 RemovableDeviceNotificationsCros::GetStorageSizeInfo( |
+ const std::string& device_location) { |
+ MountMap::const_iterator info_it = mount_map_.find(device_location); |
+ return (info_it != mount_map_.end()) ? |
+ info_it->second.storage_size_info : string16(); |
+} |
+ |
void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread( |
const disks::DiskMountManager::MountPointInfo& mount_info) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
@@ -218,27 +257,33 @@ void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread( |
// Get the media device uuid and label if exists. |
std::string unique_id; |
string16 device_label; |
- if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label)) |
+ string16 device_size; |
+ if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label, |
+ &device_size)) |
return; |
// Keep track of device uuid and label, to see how often we receive empty |
// values. |
- MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, device_label); |
+ chrome::MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, |
+ device_label); |
if (unique_id.empty() || device_label.empty()) |
return; |
- MediaStorageUtil::Type type = has_dcim ? |
- MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : |
- MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
+ chrome::MediaStorageUtil::Type type = has_dcim ? |
+ chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : |
+ chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, |
unique_id); |
- SystemMonitor::RemovableStorageInfo info(device_id, device_label, |
- mount_info.mount_path); |
- mount_map_.insert(std::make_pair(mount_info.mount_path, info)); |
+ StorageObjectInfo object_info = { |
+ base::SystemMonitor::RemovableStorageInfo(device_id, device_label, |
+ mount_info.mount_path), |
+ device_size |
+ }; |
+ mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
SystemMonitor::Get()->ProcessRemovableStorageAttached( |
device_id, |
- device_label, |
+ device_size + ASCIIToUTF16(" ") + device_label, |
mount_info.mount_path); |
} |