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 // 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 20 matching lines...) Expand all Loading... | |
| 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 |
| 65 bool IsRemovableStorageAttached(const std::string& id) { | 63 bool IsRemovableStorageAttached(const std::string& id) { |
| 66 std::vector<SystemMonitor::RemovableStorageInfo> media_devices = | 64 typedef std::vector<RemovableStorageNotifications::StorageInfo> |
| 67 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 65 StorageInfoList; |
| 68 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = | 66 StorageInfoList devices = |
| 69 media_devices.begin(); | 67 RemovableStorageNotifications::GetInstance()->GetAttachedStorage(); |
| 70 it != media_devices.end(); | 68 for (StorageInfoList::const_iterator it = devices.begin(); |
| 69 it != devices.end(); | |
| 71 ++it) { | 70 ++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 std::vector<RemovableStorageNotifications::StorageInfo> devices = |
| 81 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 80 RemovableStorageNotifications::GetInstance()->GetAttachedStorage(); |
| 82 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = | 81 for (std::vector<RemovableStorageNotifications::StorageInfo>:: |
|
vandebo (ex-Chrome)
2013/01/26 01:00:21
One more instance here.
Greg Billock
2013/01/26 01:42:07
Done.
| |
| 83 media_devices.begin(); | 82 const_iterator it = devices.begin(); |
| 84 it != media_devices.end(); | 83 it != devices.end(); |
| 85 ++it) { | 84 ++it) { |
| 86 if (it->device_id == device_id) | 85 if (it->device_id == device_id) |
| 87 return it->location; | 86 return it->location; |
| 88 } | 87 } |
| 89 return FilePath::StringType(); | 88 return FilePath::StringType(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { | 91 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 94 MediaStorageUtil::DeviceIdSet missing_devices; | 93 MediaStorageUtil::DeviceIdSet missing_devices; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 if (type == FIXED_MASS_STORAGE) { | 234 if (type == FIXED_MASS_STORAGE) { |
| 236 // For this type, the unique_id is the path. | 235 // For this type, the unique_id is the path. |
| 237 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 236 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 238 base::Bind(&ValidatePathOnFileThread, | 237 base::Bind(&ValidatePathOnFileThread, |
| 239 FilePath::FromUTF8Unsafe(unique_id), | 238 FilePath::FromUTF8Unsafe(unique_id), |
| 240 callback)); | 239 callback)); |
| 241 } else { | 240 } else { |
| 242 DCHECK(type == MTP_OR_PTP || | 241 DCHECK(type == MTP_OR_PTP || |
| 243 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || | 242 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
| 244 type == REMOVABLE_MASS_STORAGE_NO_DCIM); | 243 type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 245 // We should be able to find removable storage in SystemMonitor. | 244 // We should be able to find removable storage. |
| 246 callback.Run(IsRemovableStorageAttached(device_id)); | 245 callback.Run(IsRemovableStorageAttached(device_id)); |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 | 248 |
| 250 // static | 249 // static |
| 251 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, | 250 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, |
| 252 const base::Closure& done) { | 251 const base::Closure& done) { |
| 253 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 252 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 254 FilterAttachedDevicesOnFileThread(devices); | 253 FilterAttachedDevicesOnFileThread(devices); |
| 255 done.Run(); | 254 done.Run(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 270 if (!path.IsAbsolute()) | 269 if (!path.IsAbsolute()) |
| 271 return false; | 270 return false; |
| 272 | 271 |
| 273 if (g_test_get_device_info_from_path_function) { | 272 if (g_test_get_device_info_from_path_function) { |
| 274 return g_test_get_device_info_from_path_function(path, device_id, | 273 return g_test_get_device_info_from_path_function(path, device_id, |
| 275 device_name, | 274 device_name, |
| 276 relative_path); | 275 relative_path); |
| 277 } | 276 } |
| 278 | 277 |
| 279 bool found_device = false; | 278 bool found_device = false; |
| 280 base::SystemMonitor::RemovableStorageInfo device_info; | 279 RemovableStorageNotifications::StorageInfo device_info; |
| 281 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) | 280 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
| 282 RemovableStorageNotifications* notifier = | 281 RemovableStorageNotifications* notifier = |
| 283 RemovableStorageNotifications::GetInstance(); | 282 RemovableStorageNotifications::GetInstance(); |
| 284 found_device = notifier->GetDeviceInfoForPath(path, &device_info); | 283 found_device = notifier->GetDeviceInfoForPath(path, &device_info); |
| 285 #endif | 284 #endif |
| 286 | 285 |
| 287 #if defined(OS_LINUX) | 286 #if defined(OS_LINUX) |
| 288 if (!found_device) { | 287 if (!found_device) { |
| 289 MediaTransferProtocolDeviceObserverLinux* mtp_manager = | 288 MediaTransferProtocolDeviceObserverLinux* mtp_manager = |
| 290 MediaTransferProtocolDeviceObserverLinux::GetInstance(); | 289 MediaTransferProtocolDeviceObserverLinux::GetInstance(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 DEVICE_INFO_BUCKET_BOUNDARY); | 382 DEVICE_INFO_BUCKET_BOUNDARY); |
| 384 } | 383 } |
| 385 | 384 |
| 386 // static | 385 // static |
| 387 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 386 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
| 388 GetDeviceInfoFromPathFunction function) { | 387 GetDeviceInfoFromPathFunction function) { |
| 389 g_test_get_device_info_from_path_function = function; | 388 g_test_get_device_info_from_path_function = function; |
| 390 } | 389 } |
| 391 | 390 |
| 392 } // namespace chrome | 391 } // namespace chrome |
| OLD | NEW |