Chromium Code Reviews| 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..3c77368f0b48d59cb1bb97b18de338d94fdafccc 100644 |
| --- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc |
| +++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc |
| @@ -15,6 +15,7 @@ |
| #include "chrome/browser/system_monitor/media_storage_util.h" |
| #include "chrome/browser/system_monitor/removable_device_constants.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "ui/base/text/bytes_formatting.h" |
| namespace chromeos { |
| @@ -22,23 +23,17 @@ using base::SystemMonitor; |
| namespace { |
| -// Construct a device name using label or manufacturer (vendor and product) name |
| -// details. |
| +// 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_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; |
| - } |
| - } |
| + std::string device_name = (disk.device_type() == DEVICE_TYPE_SD) ? |
| + "SD Card" : disk.device_label(); |
| + if (device_name.empty()) |
| + device_name = "{" + disk.vendor_name() + ", " + disk.product_name() + "}"; |
|
Lei Zhang
2012/11/09 04:51:14
What if either the vendor or product name is empty
kmadhusu
2012/11/09 21:59:40
Fixed. Created a util function.
|
| 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 +56,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 +72,12 @@ bool GetDeviceInfo(const std::string& source_path, std::string* unique_id, |
| if (device_label) |
| *device_label = GetDeviceName(*disk); |
| + *device_size = ui::FormatBytes(disk->total_size_in_bytes()); |
| return true; |
| } |
| } // namespace |
| -using chrome::MediaStorageUtil; |
| using content::BrowserThread; |
| RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { |
| @@ -164,7 +161,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 +185,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 +222,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); |
| } |