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