| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 const DeviceDetails* device_details, const bool result) { | 587 const DeviceDetails* device_details, const bool result) { |
| 588 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 588 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 589 DCHECK(device_details); | 589 DCHECK(device_details); |
| 590 if (!result) | 590 if (!result) |
| 591 return; | 591 return; |
| 592 | 592 |
| 593 const StorageObjects& storage_objects = device_details->storage_objects; | 593 const StorageObjects& storage_objects = device_details->storage_objects; |
| 594 const string16& name = device_details->name; | 594 const string16& name = device_details->name; |
| 595 const string16& location = device_details->location; | 595 const string16& location = device_details->location; |
| 596 DCHECK(!ContainsKey(device_map_, location)); | 596 DCHECK(!ContainsKey(device_map_, location)); |
| 597 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 597 RemovableStorageNotifications* notifications = |
| 598 DCHECK(system_monitor); | 598 RemovableStorageNotifications::GetInstance(); |
| 599 DCHECK(notifications); |
| 599 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); | 600 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); |
| 600 storage_iter != storage_objects.end(); ++storage_iter) { | 601 storage_iter != storage_objects.end(); ++storage_iter) { |
| 601 const std::string& storage_id = storage_iter->object_persistent_id; | 602 const std::string& storage_id = storage_iter->object_persistent_id; |
| 602 DCHECK(!ContainsKey(storage_map_, storage_id)); | 603 DCHECK(!ContainsKey(storage_map_, storage_id)); |
| 603 | 604 |
| 604 // Keep track of storage id and storage name to see how often we receive | 605 // Keep track of storage id and storage name to see how often we receive |
| 605 // empty values. | 606 // empty values. |
| 606 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); | 607 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); |
| 607 if (storage_id.empty() || name.empty()) | 608 if (storage_id.empty() || name.empty()) |
| 608 return; | 609 return; |
| 609 | 610 |
| 610 // Device can have several data partitions. Therefore, add the | 611 // Device can have several data partitions. Therefore, add the |
| 611 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" | 612 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" |
| 612 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + | 613 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + |
| 613 L')'); | 614 L')'); |
| 614 storage_map_[storage_id] = | 615 storage_map_[storage_id] = RemovableStorageNotifications::StorageInfo( |
| 615 base::SystemMonitor::RemovableStorageInfo(storage_id, storage_name, | 616 storage_id, storage_name, location); |
| 616 location); | 617 notifications->ProcessAttach( |
| 617 system_monitor->ProcessRemovableStorageAttached( | |
| 618 storage_id, storage_name, GetStoragePathFromStorageId(storage_id)); | 618 storage_id, storage_name, GetStoragePathFromStorageId(storage_id)); |
| 619 } | 619 } |
| 620 device_map_[location] = storage_objects; | 620 device_map_[location] = storage_objects; |
| 621 } | 621 } |
| 622 | 622 |
| 623 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( | 623 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( |
| 624 const string16& pnp_device_id) { | 624 const string16& pnp_device_id) { |
| 625 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 625 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 626 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); | 626 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); |
| 627 if (device_iter == device_map_.end()) | 627 if (device_iter == device_map_.end()) |
| 628 return; | 628 return; |
| 629 | 629 |
| 630 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 630 RemovableStorageNotifications* notifications = |
| 631 DCHECK(system_monitor); | 631 RemovableStorageNotifications::GetInstance(); |
| 632 DCHECK(notifications); |
| 632 | 633 |
| 633 const StorageObjects& storage_objects = device_iter->second; | 634 const StorageObjects& storage_objects = device_iter->second; |
| 634 for (StorageObjects::const_iterator storage_object_iter = | 635 for (StorageObjects::const_iterator storage_object_iter = |
| 635 storage_objects.begin(); storage_object_iter != storage_objects.end(); | 636 storage_objects.begin(); storage_object_iter != storage_objects.end(); |
| 636 ++storage_object_iter) { | 637 ++storage_object_iter) { |
| 637 std::string storage_id = storage_object_iter->object_persistent_id; | 638 std::string storage_id = storage_object_iter->object_persistent_id; |
| 638 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 639 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 639 DCHECK(storage_map_iter != storage_map_.end()); | 640 DCHECK(storage_map_iter != storage_map_.end()); |
| 640 system_monitor->ProcessRemovableStorageDetached( | 641 notifications->ProcessDetach(storage_map_iter->second.device_id); |
| 641 storage_map_iter->second.device_id); | |
| 642 storage_map_.erase(storage_map_iter); | 642 storage_map_.erase(storage_map_iter); |
| 643 } | 643 } |
| 644 device_map_.erase(device_iter); | 644 device_map_.erase(device_iter); |
| 645 } | 645 } |
| 646 | 646 |
| 647 } // namespace chrome | 647 } // namespace chrome |
| OLD | NEW |