| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/system_monitor/system_monitor.h" | |
| 16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" | 16 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
| 18 #include "chrome/browser/system_monitor/removable_storage_notifications.h" | 17 #include "chrome/browser/system_monitor/removable_storage_notifications.h" |
| 19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 20 | 19 |
| 21 #if defined(OS_LINUX) // Implies OS_CHROMEOS | 20 #if defined(OS_LINUX) // Implies OS_CHROMEOS |
| 22 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_
linux.h" | 21 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_
linux.h" |
| 23 #endif | 22 #endif |
| 24 | 23 |
| 25 using base::SystemMonitor; | |
| 26 using content::BrowserThread; | 24 using content::BrowserThread; |
| 27 | 25 |
| 28 const char kRootPath[] = "/"; | 26 const char kRootPath[] = "/"; |
| 29 | 27 |
| 30 namespace chrome { | 28 namespace chrome { |
| 31 | 29 |
| 32 namespace { | 30 namespace { |
| 33 | 31 |
| 34 // MediaDeviceNotification.DeviceInfo histogram values. | 32 // MediaDeviceNotification.DeviceInfo histogram values. |
| 35 enum DeviceInfoHistogramBuckets { | 33 enum DeviceInfoHistogramBuckets { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 const FilePath& path, std::string* device_id, string16* device_name, | 53 const FilePath& path, std::string* device_id, string16* device_name, |
| 56 FilePath* relative_path) = NULL; | 54 FilePath* relative_path) = NULL; |
| 57 | 55 |
| 58 void ValidatePathOnFileThread( | 56 void ValidatePathOnFileThread( |
| 59 const FilePath& path, const MediaStorageUtil::BoolCallback& callback) { | 57 const FilePath& path, const MediaStorageUtil::BoolCallback& callback) { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 61 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 59 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 62 base::Bind(callback, file_util::PathExists(path))); | 60 base::Bind(callback, file_util::PathExists(path))); |
| 63 } | 61 } |
| 64 | 62 |
| 63 typedef std::vector<RemovableStorageNotifications::StorageInfo> |
| 64 StorageInfoList; |
| 65 |
| 65 bool IsRemovableStorageAttached(const std::string& id) { | 66 bool IsRemovableStorageAttached(const std::string& id) { |
| 66 std::vector<SystemMonitor::RemovableStorageInfo> media_devices = | 67 StorageInfoList devices = |
| 67 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 68 RemovableStorageNotifications::GetInstance()->GetAttachedStorage(); |
| 68 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = | 69 for (StorageInfoList::const_iterator it = devices.begin(); |
| 69 media_devices.begin(); | 70 it != devices.end(); ++it) { |
| 70 it != media_devices.end(); | |
| 71 ++it) { | |
| 72 if (it->device_id == id) | 71 if (it->device_id == id) |
| 73 return true; | 72 return true; |
| 74 } | 73 } |
| 75 return false; | 74 return false; |
| 76 } | 75 } |
| 77 | 76 |
| 78 FilePath::StringType FindRemovableStorageLocationById( | 77 FilePath::StringType FindRemovableStorageLocationById( |
| 79 const std::string& device_id) { | 78 const std::string& device_id) { |
| 80 std::vector<SystemMonitor::RemovableStorageInfo> media_devices = | 79 StorageInfoList devices = |
| 81 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 80 RemovableStorageNotifications::GetInstance()->GetAttachedStorage(); |
| 82 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = | 81 for (StorageInfoList::const_iterator it = devices.begin(); |
| 83 media_devices.begin(); | 82 it != devices.end(); ++it) { |
| 84 it != media_devices.end(); | |
| 85 ++it) { | |
| 86 if (it->device_id == device_id) | 83 if (it->device_id == device_id) |
| 87 return it->location; | 84 return it->location; |
| 88 } | 85 } |
| 89 return FilePath::StringType(); | 86 return FilePath::StringType(); |
| 90 } | 87 } |
| 91 | 88 |
| 92 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { | 89 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 94 MediaStorageUtil::DeviceIdSet missing_devices; | 91 MediaStorageUtil::DeviceIdSet missing_devices; |
| 95 | 92 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (type == FIXED_MASS_STORAGE) { | 232 if (type == FIXED_MASS_STORAGE) { |
| 236 // For this type, the unique_id is the path. | 233 // For this type, the unique_id is the path. |
| 237 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 234 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 238 base::Bind(&ValidatePathOnFileThread, | 235 base::Bind(&ValidatePathOnFileThread, |
| 239 FilePath::FromUTF8Unsafe(unique_id), | 236 FilePath::FromUTF8Unsafe(unique_id), |
| 240 callback)); | 237 callback)); |
| 241 } else { | 238 } else { |
| 242 DCHECK(type == MTP_OR_PTP || | 239 DCHECK(type == MTP_OR_PTP || |
| 243 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || | 240 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
| 244 type == REMOVABLE_MASS_STORAGE_NO_DCIM); | 241 type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 245 // We should be able to find removable storage in SystemMonitor. | 242 // We should be able to find removable storage. |
| 246 callback.Run(IsRemovableStorageAttached(device_id)); | 243 callback.Run(IsRemovableStorageAttached(device_id)); |
| 247 } | 244 } |
| 248 } | 245 } |
| 249 | 246 |
| 250 // static | 247 // static |
| 251 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, | 248 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, |
| 252 const base::Closure& done) { | 249 const base::Closure& done) { |
| 253 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 250 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 254 FilterAttachedDevicesOnFileThread(devices); | 251 FilterAttachedDevicesOnFileThread(devices); |
| 255 done.Run(); | 252 done.Run(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 if (!path.IsAbsolute()) | 267 if (!path.IsAbsolute()) |
| 271 return false; | 268 return false; |
| 272 | 269 |
| 273 if (g_test_get_device_info_from_path_function) { | 270 if (g_test_get_device_info_from_path_function) { |
| 274 return g_test_get_device_info_from_path_function(path, device_id, | 271 return g_test_get_device_info_from_path_function(path, device_id, |
| 275 device_name, | 272 device_name, |
| 276 relative_path); | 273 relative_path); |
| 277 } | 274 } |
| 278 | 275 |
| 279 bool found_device = false; | 276 bool found_device = false; |
| 280 base::SystemMonitor::RemovableStorageInfo device_info; | 277 RemovableStorageNotifications::StorageInfo device_info; |
| 281 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) | 278 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
| 282 RemovableStorageNotifications* notifier = | 279 RemovableStorageNotifications* notifier = |
| 283 RemovableStorageNotifications::GetInstance(); | 280 RemovableStorageNotifications::GetInstance(); |
| 284 found_device = notifier->GetDeviceInfoForPath(path, &device_info); | 281 found_device = notifier->GetDeviceInfoForPath(path, &device_info); |
| 285 #endif | 282 #endif |
| 286 | 283 |
| 287 #if defined(OS_LINUX) | 284 #if defined(OS_LINUX) |
| 288 if (!found_device) { | 285 if (!found_device) { |
| 289 MediaTransferProtocolDeviceObserverLinux* mtp_manager = | 286 MediaTransferProtocolDeviceObserverLinux* mtp_manager = |
| 290 MediaTransferProtocolDeviceObserverLinux::GetInstance(); | 287 MediaTransferProtocolDeviceObserverLinux::GetInstance(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 DEVICE_INFO_BUCKET_BOUNDARY); | 380 DEVICE_INFO_BUCKET_BOUNDARY); |
| 384 } | 381 } |
| 385 | 382 |
| 386 // static | 383 // static |
| 387 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 384 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
| 388 GetDeviceInfoFromPathFunction function) { | 385 GetDeviceInfoFromPathFunction function) { |
| 389 g_test_get_device_info_from_path_function = function; | 386 g_test_get_device_info_from_path_function = function; |
| 390 } | 387 } |
| 391 | 388 |
| 392 } // namespace chrome | 389 } // namespace chrome |
| OLD | NEW |