Skip to content

Commit

Permalink
Move GetUdevDevicePropertyValue from components/storage_monitor to de…
Browse files Browse the repository at this point in the history
…vice/udev_linux and rename to UdevDeviceGetPropertyValue

I am going to use this as part of Web MIDI and don't want to depend on storage_monitor.

Review URL: https://codereview.chromium.org/982883004

Cr-Commit-Position: refs/heads/master@{#319415}
  • Loading branch information
agoode authored and Commit bot committed Mar 6, 2015
1 parent 9ad6518 commit 7a59246
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
22 changes: 11 additions & 11 deletions components/storage_monitor/storage_monitor_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const char kVendorID[] = "ID_VENDOR_ID";

// Construct a device id using label or manufacturer (vendor and model) details.
std::string MakeDeviceUniqueId(struct udev_device* device) {
std::string uuid = GetUdevDevicePropertyValue(device, kFsUUID);
std::string uuid = device::UdevDeviceGetPropertyValue(device, kFsUUID);
// Keep track of device uuid, to see how often we receive empty uuid values.
UMA_HISTOGRAM_BOOLEAN(
"RemovableDeviceNotificationsLinux.device_file_system_uuid_available",
Expand All @@ -64,10 +64,10 @@ std::string MakeDeviceUniqueId(struct udev_device* device) {
// in the string is empty.
// Format: VendorModelSerial:VendorInfo:ModelInfo:SerialShortInfo
// E.g.: VendorModelSerial:Kn:DataTravel_12.10:8000000000006CB02CDB
std::string vendor = GetUdevDevicePropertyValue(device, kVendorID);
std::string model = GetUdevDevicePropertyValue(device, kModelID);
std::string serial_short = GetUdevDevicePropertyValue(device,
kSerialShort);
std::string vendor = device::UdevDeviceGetPropertyValue(device, kVendorID);
std::string model = device::UdevDeviceGetPropertyValue(device, kModelID);
std::string serial_short =
device::UdevDeviceGetPropertyValue(device, kSerialShort);
if (vendor.empty() && model.empty() && serial_short.empty())
return std::string();

Expand Down Expand Up @@ -147,12 +147,12 @@ scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path,
if (!device.get())
return storage_info.Pass();

base::string16 volume_label =
base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kLabel));
base::string16 vendor_name =
base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kVendor));
base::string16 model_name =
base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kModel));
base::string16 volume_label = base::UTF8ToUTF16(
device::UdevDeviceGetPropertyValue(device.get(), kLabel));
base::string16 vendor_name = base::UTF8ToUTF16(
device::UdevDeviceGetPropertyValue(device.get(), kVendor));
base::string16 model_name = base::UTF8ToUTF16(
device::UdevDeviceGetPropertyValue(device.get(), kModel));

std::string unique_id = MakeDeviceUniqueId(device.get());

Expand Down
8 changes: 1 addition & 7 deletions components/storage_monitor/udev_util_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

namespace storage_monitor {

std::string GetUdevDevicePropertyValue(udev_device* udev_device,
const char* key) {
const char* value = device::udev_device_get_property_value(udev_device, key);
return value ? value : std::string();
}

bool GetUdevDevicePropertyValueByPath(const base::FilePath& device_path,
const char* key,
std::string* result) {
Expand All @@ -25,7 +19,7 @@ bool GetUdevDevicePropertyValueByPath(const base::FilePath& device_path,
udev.get(), device_path.value().c_str()));
if (!device.get())
return false;
*result = GetUdevDevicePropertyValue(device.get(), key);
*result = device::UdevDeviceGetPropertyValue(device.get(), key);
return true;
}

Expand Down
5 changes: 0 additions & 5 deletions components/storage_monitor/udev_util_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ class FilePath;

namespace storage_monitor {

// Wrapper function for udev_device_get_property_value() that also checks for
// valid but empty values.
std::string GetUdevDevicePropertyValue(udev_device* udev_device,
const char* key);

// Helper for udev_device_new_from_syspath()/udev_device_get_property_value()
// pair. |device_path| is the absolute path to the device, including /sys.
bool GetUdevDevicePropertyValueByPath(const base::FilePath& device_path,
Expand Down
6 changes: 6 additions & 0 deletions device/udev_linux/udev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@ void udev_unref(udev* udev) {
UdevLoader::Get()->udev_unref(udev);
}

std::string UdevDeviceGetPropertyValue(udev_device* udev_device,
const char* key) {
const char* value = device::udev_device_get_property_value(udev_device, key);
return value ? value : std::string();
}

} // namespace device
7 changes: 7 additions & 0 deletions device/udev_linux/udev.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <sys/types.h>
#include <sys/stat.h>

#include <string>

#if !defined(USE_UDEV)
#error "USE_UDEV not defined"
#endif
Expand Down Expand Up @@ -72,6 +74,11 @@ void udev_set_log_fn(
void udev_set_log_priority(struct udev* udev, int priority);
void udev_unref(udev* udev);

// Calls udev_device_get_property_value() and replaces missing values with
// the empty string.
std::string UdevDeviceGetPropertyValue(udev_device* udev_device,
const char* key);

} // namespace device

#endif // DEVICE_UDEV_LINUX_UDEV_H_

0 comments on commit 7a59246

Please sign in to comment.