| 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/storage_monitor/portable_device_watcher_win.h" | 9 #include "chrome/browser/storage_monitor/portable_device_watcher_win.h" |
| 10 | 10 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 548 } |
| 549 | 549 |
| 550 void PortableDeviceWatcherWin::SetNotifications( | 550 void PortableDeviceWatcherWin::SetNotifications( |
| 551 StorageMonitor::Receiver* notifications) { | 551 StorageMonitor::Receiver* notifications) { |
| 552 storage_notifications_ = notifications; | 552 storage_notifications_ = notifications; |
| 553 } | 553 } |
| 554 | 554 |
| 555 void PortableDeviceWatcherWin::EjectDevice( | 555 void PortableDeviceWatcherWin::EjectDevice( |
| 556 const std::string& device_id, | 556 const std::string& device_id, |
| 557 base::Callback<void(StorageMonitor::EjectStatus)> callback) { | 557 base::Callback<void(StorageMonitor::EjectStatus)> callback) { |
| 558 callback.Run(chrome::StorageMonitor::EJECT_FAILURE); | 558 // MTP devices on Windows don't have a detach API needed -- signal |
| 559 // the object as if the device is gone and tell the caller it is OK |
| 560 // to remove. |
| 561 string16 device_location; // The device_map_ key. |
| 562 string16 storage_object_id; |
| 563 if (!GetMTPStorageInfoFromDeviceId(device_id, |
| 564 &device_location, &storage_object_id)) { |
| 565 callback.Run(chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE); |
| 566 return; |
| 567 } |
| 568 HandleDeviceDetachEvent(device_location); |
| 569 |
| 570 callback.Run(chrome::StorageMonitor::EJECT_OK); |
| 559 } | 571 } |
| 560 | 572 |
| 561 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { | 573 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { |
| 562 DCHECK(media_task_runner_.get()); | 574 DCHECK(media_task_runner_.get()); |
| 563 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 575 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 564 Devices* devices = new Devices; | 576 Devices* devices = new Devices; |
| 565 base::PostTaskAndReplyWithResult( | 577 base::PostTaskAndReplyWithResult( |
| 566 media_task_runner_, | 578 media_task_runner_, |
| 567 FROM_HERE, | 579 FROM_HERE, |
| 568 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), | 580 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 // empty values. | 628 // empty values. |
| 617 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); | 629 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); |
| 618 if (storage_id.empty() || name.empty()) | 630 if (storage_id.empty() || name.empty()) |
| 619 return; | 631 return; |
| 620 | 632 |
| 621 // Device can have several data partitions. Therefore, add the | 633 // Device can have several data partitions. Therefore, add the |
| 622 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" | 634 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" |
| 623 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + | 635 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + |
| 624 L')'); | 636 L')'); |
| 625 StorageInfo info(storage_id, storage_name, location, | 637 StorageInfo info(storage_id, storage_name, location, |
| 626 string16(), string16(), string16(), 0); | 638 storage_name, string16(), string16(), 0); |
| 627 storage_map_[storage_id] = info; | 639 storage_map_[storage_id] = info; |
| 628 if (storage_notifications_) { | 640 if (storage_notifications_) { |
| 629 info.set_location(GetStoragePathFromStorageId(storage_id)); | 641 info.set_location(GetStoragePathFromStorageId(storage_id)); |
| 630 storage_notifications_->ProcessAttach(info); | 642 storage_notifications_->ProcessAttach(info); |
| 631 } | 643 } |
| 632 } | 644 } |
| 633 device_map_[location] = storage_objects; | 645 device_map_[location] = storage_objects; |
| 634 } | 646 } |
| 635 | 647 |
| 636 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( | 648 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 650 if (storage_notifications_) { | 662 if (storage_notifications_) { |
| 651 storage_notifications_->ProcessDetach( | 663 storage_notifications_->ProcessDetach( |
| 652 storage_map_iter->second.device_id()); | 664 storage_map_iter->second.device_id()); |
| 653 } | 665 } |
| 654 storage_map_.erase(storage_map_iter); | 666 storage_map_.erase(storage_map_iter); |
| 655 } | 667 } |
| 656 device_map_.erase(device_iter); | 668 device_map_.erase(device_iter); |
| 657 } | 669 } |
| 658 | 670 |
| 659 } // namespace chrome | 671 } // namespace chrome |
| OLD | NEW |