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 // 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 if (!IsPortableDeviceStructure(data)) | 509 if (!IsPortableDeviceStructure(data)) |
| 510 return; | 510 return; |
| 511 | 511 |
| 512 string16 device_id = GetPnpDeviceId(data); | 512 string16 device_id = GetPnpDeviceId(data); |
| 513 if (event_type == DBT_DEVICEARRIVAL) | 513 if (event_type == DBT_DEVICEARRIVAL) |
| 514 HandleDeviceAttachEvent(device_id); | 514 HandleDeviceAttachEvent(device_id); |
| 515 else if (event_type == DBT_DEVICEREMOVECOMPLETE) | 515 else if (event_type == DBT_DEVICEREMOVECOMPLETE) |
| 516 HandleDeviceDetachEvent(device_id); | 516 HandleDeviceDetachEvent(device_id); |
| 517 } | 517 } |
| 518 | 518 |
| 519 bool PortableDeviceWatcherWin::GetMTPStorageInfoFromDeviceId( | |
| 520 const std::string& storage_device_id, | |
| 521 string16* device_location, | |
| 522 string16* storage_object_id) { | |
| 523 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 524 DCHECK(device_location); | |
| 525 DCHECK(storage_object_id); | |
| 526 MTPStorageMap::const_iterator storage_map_iter = | |
| 527 storage_map_.find(storage_device_id); | |
| 528 if (storage_map_iter == storage_map_.end()) | |
| 529 return false; | |
| 530 | |
| 531 *device_location = storage_map_iter->second.location; | |
|
Lei Zhang
2013/01/14 23:25:30
If you delay assigning to |device_location| until
kmadhusu
2013/01/15 19:08:17
Done.
| |
| 532 MTPDeviceMap::const_iterator device_iter = device_map_.find(*device_location); | |
| 533 if (device_iter == device_map_.end()) | |
| 534 return false; | |
| 535 const StorageObjects& storage_objects = device_iter->second; | |
| 536 for (StorageObjects::const_iterator storage_object_iter = | |
| 537 storage_objects.begin(); storage_object_iter != storage_objects.end(); | |
| 538 ++storage_object_iter) { | |
| 539 if (storage_device_id == storage_object_iter->object_persistent_id) { | |
| 540 *storage_object_id = storage_object_iter->object_temporary_id; | |
| 541 break; | |
|
Lei Zhang
2013/01/14 20:49:02
You can just return true here and return false at
kmadhusu
2013/01/15 19:08:17
Done.
| |
| 542 } | |
| 543 } | |
| 544 return !storage_object_id->empty(); | |
| 545 } | |
| 546 | |
| 519 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { | 547 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { |
| 520 DCHECK(media_task_runner_.get()); | 548 DCHECK(media_task_runner_.get()); |
| 521 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 549 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 522 Devices* devices = new Devices; | 550 Devices* devices = new Devices; |
| 523 base::PostTaskAndReplyWithResult( | 551 base::PostTaskAndReplyWithResult( |
| 524 media_task_runner_, | 552 media_task_runner_, |
| 525 FROM_HERE, | 553 FROM_HERE, |
| 526 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), | 554 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), |
| 527 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, | 555 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, |
| 528 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); | 556 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 637 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 610 DCHECK(storage_map_iter != storage_map_.end()); | 638 DCHECK(storage_map_iter != storage_map_.end()); |
| 611 system_monitor->ProcessRemovableStorageDetached( | 639 system_monitor->ProcessRemovableStorageDetached( |
| 612 storage_map_iter->second.device_id); | 640 storage_map_iter->second.device_id); |
| 613 storage_map_.erase(storage_map_iter); | 641 storage_map_.erase(storage_map_iter); |
| 614 } | 642 } |
| 615 device_map_.erase(device_iter); | 643 device_map_.erase(device_iter); |
| 616 } | 644 } |
| 617 | 645 |
| 618 } // namespace chrome | 646 } // namespace chrome |
| OLD | NEW |