Chromium Code Reviews| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 std::string device_label = GetUdevDevicePropertyValue(device, kLabel); | 138 std::string device_label = GetUdevDevicePropertyValue(device, kLabel); | 
| 140 if (!device_label.empty() && IsStringUTF8(device_label)) | 139 if (!device_label.empty() && IsStringUTF8(device_label)) | 
| 141 return UTF8ToUTF16(device_label); | 140 return UTF8ToUTF16(device_label); | 
| 142 | 141 | 
| 143 device_label = GetUdevDevicePropertyValue(device, kFsUUID); | 142 device_label = GetUdevDevicePropertyValue(device, kFsUUID); | 
| 144 // Keep track of device uuid, to see how often we receive empty uuid values. | 143 // Keep track of device uuid, to see how often we receive empty uuid values. | 
| 145 UMA_HISTOGRAM_BOOLEAN( | 144 UMA_HISTOGRAM_BOOLEAN( | 
| 146 "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", | 145 "RemovableDeviceNotificationsLinux.device_file_system_uuid_available", | 
| 147 !device_label.empty()); | 146 !device_label.empty()); | 
| 148 | 147 | 
| 149 const string16 name = GetFullProductName( | 148 const string16 name = MediaStorageUtil::GetFullProductName( | 
| 150 GetUdevDevicePropertyValue(device, kVendor), | 149 GetUdevDevicePropertyValue(device, kVendor), | 
| 151 GetUdevDevicePropertyValue(device, kModel)); | 150 GetUdevDevicePropertyValue(device, kModel)); | 
| 152 | 151 | 
| 153 const string16 device_label_utf16 = | 152 const string16 device_label_utf16 = | 
| 154 (!device_label.empty() && IsStringUTF8(device_label)) ? | 153 (!device_label.empty() && IsStringUTF8(device_label)) ? | 
| 155 UTF8ToUTF16(device_label) : string16(); | 154 UTF8ToUTF16(device_label) : string16(); | 
| 156 if (!name.empty() && !device_label_utf16.empty()) | 155 if (!name.empty() && !device_label_utf16.empty()) | 
| 157 return device_label_utf16 + ASCIIToUTF16(" ") + name; | 156 return device_label_utf16 + ASCIIToUTF16(" ") + name; | 
| 158 return name.empty() ? device_label_utf16 : name; | 157 return name.empty() ? device_label_utf16 : name; | 
| 159 } | 158 } | 
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 bool removable; | 420 bool removable; | 
| 422 uint64 partition_size_in_bytes; | 421 uint64 partition_size_in_bytes; | 
| 423 get_device_info_func_(mount_device, &unique_id, &name, &removable, | 422 get_device_info_func_(mount_device, &unique_id, &name, &removable, | 
| 424 &partition_size_in_bytes); | 423 &partition_size_in_bytes); | 
| 425 | 424 | 
| 426 // Keep track of device info details to see how often we get invalid values. | 425 // Keep track of device info details to see how often we get invalid values. | 
| 427 MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, name); | 426 MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, name); | 
| 428 if (unique_id.empty() || name.empty()) | 427 if (unique_id.empty() || name.empty()) | 
| 429 return; | 428 return; | 
| 430 | 429 | 
| 431 bool has_dcim = IsMediaDevice(mount_point.value()); | 430 bool has_dcim = MediaStorageUtil::HasDcim(mount_point.value()); | 
| 432 MediaStorageUtil::Type type; | 431 MediaStorageUtil::Type type; | 
| 433 if (removable) { | 432 if (removable) { | 
| 434 if (has_dcim) { | 433 if (has_dcim) { | 
| 435 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 434 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM; | 
| 436 } else { | 435 } else { | 
| 437 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | 436 type = MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | 
| 438 } | 437 } | 
| 439 } else { | 438 } else { | 
| 440 type = MediaStorageUtil::FIXED_MASS_STORAGE; | 439 type = MediaStorageUtil::FIXED_MASS_STORAGE; | 
| 441 } | 440 } | 
| 442 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 441 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 
| 443 | 442 | 
| 444 MountPointInfo mount_point_info; | 443 MountPointInfo mount_point_info; | 
| 445 mount_point_info.mount_device = mount_device; | 444 mount_point_info.mount_device = mount_device; | 
| 446 mount_point_info.device_id = device_id; | 445 mount_point_info.device_id = device_id; | 
| 447 mount_point_info.device_name = name; | 446 mount_point_info.device_name = name; | 
| 448 mount_point_info.partition_size_in_bytes = partition_size_in_bytes; | 447 mount_point_info.partition_size_in_bytes = partition_size_in_bytes; | 
| 449 | 448 | 
| 450 mount_info_map_[mount_point] = mount_point_info; | 449 mount_info_map_[mount_point] = mount_point_info; | 
| 451 mount_priority_map_[mount_device][mount_point] = removable; | 450 mount_priority_map_[mount_device][mount_point] = removable; | 
| 452 | 451 | 
| 453 if (removable) { | 452 if (removable) { | 
| 454 receiver()->ProcessAttach(StorageInfo( | 453 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( | 
| 455 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), | 454 partition_size_in_bytes, name); | 
| 456 mount_point.value())); | 455 | 
| 456 StorageInfo storage_info(device_id, display_name, mount_point.value()); | |
| 
 
Greg Billock
2013/03/06 21:48:27
I'd get rid of this temporary here and elsewhere.
 
 | |
| 457 receiver()->ProcessAttach(storage_info); | |
| 457 } | 458 } | 
| 458 } | 459 } | 
| 459 | 460 | 
| 460 } // namespace chrome | 461 } // namespace chrome | 
| OLD | NEW |