| 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 std::vector<RemovableStorageNotifications::StorageInfo> devices = |
| 67 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 65 RemovableStorageNotifications::GetInstance()->GetAttachedStorage(); |
| 68 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = | 66 for (std::vector<RemovableStorageNotifications::StorageInfo>:: |
| 69 media_devices.begin(); | 67 const_iterator it = devices.begin(); |
| 70 it != media_devices.end(); | 68 it != devices.end(); |
| 71 ++it) { | 69 ++it) { |
| 72 if (it->device_id == id) | 70 if (it->device_id == id) |
| 73 return true; | 71 return true; |
| 74 } | 72 } |
| 75 return false; | 73 return false; |
| 76 } | 74 } |
| 77 | 75 |
| 78 FilePath::StringType FindRemovableStorageLocationById( | 76 FilePath::StringType FindRemovableStorageLocationById( |
| 79 const std::string& device_id) { | 77 const std::string& device_id) { |
| 80 std::vector<SystemMonitor::RemovableStorageInfo> media_devices = | 78 std::vector<RemovableStorageNotifications::StorageInfo> devices = |
| 81 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 79 RemovableStorageNotifications::GetInstance()->GetAttachedStorage(); |
| 82 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = | 80 for (std::vector<RemovableStorageNotifications::StorageInfo>:: |
| 83 media_devices.begin(); | 81 const_iterator it = devices.begin(); |
| 84 it != media_devices.end(); | 82 it != devices.end(); |
| 85 ++it) { | 83 ++it) { |
| 86 if (it->device_id == device_id) | 84 if (it->device_id == device_id) |
| 87 return it->location; | 85 return it->location; |
| 88 } | 86 } |
| 89 return FilePath::StringType(); | 87 return FilePath::StringType(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { | 90 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 94 MediaStorageUtil::DeviceIdSet missing_devices; | 92 MediaStorageUtil::DeviceIdSet missing_devices; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (type == FIXED_MASS_STORAGE) { | 220 if (type == FIXED_MASS_STORAGE) { |
| 223 // For this type, the unique_id is the path. | 221 // For this type, the unique_id is the path. |
| 224 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 222 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 225 base::Bind(&ValidatePathOnFileThread, | 223 base::Bind(&ValidatePathOnFileThread, |
| 226 FilePath::FromUTF8Unsafe(unique_id), | 224 FilePath::FromUTF8Unsafe(unique_id), |
| 227 callback)); | 225 callback)); |
| 228 } else { | 226 } else { |
| 229 DCHECK(type == MTP_OR_PTP || | 227 DCHECK(type == MTP_OR_PTP || |
| 230 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || | 228 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
| 231 type == REMOVABLE_MASS_STORAGE_NO_DCIM); | 229 type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 232 // We should be able to find removable storage in SystemMonitor. | 230 // We should be able to find removable storage. |
| 233 callback.Run(IsRemovableStorageAttached(device_id)); | 231 callback.Run(IsRemovableStorageAttached(device_id)); |
| 234 } | 232 } |
| 235 } | 233 } |
| 236 | 234 |
| 237 // static | 235 // static |
| 238 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, | 236 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, |
| 239 const base::Closure& done) { | 237 const base::Closure& done) { |
| 240 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 238 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 241 FilterAttachedDevicesOnFileThread(devices); | 239 FilterAttachedDevicesOnFileThread(devices); |
| 242 done.Run(); | 240 done.Run(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 256 if (!path.IsAbsolute()) | 254 if (!path.IsAbsolute()) |
| 257 return false; | 255 return false; |
| 258 | 256 |
| 259 if (g_test_get_device_info_from_path_function) { | 257 if (g_test_get_device_info_from_path_function) { |
| 260 return g_test_get_device_info_from_path_function(path, device_id, | 258 return g_test_get_device_info_from_path_function(path, device_id, |
| 261 device_name, | 259 device_name, |
| 262 relative_path); | 260 relative_path); |
| 263 } | 261 } |
| 264 | 262 |
| 265 bool found_device = false; | 263 bool found_device = false; |
| 266 base::SystemMonitor::RemovableStorageInfo device_info; | 264 RemovableStorageNotifications::StorageInfo device_info; |
| 267 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) | 265 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
| 268 RemovableStorageNotifications* notifier = | 266 RemovableStorageNotifications* notifier = |
| 269 RemovableStorageNotifications::GetInstance(); | 267 RemovableStorageNotifications::GetInstance(); |
| 270 found_device = notifier->GetDeviceInfoForPath(path, &device_info); | 268 found_device = notifier->GetDeviceInfoForPath(path, &device_info); |
| 271 #endif | 269 #endif |
| 272 | 270 |
| 273 #if defined(OS_LINUX) | 271 #if defined(OS_LINUX) |
| 274 if (!found_device) { | 272 if (!found_device) { |
| 275 MediaTransferProtocolDeviceObserverLinux* mtp_manager = | 273 MediaTransferProtocolDeviceObserverLinux* mtp_manager = |
| 276 MediaTransferProtocolDeviceObserverLinux::GetInstance(); | 274 MediaTransferProtocolDeviceObserverLinux::GetInstance(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 DEVICE_INFO_BUCKET_BOUNDARY); | 369 DEVICE_INFO_BUCKET_BOUNDARY); |
| 372 } | 370 } |
| 373 | 371 |
| 374 // static | 372 // static |
| 375 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 373 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
| 376 GetDeviceInfoFromPathFunction function) { | 374 GetDeviceInfoFromPathFunction function) { |
| 377 g_test_get_device_info_from_path_function = function; | 375 g_test_get_device_info_from_path_function = function; |
| 378 } | 376 } |
| 379 | 377 |
| 380 } // namespace chrome | 378 } // namespace chrome |
| OLD | NEW |