| 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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 const DeviceDetails* device_details, const bool result) { | 558 const DeviceDetails* device_details, const bool result) { |
| 559 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 559 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 560 DCHECK(device_details); | 560 DCHECK(device_details); |
| 561 if (!result) | 561 if (!result) |
| 562 return; | 562 return; |
| 563 | 563 |
| 564 const StorageObjects& storage_objects = device_details->storage_objects; | 564 const StorageObjects& storage_objects = device_details->storage_objects; |
| 565 const string16& name = device_details->name; | 565 const string16& name = device_details->name; |
| 566 const string16& location = device_details->location; | 566 const string16& location = device_details->location; |
| 567 DCHECK(!ContainsKey(device_map_, location)); | 567 DCHECK(!ContainsKey(device_map_, location)); |
| 568 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 568 RemovableStorageNotifications* notifications = |
| 569 DCHECK(system_monitor); | 569 RemovableStorageNotifications::GetInstance(); |
| 570 DCHECK(notifications); |
| 570 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); | 571 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); |
| 571 storage_iter != storage_objects.end(); ++storage_iter) { | 572 storage_iter != storage_objects.end(); ++storage_iter) { |
| 572 const std::string& storage_id = storage_iter->object_persistent_id; | 573 const std::string& storage_id = storage_iter->object_persistent_id; |
| 573 DCHECK(!ContainsKey(storage_map_, storage_id)); | 574 DCHECK(!ContainsKey(storage_map_, storage_id)); |
| 574 | 575 |
| 575 // Keep track of storage id and storage name to see how often we receive | 576 // Keep track of storage id and storage name to see how often we receive |
| 576 // empty values. | 577 // empty values. |
| 577 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); | 578 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); |
| 578 if (storage_id.empty() || name.empty()) | 579 if (storage_id.empty() || name.empty()) |
| 579 return; | 580 return; |
| 580 | 581 |
| 581 // Device can have several data partitions. Therefore, add the | 582 // Device can have several data partitions. Therefore, add the |
| 582 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" | 583 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" |
| 583 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + | 584 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + |
| 584 L')'); | 585 L')'); |
| 585 storage_map_[storage_id] = | 586 storage_map_[storage_id] = RemovableStorageNotifications::StorageInfo( |
| 586 base::SystemMonitor::RemovableStorageInfo(storage_id, storage_name, | 587 storage_id, storage_name, location); |
| 587 location); | 588 notifications->ProcessAttach( |
| 588 system_monitor->ProcessRemovableStorageAttached( | |
| 589 storage_id, storage_name, GetStoragePathFromStorageId(storage_id)); | 589 storage_id, storage_name, GetStoragePathFromStorageId(storage_id)); |
| 590 } | 590 } |
| 591 device_map_[location] = storage_objects; | 591 device_map_[location] = storage_objects; |
| 592 } | 592 } |
| 593 | 593 |
| 594 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( | 594 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( |
| 595 const string16& pnp_device_id) { | 595 const string16& pnp_device_id) { |
| 596 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 596 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 597 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); | 597 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); |
| 598 if (device_iter == device_map_.end()) | 598 if (device_iter == device_map_.end()) |
| 599 return; | 599 return; |
| 600 | 600 |
| 601 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | 601 RemovableStorageNotifications* notifications = |
| 602 DCHECK(system_monitor); | 602 RemovableStorageNotifications::GetInstance(); |
| 603 DCHECK(notifications); |
| 603 | 604 |
| 604 const StorageObjects& storage_objects = device_iter->second; | 605 const StorageObjects& storage_objects = device_iter->second; |
| 605 for (StorageObjects::const_iterator storage_object_iter = | 606 for (StorageObjects::const_iterator storage_object_iter = |
| 606 storage_objects.begin(); storage_object_iter != storage_objects.end(); | 607 storage_objects.begin(); storage_object_iter != storage_objects.end(); |
| 607 ++storage_object_iter) { | 608 ++storage_object_iter) { |
| 608 std::string storage_id = storage_object_iter->object_persistent_id; | 609 std::string storage_id = storage_object_iter->object_persistent_id; |
| 609 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 610 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 610 DCHECK(storage_map_iter != storage_map_.end()); | 611 DCHECK(storage_map_iter != storage_map_.end()); |
| 611 system_monitor->ProcessRemovableStorageDetached( | 612 notifications->ProcessDetach(storage_map_iter->second.device_id); |
| 612 storage_map_iter->second.device_id); | |
| 613 storage_map_.erase(storage_map_iter); | 613 storage_map_.erase(storage_map_iter); |
| 614 } | 614 } |
| 615 device_map_.erase(device_iter); | 615 device_map_.erase(device_iter); |
| 616 } | 616 } |
| 617 | 617 |
| 618 } // namespace chrome | 618 } // namespace chrome |
| OLD | NEW |