Index: chrome/browser/system_monitor/media_storage_util.cc |
diff --git a/chrome/browser/system_monitor/media_storage_util.cc b/chrome/browser/system_monitor/media_storage_util.cc |
index e4f69b4de0b6d93e40ecdea87e38a638317bb364..7c5570fcc4423472db0723180d7a52bb8b4d5a05 100644 |
--- a/chrome/browser/system_monitor/media_storage_util.cc |
+++ b/chrome/browser/system_monitor/media_storage_util.cc |
@@ -34,12 +34,12 @@ |
using base::SystemMonitor; |
using content::BrowserThread; |
+const char kRootPath[] = "/"; |
+ |
namespace chrome { |
namespace { |
-typedef std::vector<SystemMonitor::RemovableStorageInfo> RemovableStorageInfo; |
- |
// MediaDeviceNotification.DeviceInfo histogram values. |
enum DeviceInfoHistogramBuckets { |
MASS_STORAGE_DEVICE_NAME_AND_UUID_AVAILABLE, |
@@ -58,6 +58,7 @@ const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; |
const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; |
const char kFixedMassStoragePrefix[] = "path:"; |
const char kMtpPtpPrefix[] = "mtp:"; |
+const char kMacImageCapture[] = "ic:"; |
static bool (*g_test_get_device_info_from_path_function)( // NOLINT |
const FilePath& path, std::string* device_id, string16* device_name, |
@@ -70,11 +71,25 @@ void ValidatePathOnFileThread( |
base::Bind(callback, file_util::PathExists(path))); |
} |
+bool IsRemovableStorageAttached(const std::string& id) { |
+ std::vector<SystemMonitor::RemovableStorageInfo> media_devices = |
+ SystemMonitor::Get()->GetAttachedRemovableStorage(); |
+ for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = |
+ media_devices.begin(); |
+ it != media_devices.end(); |
+ ++it) { |
+ if (it->device_id == id) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
FilePath::StringType FindRemovableStorageLocationById( |
const std::string& device_id) { |
- RemovableStorageInfo media_devices = |
+ std::vector<SystemMonitor::RemovableStorageInfo> media_devices = |
SystemMonitor::Get()->GetAttachedRemovableStorage(); |
- for (RemovableStorageInfo::const_iterator it = media_devices.begin(); |
+ for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = |
+ media_devices.begin(); |
it != media_devices.end(); |
++it) { |
if (it->device_id == device_id) |
@@ -103,10 +118,7 @@ void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { |
continue; |
} |
- DCHECK(type == MediaStorageUtil::MTP_OR_PTP || |
- type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM || |
- type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); |
- if (FindRemovableStorageLocationById(*it).empty()) |
+ if (!IsRemovableStorageAttached(*it)) |
missing_devices.insert(*it); |
} |
@@ -133,6 +145,8 @@ std::string MediaStorageUtil::MakeDeviceId(Type type, |
return std::string(kFixedMassStoragePrefix) + unique_id; |
case MTP_OR_PTP: |
return std::string(kMtpPtpPrefix) + unique_id; |
+ case MAC_IMAGE_CAPTURE: |
+ return std::string(kMacImageCapture) + unique_id; |
} |
NOTREACHED(); |
return std::string(); |
@@ -154,6 +168,8 @@ bool MediaStorageUtil::CrackDeviceId(const std::string& device_id, |
found_type = FIXED_MASS_STORAGE; |
} else if (prefix == kMtpPtpPrefix) { |
found_type = MTP_OR_PTP; |
+ } else if (prefix == kMacImageCapture) { |
+ found_type = MAC_IMAGE_CAPTURE; |
} else { |
NOTREACHED(); |
return false; |
@@ -170,7 +186,8 @@ bool MediaStorageUtil::CrackDeviceId(const std::string& device_id, |
bool MediaStorageUtil::IsMediaDevice(const std::string& device_id) { |
Type type; |
return CrackDeviceId(device_id, &type, NULL) && |
- (type == REMOVABLE_MASS_STORAGE_WITH_DCIM || type == MTP_OR_PTP); |
+ (type == REMOVABLE_MASS_STORAGE_WITH_DCIM || type == MTP_OR_PTP || |
+ type == MAC_IMAGE_CAPTURE); |
} |
// static |
@@ -182,7 +199,23 @@ bool MediaStorageUtil::IsRemovableDevice(const std::string& device_id) { |
// static |
bool MediaStorageUtil::IsMassStorageDevice(const std::string& device_id) { |
Type type; |
- return CrackDeviceId(device_id, &type, NULL) && type != MTP_OR_PTP; |
+ return CrackDeviceId(device_id, &type, NULL) && |
+ (type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
+ type == REMOVABLE_MASS_STORAGE_NO_DCIM || |
+ type == FIXED_MASS_STORAGE); |
+} |
+ |
+// static |
+bool MediaStorageUtil::CanCreateFileSystem(const std::string& device_id, |
+ const FilePath& path) { |
+ Type type; |
+ if (!CrackDeviceId(device_id, &type, NULL)) |
+ return false; |
+ |
+ if (type == MAC_IMAGE_CAPTURE) |
+ return true; |
+ |
+ return path.IsAbsolute() && !path.ReferencesParent(); |
} |
// static |
@@ -206,7 +239,7 @@ void MediaStorageUtil::IsDeviceAttached(const std::string& device_id, |
type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
// We should be able to find removable storage in SystemMonitor. |
- callback.Run(!FindRemovableStorageLocationById(device_id).empty()); |
+ callback.Run(IsRemovableStorageAttached(device_id)); |
} |
} |
@@ -310,6 +343,14 @@ FilePath MediaStorageUtil::FindDevicePathById(const std::string& device_id) { |
return FilePath::FromUTF8Unsafe(unique_id); |
} |
+ // For ImageCapture, the synthetic filesystem will be rooted at a fake |
+ // top-level directory which is the device_id. |
+ if (type == MAC_IMAGE_CAPTURE) { |
+#if !defined(OS_WIN) |
+ return FilePath(kRootPath + device_id); |
+#endif |
+ } |
+ |
DCHECK(type == MTP_OR_PTP || |
type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
type == REMOVABLE_MASS_STORAGE_NO_DCIM); |