Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: chrome/browser/system_monitor/removable_device_notifications_chromeos.cc

Issue 11366144: [Media Gallery][ChromeOS] Improve device media gallery names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..9dd8fb863ccfb32122e5ddda6b5ef654931af785 100644
--- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
+++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
+#include "base/string_util.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"
@@ -22,23 +23,29 @@ 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;
- }
+ if (disk.device_type() == DEVICE_TYPE_SD) {
+ // Mount path of an SD card will be one of the following:
+ // (1) /media/removable/<volume_label>
+ // (2) /media/removable/SD Card
+ // If the volume label is available, mount path will be (1) else (2).
+ FilePath mount_point(disk.mount_path());
+ if (!mount_point.BaseName().LossyDisplayName().empty())
Lei Zhang 2012/11/12 23:20:52 Save this to a local variable to avoid calling it
kmadhusu 2012/11/13 01:03:58 Done.
+ return mount_point.BaseName().LossyDisplayName();
}
- return UTF8ToUTF16(device_name);
+
+ const std::string& device_label = disk.device_label();
+ if (!device_label.empty() && IsStringUTF8(device_label))
+ return UTF8ToUTF16(device_label);
+
+ const std::string name = chrome::GetFullProductName(disk.vendor_name(),
+ disk.product_name());
+ return (!name.empty() && IsStringUTF8(name)) ? UTF8ToUTF16(name) : string16();
}
-// 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 +68,11 @@ 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 |storage_size_in_bytes|.
+bool GetDeviceInfo(const std::string& source_path,
+ std::string* unique_id,
+ string16* device_label,
+ uint64* storage_size_in_bytes) {
const disks::DiskMountManager::Disk* disk =
disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path);
if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN)
@@ -75,12 +83,14 @@ bool GetDeviceInfo(const std::string& source_path, std::string* unique_id,
if (device_label)
*device_label = GetDeviceName(*disk);
+
+ if (storage_size_in_bytes)
+ *storage_size_in_bytes = disk->total_size_in_bytes();
return true;
}
} // namespace
-using chrome::MediaStorageUtil;
using content::BrowserThread;
RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() {
@@ -164,7 +174,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 +198,17 @@ bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath(
return false;
if (device_info)
- *device_info = info_it->second;
+ *device_info = info_it->second.storage_info;
return true;
}
+uint64 RemovableDeviceNotificationsCros::GetStorageSize(
+ 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_in_bytes : 0;
+}
+
void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread(
const disks::DiskMountManager::MountPointInfo& mount_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
@@ -218,28 +235,34 @@ 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))
+ uint64 storage_size_in_bytes;
+ if (!GetDeviceInfo(mount_info.source_path, &unique_id, &device_label,
+ &storage_size_in_bytes))
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),
+ storage_size_in_bytes
+ };
+ mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
SystemMonitor::Get()->ProcessRemovableStorageAttached(
device_id,
- device_label,
+ chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label),
mount_info.mount_path);
}
-} // namespace chrome
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698