| 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 // chrome::MediaStorageUtil implementation. | 5 // chrome::MediaStorageUtil implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/media_storage_util.h" | 7 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 typedef std::vector<SystemMonitor::RemovableStorageInfo> RemovableStorageInfo; | 24 typedef std::vector<SystemMonitor::RemovableStorageInfo> RemovableStorageInfo; |
| 25 | 25 |
| 26 // Prefix constants for different device id spaces. | 26 // Prefix constants for different device id spaces. |
| 27 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; | 27 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; |
| 28 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; | 28 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; |
| 29 const char kFixedMassStoragePrefix[] = "path:"; | 29 const char kFixedMassStoragePrefix[] = "path:"; |
| 30 const char kMtpPtpPrefix[] = "mtp:"; | 30 const char kMtpPtpPrefix[] = "mtp:"; |
| 31 | 31 |
| 32 static void (*g_test_get_device_info_from_path_function)( | 32 static bool (*g_test_get_device_info_from_path_function)( |
| 33 const FilePath& path, std::string* device_id, string16* device_name, | 33 const FilePath& path, std::string* device_id, string16* device_name, |
| 34 FilePath* relative_path) = NULL; | 34 FilePath* relative_path) = NULL; |
| 35 | 35 |
| 36 void ValidatePathOnFileThread( | 36 void ValidatePathOnFileThread( |
| 37 const FilePath& path, const MediaStorageUtil::BoolCallback& callback) { | 37 const FilePath& path, const MediaStorageUtil::BoolCallback& callback) { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 40 base::Bind(callback, file_util::PathExists(path))); | 40 base::Bind(callback, file_util::PathExists(path))); |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } else { | 139 } else { |
| 140 DCHECK(type == MTP_OR_PTP || | 140 DCHECK(type == MTP_OR_PTP || |
| 141 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || | 141 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
| 142 type == REMOVABLE_MASS_STORAGE_NO_DCIM); | 142 type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 143 // We should be able to find removable storage in SystemMonitor. | 143 // We should be able to find removable storage in SystemMonitor. |
| 144 callback.Run(!FindRemovableStorageLocationById(device_id).empty()); | 144 callback.Run(!FindRemovableStorageLocationById(device_id).empty()); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 // static | 148 // static |
| 149 void MediaStorageUtil::GetDeviceInfoFromPath(const FilePath& path, | 149 bool MediaStorageUtil::GetDeviceInfoFromPath(const FilePath& path, |
| 150 std::string* device_id, | 150 std::string* device_id, |
| 151 string16* device_name, | 151 string16* device_name, |
| 152 FilePath* relative_path) { | 152 FilePath* relative_path) { |
| 153 if (g_test_get_device_info_from_path_function) { | 153 if (g_test_get_device_info_from_path_function) { |
| 154 g_test_get_device_info_from_path_function(path, device_id, device_name, | 154 return g_test_get_device_info_from_path_function(path, device_id, |
| 155 relative_path); | 155 device_name, |
| 156 relative_path); |
| 156 } else { | 157 } else { |
| 157 GetDeviceInfoFromPathImpl(path, device_id, device_name, relative_path); | 158 return GetDeviceInfoFromPathImpl(path, device_id, device_name, |
| 159 relative_path); |
| 158 } | 160 } |
| 159 } | 161 } |
| 160 | 162 |
| 161 // static | 163 // static |
| 162 FilePath MediaStorageUtil::FindDevicePathById(const std::string& device_id) { | 164 FilePath MediaStorageUtil::FindDevicePathById(const std::string& device_id) { |
| 163 Type type; | 165 Type type; |
| 164 std::string unique_id; | 166 std::string unique_id; |
| 165 if (!CrackDeviceId(device_id, &type, &unique_id)) | 167 if (!CrackDeviceId(device_id, &type, &unique_id)) |
| 166 return FilePath(); | 168 return FilePath(); |
| 167 | 169 |
| 168 if (type == FIXED_MASS_STORAGE) { | 170 if (type == FIXED_MASS_STORAGE) { |
| 169 // For this type, the unique_id is the path. | 171 // For this type, the unique_id is the path. |
| 170 return FilePath::FromUTF8Unsafe(unique_id); | 172 return FilePath::FromUTF8Unsafe(unique_id); |
| 171 } | 173 } |
| 172 | 174 |
| 173 DCHECK(type == MTP_OR_PTP || | 175 DCHECK(type == MTP_OR_PTP || |
| 174 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || | 176 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
| 175 type == REMOVABLE_MASS_STORAGE_NO_DCIM); | 177 type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 176 return FilePath(FindRemovableStorageLocationById(device_id)); | 178 return FilePath(FindRemovableStorageLocationById(device_id)); |
| 177 } | 179 } |
| 178 | 180 |
| 179 // static | 181 // static |
| 180 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 182 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
| 181 GetDeviceInfoFromPathFunction function) { | 183 GetDeviceInfoFromPathFunction function) { |
| 182 g_test_get_device_info_from_path_function = function; | 184 g_test_get_device_info_from_path_function = function; |
| 183 } | 185 } |
| 184 | 186 |
| 185 MediaStorageUtil::MediaStorageUtil() {} | 187 MediaStorageUtil::MediaStorageUtil() {} |
| 186 | 188 |
| 187 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) | 189 #if !defined(OS_WIN) || !defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 188 // static | 190 // static |
| 189 void MediaStorageUtil::GetDeviceInfoFromPathImpl(const FilePath& path, | 191 bool MediaStorageUtil::GetDeviceInfoFromPathImpl(const FilePath& path, |
| 190 std::string* device_id, | 192 std::string* device_id, |
| 191 string16* device_name, | 193 string16* device_name, |
| 192 FilePath* relative_path) { | 194 FilePath* relative_path) { |
| 193 // TODO(vandebo) This needs to be implemented per platform. Below is no | 195 // TODO(vandebo) This needs to be implemented per platform. Below is no |
| 194 // worse than what the code already does. | 196 // worse than what the code already does. |
| 195 // * Find mount point parent (determines relative file path) | 197 // * Find mount point parent (determines relative file path) |
| 196 // * Search System monitor, just in case. | 198 // * Search System monitor, just in case. |
| 197 // * If it's a removable device, generate device id, else use device root | 199 // * If it's a removable device, generate device id, else use device root |
| 198 // path as id | 200 // path as id |
| 199 if (device_id) | 201 if (device_id) |
| 200 *device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); | 202 *device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); |
| 201 if (device_name) | 203 if (device_name) |
| 202 *device_name = path.BaseName().LossyDisplayName(); | 204 *device_name = path.BaseName().LossyDisplayName(); |
| 203 if (relative_path) | 205 if (relative_path) |
| 204 *relative_path = FilePath(); | 206 *relative_path = FilePath(); |
| 207 return true; |
| 205 } | 208 } |
| 206 #endif | 209 #endif |
| 207 | 210 |
| 208 } // namespace chrome | 211 } // namespace chrome |
| OLD | NEW |