| 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 // Any tasks that communicates with the portable device may take >100ms to | 5 // Any tasks that communicates with the portable device may take >100ms to |
| 6 // complete. Those tasks should be run on an blocking thread instead of the | 6 // complete. Those tasks should be run on an blocking thread instead of the |
| 7 // UI thread. | 7 // UI thread. |
| 8 | 8 |
| 9 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" | 9 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
| 10 | 10 |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 if (!IsPortableDeviceStructure(data)) | 502 if (!IsPortableDeviceStructure(data)) |
| 503 return; | 503 return; |
| 504 | 504 |
| 505 string16 device_id = GetPnpDeviceId(data); | 505 string16 device_id = GetPnpDeviceId(data); |
| 506 if (event_type == DBT_DEVICEARRIVAL) | 506 if (event_type == DBT_DEVICEARRIVAL) |
| 507 HandleDeviceAttachEvent(device_id); | 507 HandleDeviceAttachEvent(device_id); |
| 508 else if (event_type == DBT_DEVICEREMOVECOMPLETE) | 508 else if (event_type == DBT_DEVICEREMOVECOMPLETE) |
| 509 HandleDeviceDetachEvent(device_id); | 509 HandleDeviceDetachEvent(device_id); |
| 510 } | 510 } |
| 511 | 511 |
| 512 bool PortableDeviceWatcherWin::GetMTPStorageInfoFromDeviceId( |
| 513 const std::string& storage_device_id, |
| 514 string16* device_location, |
| 515 string16* storage_object_id) { |
| 516 DCHECK(device_location); |
| 517 DCHECK(storage_object_id); |
| 518 MTPStorageMap::const_iterator storage_map_iter = |
| 519 storage_map_.find(storage_device_id); |
| 520 if (storage_map_iter == storage_map_.end()) |
| 521 return false; |
| 522 |
| 523 *device_location = storage_map_iter->second.location; |
| 524 MTPDeviceMap::const_iterator device_iter = device_map_.find(*device_location); |
| 525 DCHECK(device_iter != device_map_.end()); |
| 526 const StorageObjects& storage_objects = device_iter->second; |
| 527 for (StorageObjects::const_iterator storage_object_iter = |
| 528 storage_objects.begin(); storage_object_iter != storage_objects.end(); |
| 529 ++storage_object_iter) { |
| 530 if (storage_device_id == storage_object_iter->object_persistent_id) { |
| 531 *storage_object_id = storage_object_iter->object_temporary_id; |
| 532 break; |
| 533 } |
| 534 } |
| 535 return !storage_object_id->empty(); |
| 536 } |
| 537 |
| 512 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { | 538 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { |
| 513 DCHECK(media_task_runner_.get()); | 539 DCHECK(media_task_runner_.get()); |
| 514 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 540 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 515 Devices* devices = new Devices; | 541 Devices* devices = new Devices; |
| 516 base::PostTaskAndReplyWithResult( | 542 base::PostTaskAndReplyWithResult( |
| 517 media_task_runner_, | 543 media_task_runner_, |
| 518 FROM_HERE, | 544 FROM_HERE, |
| 519 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), | 545 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), |
| 520 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, | 546 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, |
| 521 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); | 547 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 628 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 603 DCHECK(storage_map_iter != storage_map_.end()); | 629 DCHECK(storage_map_iter != storage_map_.end()); |
| 604 system_monitor->ProcessRemovableStorageDetached( | 630 system_monitor->ProcessRemovableStorageDetached( |
| 605 storage_map_iter->second.device_id); | 631 storage_map_iter->second.device_id); |
| 606 storage_map_.erase(storage_map_iter); | 632 storage_map_.erase(storage_map_iter); |
| 607 } | 633 } |
| 608 device_map_.erase(device_iter); | 634 device_map_.erase(device_iter); |
| 609 } | 635 } |
| 610 | 636 |
| 611 } // namespace chrome | 637 } // namespace chrome |
| OLD | NEW |