Chromium Code Reviews| Index: chrome/browser/system_monitor/portable_device_watcher_win.cc |
| diff --git a/chrome/browser/system_monitor/portable_device_watcher_win.cc b/chrome/browser/system_monitor/portable_device_watcher_win.cc |
| index 70a5d6800e8177fa850502443841a1abb9bd76a1..4edde6e8074776df36684fe380d42de6923226a1 100644 |
| --- a/chrome/browser/system_monitor/portable_device_watcher_win.cc |
| +++ b/chrome/browser/system_monitor/portable_device_watcher_win.cc |
| @@ -516,6 +516,34 @@ void PortableDeviceWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) { |
| HandleDeviceDetachEvent(device_id); |
| } |
| +bool PortableDeviceWatcherWin::GetMTPStorageInfoFromDeviceId( |
| + const std::string& storage_device_id, |
| + string16* device_location, |
| + string16* storage_object_id) { |
| + DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
|
Peter Kasting
2012/12/21 18:13:30
This is scary. What if the UI thread deletes the
kmadhusu
2013/01/02 19:48:31
There is a chance that the UI thread may delete th
Peter Kasting
2013/01/04 21:13:38
It might be nice to have DCHECKs that you're on th
kmadhusu
2013/01/04 22:14:32
Done.
|
| + DCHECK(device_location); |
| + DCHECK(storage_object_id); |
| + base::AutoLock locked(lock_); |
| + MTPStorageMap::const_iterator storage_map_iter = |
| + storage_map_.find(storage_device_id); |
| + if (storage_map_iter == storage_map_.end()) |
| + return false; |
| + |
| + *device_location = storage_map_iter->second.location; |
| + MTPDeviceMap::const_iterator device_iter = device_map_.find(*device_location); |
| + DCHECK(device_iter != device_map_.end()); |
| + const StorageObjects& storage_objects = device_iter->second; |
| + for (StorageObjects::const_iterator storage_object_iter = |
| + storage_objects.begin(); storage_object_iter != storage_objects.end(); |
| + ++storage_object_iter) { |
| + if (storage_device_id == storage_object_iter->object_persistent_id) { |
| + *storage_object_id = storage_object_iter->object_temporary_id; |
| + break; |
| + } |
| + } |
| + return !storage_object_id->empty(); |
| +} |
| + |
| void PortableDeviceWatcherWin::EnumerateAttachedDevices() { |
| DCHECK(media_task_runner_.get()); |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| @@ -560,7 +588,7 @@ void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent( |
| DCHECK(device_details); |
| if (!result) |
| return; |
| - |
| + base::AutoLock locked(lock_); |
| const StorageObjects& storage_objects = device_details->storage_objects; |
| const string16& name = device_details->name; |
| const string16& location = device_details->location; |
| @@ -594,6 +622,7 @@ void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent( |
| void PortableDeviceWatcherWin::HandleDeviceDetachEvent( |
| const string16& pnp_device_id) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + base::AutoLock locked(lock_); |
| MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); |
| if (device_iter == device_map_.end()) |
| return; |