| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // StorageMonitorLinux implementation. | 5 // StorageMonitorLinux implementation. |
| 6 | 6 |
| 7 #include "components/storage_monitor/storage_monitor_linux.h" | 7 #include "components/storage_monitor/storage_monitor_linux.h" |
| 8 | 8 |
| 9 #include <mntent.h> | 9 #include <mntent.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 | 11 |
| 12 #include <list> | 12 #include <list> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
| 18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "components/storage_monitor/media_storage_util.h" | 23 #include "components/storage_monitor/media_storage_util.h" |
| 24 #include "components/storage_monitor/media_transfer_protocol_device_observer_lin
ux.h" | 24 #include "components/storage_monitor/media_transfer_protocol_device_observer_lin
ux.h" |
| 25 #include "components/storage_monitor/removable_device_constants.h" | 25 #include "components/storage_monitor/removable_device_constants.h" |
| 26 #include "components/storage_monitor/storage_info.h" | 26 #include "components/storage_monitor/storage_info.h" |
| 27 #include "components/storage_monitor/udev_util_linux.h" | 27 #include "components/storage_monitor/udev_util_linux.h" |
| 28 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 28 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
| 29 #include "device/udev_linux/udev.h" |
| 29 | 30 |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| 31 | 32 |
| 32 namespace storage_monitor { | 33 namespace storage_monitor { |
| 33 | 34 |
| 34 typedef MtabWatcherLinux::MountPointDeviceMap MountPointDeviceMap; | 35 typedef MtabWatcherLinux::MountPointDeviceMap MountPointDeviceMap; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // udev device property constants. | 39 // udev device property constants. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // Gets the device information using udev library. | 118 // Gets the device information using udev library. |
| 118 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, | 119 scoped_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path, |
| 119 const base::FilePath& mount_point) { | 120 const base::FilePath& mount_point) { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 121 DCHECK(!device_path.empty()); | 122 DCHECK(!device_path.empty()); |
| 122 | 123 |
| 123 scoped_ptr<StorageInfo> storage_info; | 124 scoped_ptr<StorageInfo> storage_info; |
| 124 | 125 |
| 125 ScopedGetDeviceInfoResultRecorder results_recorder; | 126 ScopedGetDeviceInfoResultRecorder results_recorder; |
| 126 | 127 |
| 127 ScopedUdevObject udev_obj(udev_new()); | 128 device::ScopedUdevPtr udev_obj(udev_new()); |
| 128 if (!udev_obj.get()) | 129 if (!udev_obj.get()) |
| 129 return storage_info.Pass(); | 130 return storage_info.Pass(); |
| 130 | 131 |
| 131 struct stat device_stat; | 132 struct stat device_stat; |
| 132 if (stat(device_path.value().c_str(), &device_stat) < 0) | 133 if (stat(device_path.value().c_str(), &device_stat) < 0) |
| 133 return storage_info.Pass(); | 134 return storage_info.Pass(); |
| 134 | 135 |
| 135 char device_type; | 136 char device_type; |
| 136 if (S_ISCHR(device_stat.st_mode)) | 137 if (S_ISCHR(device_stat.st_mode)) |
| 137 device_type = 'c'; | 138 device_type = 'c'; |
| 138 else if (S_ISBLK(device_stat.st_mode)) | 139 else if (S_ISBLK(device_stat.st_mode)) |
| 139 device_type = 'b'; | 140 device_type = 'b'; |
| 140 else | 141 else |
| 141 return storage_info.Pass(); // Not a supported type. | 142 return storage_info.Pass(); // Not a supported type. |
| 142 | 143 |
| 143 ScopedUdevDeviceObject device( | 144 device::ScopedUdevDevicePtr device( |
| 144 udev_device_new_from_devnum(udev_obj.get(), device_type, | 145 udev_device_new_from_devnum(udev_obj.get(), device_type, |
| 145 device_stat.st_rdev)); | 146 device_stat.st_rdev)); |
| 146 if (!device.get()) | 147 if (!device.get()) |
| 147 return storage_info.Pass(); | 148 return storage_info.Pass(); |
| 148 | 149 |
| 149 base::string16 volume_label = | 150 base::string16 volume_label = |
| 150 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kLabel)); | 151 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kLabel)); |
| 151 base::string16 vendor_name = | 152 base::string16 vendor_name = |
| 152 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kVendor)); | 153 base::UTF8ToUTF16(GetUdevDevicePropertyValue(device.get(), kVendor)); |
| 153 base::string16 model_name = | 154 base::string16 model_name = |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 mount_priority_map_[mount_device][mount_point] = removable; | 498 mount_priority_map_[mount_device][mount_point] = removable; |
| 498 receiver()->ProcessAttach(*storage_info); | 499 receiver()->ProcessAttach(*storage_info); |
| 499 } | 500 } |
| 500 | 501 |
| 501 StorageMonitor* StorageMonitor::CreateInternal() { | 502 StorageMonitor* StorageMonitor::CreateInternal() { |
| 502 const base::FilePath kDefaultMtabPath("/etc/mtab"); | 503 const base::FilePath kDefaultMtabPath("/etc/mtab"); |
| 503 return new StorageMonitorLinux(kDefaultMtabPath); | 504 return new StorageMonitorLinux(kDefaultMtabPath); |
| 504 } | 505 } |
| 505 | 506 |
| 506 } // namespace storage_monitor | 507 } // namespace storage_monitor |
| OLD | NEW |