| 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 24 matching lines...) Expand all Loading... |
| 546 base::Bind(&PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent, | 572 base::Bind(&PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent, |
| 547 weak_ptr_factory_.GetWeakPtr(), base::Owned(device_details))); | 573 weak_ptr_factory_.GetWeakPtr(), base::Owned(device_details))); |
| 548 } | 574 } |
| 549 | 575 |
| 550 void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent( | 576 void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent( |
| 551 const DeviceDetails* device_details, const bool result) { | 577 const DeviceDetails* device_details, const bool result) { |
| 552 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 578 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 553 DCHECK(device_details); | 579 DCHECK(device_details); |
| 554 if (!result) | 580 if (!result) |
| 555 return; | 581 return; |
| 556 | |
| 557 const StorageObjects& storage_objects = device_details->storage_objects; | 582 const StorageObjects& storage_objects = device_details->storage_objects; |
| 558 const string16& name = device_details->name; | 583 const string16& name = device_details->name; |
| 559 const string16& location = device_details->location; | 584 const string16& location = device_details->location; |
| 560 DCHECK(!ContainsKey(device_map_, location)); | 585 DCHECK(!ContainsKey(device_map_, location)); |
| 561 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 586 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
| 562 DCHECK(system_monitor); | 587 DCHECK(system_monitor); |
| 563 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); | 588 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); |
| 564 storage_iter != storage_objects.end(); ++storage_iter) { | 589 storage_iter != storage_objects.end(); ++storage_iter) { |
| 565 const std::string& storage_id = storage_iter->object_persistent_id; | 590 const std::string& storage_id = storage_iter->object_persistent_id; |
| 566 DCHECK(!ContainsKey(storage_map_, storage_id)); | 591 DCHECK(!ContainsKey(storage_map_, storage_id)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 627 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 603 DCHECK(storage_map_iter != storage_map_.end()); | 628 DCHECK(storage_map_iter != storage_map_.end()); |
| 604 system_monitor->ProcessRemovableStorageDetached( | 629 system_monitor->ProcessRemovableStorageDetached( |
| 605 storage_map_iter->second.device_id); | 630 storage_map_iter->second.device_id); |
| 606 storage_map_.erase(storage_map_iter); | 631 storage_map_.erase(storage_map_iter); |
| 607 } | 632 } |
| 608 device_map_.erase(device_iter); | 633 device_map_.erase(device_iter); |
| 609 } | 634 } |
| 610 | 635 |
| 611 } // namespace chrome | 636 } // namespace chrome |
| OLD | NEW |