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

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

Issue 10908277: [Chrome OS] Construct device label and unique id using vendor and product details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 3 months 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
« no previous file with comments | « no previous file | chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1b17b925cd5ac927a22b4c38c31401bcfae19d69..483dd85b4fcf62b4bbeebf86638c075df6976457 100644
--- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
+++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
@@ -11,15 +11,55 @@
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
+#include "base/stringprintf.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"
namespace chromeos {
namespace {
+// Construct a device name using label or manufacturer (vendor and product) name
+// details.
+string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) {
+ std::string device_label = disk.device_label();
vandebo (ex-Chrome) 2012/09/16 19:38:45 nit: device_label -> device_name or name
kmadhusu 2012/09/16 20:08:59 device_label -> device_name. Done
+ if (device_label.empty()) {
+ device_label = disk.vendor_name();
+ const std::string& product_name = disk.product_name();
+ if (!product_name.empty()) {
+ if (!device_label.empty())
+ device_label += chrome::kSpaceDelim;
+ device_label += product_name;
+ }
+ }
+ return UTF8ToUTF16(device_label);
+}
+
+// Construct 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();
+ if (!uuid.empty())
+ return chrome::kFSUniqueIdPrefix + uuid;
+
+ // If one of the vendor or product information is missing, its value in the
+ // string is empty.
+ // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialInfo
+ // TODO(kmadhusu) Extract serial information for the disks and append it to
+ // the device unique id.
+ const std::string& vendor = disk.vendor_id();
+ const std::string& product = disk.product_id();
+ if (vendor.empty() && product.empty())
+ return std::string();
+ return base::StringPrintf("%s%s%s%s%s",
+ chrome::kVendorModelSerialPrefix,
+ vendor.c_str(), chrome::kNonSpaceDelim,
+ product.c_str(), chrome::kNonSpaceDelim);
+}
+
// 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,
@@ -30,13 +70,11 @@ bool GetDeviceInfo(const std::string& source_path, std::string* unique_id,
if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN)
return false;
- *unique_id = disk->fs_uuid();
+ if (unique_id)
+ *unique_id = MakeDeviceUniqueId(*disk);
- // TODO(kmadhusu): If device label is empty, extract vendor and model details
- // and use them as device_label.
- *device_label = UTF8ToUTF16(disk->device_label().empty() ?
- FilePath(source_path).BaseName().value() :
- disk->device_label());
+ if (device_label)
+ *device_label = GetDeviceName(*disk);
return true;
}
@@ -151,7 +189,9 @@ void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread(
// Keep track of device uuid, to see how often we receive empty uuid values.
UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.DeviceUUIDAvailable",
!unique_id.empty());
- if (unique_id.empty())
+ UMA_HISTOGRAM_BOOLEAN("MediaDeviceNotification.DeviceNameAvailable",
+ !device_label.empty());
+ if (unique_id.empty() || device_label.empty())
return;
chrome::MediaStorageUtil::Type type = has_dcim ?
« no previous file with comments | « no previous file | chrome/browser/system_monitor/removable_device_notifications_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698