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

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 + Added util functions 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..1552bbf40f31c9f144e57ec8f52641999cbd2ba9 100644
--- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
+++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
@@ -10,11 +10,13 @@
#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"
#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 +24,30 @@ 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())
+ 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 manufacturer_name = chrome::GetDeviceManufacturerName(
+ disk.vendor_name(), disk.product_name());
+ return (!manufacturer_name.empty() && IsStringUTF8(manufacturer_name)) ?
+ UTF8ToUTF16(manufacturer_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 +70,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 +86,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 +175,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 +199,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::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 : string16();
+}
+
void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread(
const disks::DiskMountManager::MountPointInfo& mount_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
@@ -218,27 +236,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,
Lei Zhang 2012/11/12 07:46:56 You are already in the chrome namespace.
kmadhusu 2012/11/12 19:56:56 This code is in chromeos namespace. Fixed the comm
+ 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,
Lei Zhang 2012/11/12 07:46:56 Use GetDisplayNameForDevice() here?
kmadhusu 2012/11/12 19:56:56 oops. Fixed. Missed while merging CL's.
mount_info.mount_path);
}

Powered by Google App Engine
This is Rietveld 408576698