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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return false; | 228 return false; |
229 | 229 |
230 if (g_test_get_device_info_from_path_function) { | 230 if (g_test_get_device_info_from_path_function) { |
231 return g_test_get_device_info_from_path_function(path, device_id, | 231 return g_test_get_device_info_from_path_function(path, device_id, |
232 device_name, | 232 device_name, |
233 relative_path); | 233 relative_path); |
234 } | 234 } |
235 | 235 |
236 bool found_device = false; | 236 bool found_device = false; |
237 base::SystemMonitor::RemovableStorageInfo device_info; | 237 base::SystemMonitor::RemovableStorageInfo device_info; |
238 #if (defined(OS_LINUX) || defined(OS_MACOSX)) | 238 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
239 RemovableDeviceNotifications* notifier = | 239 RemovableDeviceNotifications* notifier = |
240 RemovableDeviceNotifications::GetInstance(); | 240 RemovableDeviceNotifications::GetInstance(); |
241 found_device = notifier->GetDeviceInfoForPath(path, &device_info); | 241 found_device = notifier->GetDeviceInfoForPath(path, &device_info); |
242 #endif | 242 #endif |
243 | 243 |
244 #if defined(OS_CHROMEOS) | 244 #if defined(OS_CHROMEOS) |
245 if (!found_device) { | 245 if (!found_device) { |
246 chromeos::mtp::MediaTransferProtocolDeviceObserverCros* mtp_manager = | 246 chromeos::mtp::MediaTransferProtocolDeviceObserverCros* mtp_manager = |
247 chromeos::mtp::MediaTransferProtocolDeviceObserverCros::GetInstance(); | 247 chromeos::mtp::MediaTransferProtocolDeviceObserverCros::GetInstance(); |
248 found_device = mtp_manager->GetStorageInfoForPath(path, &device_info); | 248 found_device = mtp_manager->GetStorageInfoForPath(path, &device_info); |
249 } | 249 } |
250 #endif | 250 #endif |
251 | 251 |
252 if (found_device && IsRemovableDevice(device_info.device_id)) { | 252 if (found_device && IsRemovableDevice(device_info.device_id)) { |
253 if (device_id) | 253 if (device_id) |
254 *device_id = device_info.device_id; | 254 *device_id = device_info.device_id; |
255 if (device_name) | 255 if (device_name) |
256 *device_name = device_info.name; | 256 *device_name = device_info.name; |
257 if (relative_path) { | 257 if (relative_path) { |
258 *relative_path = FilePath(); | 258 *relative_path = FilePath(); |
259 FilePath mount_point(device_info.location); | 259 FilePath mount_point(device_info.location); |
260 mount_point.AppendRelativePath(path, relative_path); | 260 mount_point.AppendRelativePath(path, relative_path); |
261 } | 261 } |
262 return true; | 262 return true; |
263 } | 263 } |
264 | 264 |
| 265 // On Posix systems, there's one root so any absolute path could be valid. |
| 266 #if !defined(OS_POSIX) |
| 267 if (!found_device) |
| 268 return false; |
| 269 #endif |
| 270 |
265 if (device_id) | 271 if (device_id) |
266 *device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); | 272 *device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); |
267 if (device_name) | 273 if (device_name) |
268 *device_name = path.BaseName().LossyDisplayName(); | 274 *device_name = path.BaseName().LossyDisplayName(); |
269 if (relative_path) | 275 if (relative_path) |
270 *relative_path = FilePath(); | 276 *relative_path = FilePath(); |
271 return true; | 277 return true; |
272 } | 278 } |
273 | 279 |
274 // static | 280 // static |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 320 |
315 // static | 321 // static |
316 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 322 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
317 GetDeviceInfoFromPathFunction function) { | 323 GetDeviceInfoFromPathFunction function) { |
318 g_test_get_device_info_from_path_function = function; | 324 g_test_get_device_info_from_path_function = function; |
319 } | 325 } |
320 | 326 |
321 MediaStorageUtil::MediaStorageUtil() {} | 327 MediaStorageUtil::MediaStorageUtil() {} |
322 | 328 |
323 } // namespace chrome | 329 } // namespace chrome |
OLD | NEW |