OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/storage_monitor/udev_util_linux.h" | 5 #include "chrome/browser/storage_monitor/udev_util_linux.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 | 8 |
9 namespace chrome { | 9 namespace chrome { |
10 | 10 |
| 11 void UdevDeleter::operator()(struct udev* udev) { |
| 12 udev_unref(udev); |
| 13 } |
| 14 |
| 15 void UdevDeviceDeleter::operator()(struct udev_device* device) { |
| 16 udev_device_unref(device); |
| 17 } |
| 18 |
11 std::string GetUdevDevicePropertyValue(struct udev_device* udev_device, | 19 std::string GetUdevDevicePropertyValue(struct udev_device* udev_device, |
12 const char* key) { | 20 const char* key) { |
13 const char* value = udev_device_get_property_value(udev_device, key); | 21 const char* value = udev_device_get_property_value(udev_device, key); |
14 return value ? value : std::string(); | 22 return value ? value : std::string(); |
15 } | 23 } |
16 | 24 |
17 bool GetUdevDevicePropertyValueByPath(const base::FilePath& device_path, | 25 bool GetUdevDevicePropertyValueByPath(const base::FilePath& device_path, |
18 const char* key, | 26 const char* key, |
19 std::string* result) { | 27 std::string* result) { |
20 ScopedUdevObject udev(udev_new()); | 28 ScopedUdevObject udev(udev_new()); |
21 if (!udev.get()) | 29 if (!udev.get()) |
22 return false; | 30 return false; |
23 ScopedUdevDeviceObject device(udev_device_new_from_syspath( | 31 ScopedUdevDeviceObject device(udev_device_new_from_syspath( |
24 udev.get(), device_path.value().c_str())); | 32 udev.get(), device_path.value().c_str())); |
25 if (!device.get()) | 33 if (!device.get()) |
26 return false; | 34 return false; |
27 *result = GetUdevDevicePropertyValue(device.get(), key); | 35 *result = GetUdevDevicePropertyValue(device.get(), key); |
28 return true; | 36 return true; |
29 } | 37 } |
30 | 38 |
31 } // namespace chrome | 39 } // namespace chrome |
OLD | NEW |