| 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 // StorageMonitorLinux implementation. | 5 // StorageMonitorLinux implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" | 7 #include "chrome/browser/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/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 23 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | |
| 24 #include "chrome/browser/storage_monitor/media_storage_util.h" | 23 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 25 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" | 24 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
| 26 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 25 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
| 27 #include "chrome/browser/storage_monitor/udev_util_linux.h" | 26 #include "chrome/browser/storage_monitor/udev_util_linux.h" |
| 28 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 29 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 28 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
| 30 | 29 |
| 31 namespace chrome { | 30 namespace chrome { |
| 32 | 31 |
| 33 using content::BrowserThread; | 32 using content::BrowserThread; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 154 |
| 156 if (!device_label.empty() && IsStringUTF8(device_label)) | 155 if (!device_label.empty() && IsStringUTF8(device_label)) |
| 157 return UTF8ToUTF16(device_label); | 156 return UTF8ToUTF16(device_label); |
| 158 | 157 |
| 159 device_label = GetUdevDevicePropertyValue(device, kFsUUID); | 158 device_label = GetUdevDevicePropertyValue(device, kFsUUID); |
| 160 // Keep track of device uuid, to see how often we receive empty uuid values. | 159 // Keep track of device uuid, to see how often we receive empty uuid values. |
| 161 UMA_HISTOGRAM_BOOLEAN( | 160 UMA_HISTOGRAM_BOOLEAN( |
| 162 "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", | 161 "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", |
| 163 !device_label.empty()); | 162 !device_label.empty()); |
| 164 | 163 |
| 165 const string16 name = GetFullProductName(vendor_name, model_name); | 164 const string16 name = MediaStorageUtil::GetFullProductName(vendor_name, |
| 165 model_name); |
| 166 | 166 |
| 167 const string16 device_label_utf16 = | 167 const string16 device_label_utf16 = |
| 168 (!device_label.empty() && IsStringUTF8(device_label)) ? | 168 (!device_label.empty() && IsStringUTF8(device_label)) ? |
| 169 UTF8ToUTF16(device_label) : string16(); | 169 UTF8ToUTF16(device_label) : string16(); |
| 170 if (!name.empty() && !device_label_utf16.empty()) | 170 if (!name.empty() && !device_label_utf16.empty()) |
| 171 return device_label_utf16 + ASCIIToUTF16(" ") + name; | 171 return device_label_utf16 + ASCIIToUTF16(" ") + name; |
| 172 return name.empty() ? device_label_utf16 : name; | 172 return name.empty() ? device_label_utf16 : name; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Get the device information using udev library. | 175 // Get the device information using udev library. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 value = udev_device_get_sysattr_value(parent_device, kRemovableSysAttr); | 237 value = udev_device_get_sysattr_value(parent_device, kRemovableSysAttr); |
| 238 } | 238 } |
| 239 bool is_removable = (value && atoi(value) == 1); | 239 bool is_removable = (value && atoi(value) == 1); |
| 240 if (removable) { | 240 if (removable) { |
| 241 *removable = is_removable; | 241 *removable = is_removable; |
| 242 } | 242 } |
| 243 | 243 |
| 244 if (device_id) { | 244 if (device_id) { |
| 245 MediaStorageUtil::Type type = MediaStorageUtil::FIXED_MASS_STORAGE; | 245 MediaStorageUtil::Type type = MediaStorageUtil::FIXED_MASS_STORAGE; |
| 246 if (is_removable) { | 246 if (is_removable) { |
| 247 if (IsMediaDevice(mount_point.value())) | 247 if (MediaStorageUtil::HasDcim(mount_point.value())) |
| 248 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 248 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; |
| 249 else | 249 else |
| 250 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | 250 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
| 251 } | 251 } |
| 252 *device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 252 *device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
| 253 } | 253 } |
| 254 | 254 |
| 255 if (partition_size_in_bytes) | 255 if (partition_size_in_bytes) |
| 256 *partition_size_in_bytes = GetDeviceStorageSize(device_path, device); | 256 *partition_size_in_bytes = GetDeviceStorageSize(device_path, device); |
| 257 RecordGetDeviceInfoResult(true); | 257 RecordGetDeviceInfoResult(true); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 474 |
| 475 MountPointInfo mount_point_info; | 475 MountPointInfo mount_point_info; |
| 476 mount_point_info.mount_device = mount_device; | 476 mount_point_info.mount_device = mount_device; |
| 477 mount_point_info.storage_info = StorageInfo( | 477 mount_point_info.storage_info = StorageInfo( |
| 478 device_id, name, mount_point.value(), volume_label, | 478 device_id, name, mount_point.value(), volume_label, |
| 479 vendor_name, model_name, partition_size_in_bytes); | 479 vendor_name, model_name, partition_size_in_bytes); |
| 480 mount_info_map_[mount_point] = mount_point_info; | 480 mount_info_map_[mount_point] = mount_point_info; |
| 481 mount_priority_map_[mount_device][mount_point] = removable; | 481 mount_priority_map_[mount_device][mount_point] = removable; |
| 482 | 482 |
| 483 if (removable) { | 483 if (removable) { |
| 484 receiver()->ProcessAttach(StorageInfo( | 484 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( |
| 485 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), | 485 partition_size_in_bytes, name); |
| 486 mount_point.value())); | 486 |
| 487 receiver()->ProcessAttach(StorageInfo(device_id, display_name, |
| 488 mount_point.value())); |
| 487 } | 489 } |
| 488 } | 490 } |
| 489 | 491 |
| 490 } // namespace chrome | 492 } // namespace chrome |
| OLD | NEW |