| 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/files/file_path.h" |   16 #include "base/files/file_path.h" | 
|   17 #include "base/metrics/histogram.h" |   17 #include "base/metrics/histogram.h" | 
|   18 #include "base/stl_util.h" |   18 #include "base/stl_util.h" | 
|   19 #include "base/string_util.h" |   19 #include "base/string_util.h" | 
|   20 #include "base/strings/string_number_conversions.h" |   20 #include "base/strings/string_number_conversions.h" | 
|   21 #include "base/utf_string_conversions.h" |   21 #include "base/utf_string_conversions.h" | 
|   22 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |  | 
|   23 #include "chrome/browser/storage_monitor/media_storage_util.h" |   22 #include "chrome/browser/storage_monitor/media_storage_util.h" | 
|   24 #include "chrome/browser/storage_monitor/removable_device_constants.h" |   23 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 
|   25 #include "chrome/browser/storage_monitor/udev_util_linux.h" |   24 #include "chrome/browser/storage_monitor/udev_util_linux.h" | 
|   26  |   25  | 
|   27 namespace chrome { |   26 namespace chrome { | 
|   28  |   27  | 
|   29 using content::BrowserThread; |   28 using content::BrowserThread; | 
|   30  |   29  | 
|   31 namespace { |   30 namespace { | 
|   32  |   31  | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  151  |  150  | 
|  152   if (!device_label.empty() && IsStringUTF8(device_label)) |  151   if (!device_label.empty() && IsStringUTF8(device_label)) | 
|  153     return UTF8ToUTF16(device_label); |  152     return UTF8ToUTF16(device_label); | 
|  154  |  153  | 
|  155   device_label = GetUdevDevicePropertyValue(device, kFsUUID); |  154   device_label = GetUdevDevicePropertyValue(device, kFsUUID); | 
|  156   // Keep track of device uuid, to see how often we receive empty uuid values. |  155   // Keep track of device uuid, to see how often we receive empty uuid values. | 
|  157   UMA_HISTOGRAM_BOOLEAN( |  156   UMA_HISTOGRAM_BOOLEAN( | 
|  158       "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", |  157       "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", | 
|  159       !device_label.empty()); |  158       !device_label.empty()); | 
|  160  |  159  | 
|  161   const string16 name = GetFullProductName(vendor_name, model_name); |  160   const string16 name = MediaStorageUtil::GetFullProductName(vendor_name, | 
 |  161                                                              model_name); | 
|  162  |  162  | 
|  163   const string16 device_label_utf16 = |  163   const string16 device_label_utf16 = | 
|  164       (!device_label.empty() && IsStringUTF8(device_label)) ? |  164       (!device_label.empty() && IsStringUTF8(device_label)) ? | 
|  165           UTF8ToUTF16(device_label) : string16(); |  165           UTF8ToUTF16(device_label) : string16(); | 
|  166   if (!name.empty() && !device_label_utf16.empty()) |  166   if (!name.empty() && !device_label_utf16.empty()) | 
|  167     return device_label_utf16 + ASCIIToUTF16(" ") + name; |  167     return device_label_utf16 + ASCIIToUTF16(" ") + name; | 
|  168   return name.empty() ? device_label_utf16 : name; |  168   return name.empty() ? device_label_utf16 : name; | 
|  169 } |  169 } | 
|  170  |  170  | 
|  171 // Get the device information using udev library. |  171 // Get the device information using udev library. | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  233     value = udev_device_get_sysattr_value(parent_device, kRemovableSysAttr); |  233     value = udev_device_get_sysattr_value(parent_device, kRemovableSysAttr); | 
|  234   } |  234   } | 
|  235   bool is_removable = (value && atoi(value) == 1); |  235   bool is_removable = (value && atoi(value) == 1); | 
|  236   if (removable) { |  236   if (removable) { | 
|  237     *removable = is_removable; |  237     *removable = is_removable; | 
|  238   } |  238   } | 
|  239  |  239  | 
|  240   if (device_id) { |  240   if (device_id) { | 
|  241     MediaStorageUtil::Type type = MediaStorageUtil::FIXED_MASS_STORAGE; |  241     MediaStorageUtil::Type type = MediaStorageUtil::FIXED_MASS_STORAGE; | 
|  242     if (is_removable) { |  242     if (is_removable) { | 
|  243       if (IsMediaDevice(mount_point.value())) |  243       if (MediaStorageUtil::HasDcim(mount_point.value())) | 
|  244         type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; |  244         type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 
|  245       else |  245       else | 
|  246         type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |  246         type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | 
|  247     } |  247     } | 
|  248     *device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |  248     *device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 
|  249   } |  249   } | 
|  250  |  250  | 
|  251   if (partition_size_in_bytes) |  251   if (partition_size_in_bytes) | 
|  252     *partition_size_in_bytes = GetDeviceStorageSize(device_path, device); |  252     *partition_size_in_bytes = GetDeviceStorageSize(device_path, device); | 
|  253   RecordGetDeviceInfoResult(true); |  253   RecordGetDeviceInfoResult(true); | 
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  456  |  456  | 
|  457   MountPointInfo mount_point_info; |  457   MountPointInfo mount_point_info; | 
|  458   mount_point_info.mount_device = mount_device; |  458   mount_point_info.mount_device = mount_device; | 
|  459   mount_point_info.storage_info = StorageInfo( |  459   mount_point_info.storage_info = StorageInfo( | 
|  460       device_id, name, mount_point.value(), volume_label, |  460       device_id, name, mount_point.value(), volume_label, | 
|  461       vendor_name, model_name, partition_size_in_bytes); |  461       vendor_name, model_name, partition_size_in_bytes); | 
|  462   mount_info_map_[mount_point] = mount_point_info; |  462   mount_info_map_[mount_point] = mount_point_info; | 
|  463   mount_priority_map_[mount_device][mount_point] = removable; |  463   mount_priority_map_[mount_device][mount_point] = removable; | 
|  464  |  464  | 
|  465   if (removable) { |  465   if (removable) { | 
|  466     receiver()->ProcessAttach(StorageInfo( |  466     string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( | 
|  467         device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), |  467         partition_size_in_bytes, name); | 
|  468         mount_point.value())); |  468  | 
 |  469     receiver()->ProcessAttach(StorageInfo(device_id, display_name, | 
 |  470                                           mount_point.value())); | 
|  469   } |  471   } | 
|  470 } |  472 } | 
|  471  |  473  | 
|  472 }  // namespace chrome |  474 }  // namespace chrome | 
| OLD | NEW |