| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 471 |
| 472 PortableDeviceWatcherWin::DeviceStorageObject::DeviceStorageObject( | 472 PortableDeviceWatcherWin::DeviceStorageObject::DeviceStorageObject( |
| 473 const string16& temporary_id, | 473 const string16& temporary_id, |
| 474 const std::string& persistent_id) | 474 const std::string& persistent_id) |
| 475 : object_temporary_id(temporary_id), | 475 : object_temporary_id(temporary_id), |
| 476 object_persistent_id(persistent_id) { | 476 object_persistent_id(persistent_id) { |
| 477 } | 477 } |
| 478 | 478 |
| 479 PortableDeviceWatcherWin::PortableDeviceWatcherWin() | 479 PortableDeviceWatcherWin::PortableDeviceWatcherWin() |
| 480 : notifications_(NULL), | 480 : notifications_(NULL), |
| 481 storage_notifications_(NULL), |
| 481 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 482 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 482 } | 483 } |
| 483 | 484 |
| 484 PortableDeviceWatcherWin::~PortableDeviceWatcherWin() { | 485 PortableDeviceWatcherWin::~PortableDeviceWatcherWin() { |
| 485 UnregisterDeviceNotification(notifications_); | 486 UnregisterDeviceNotification(notifications_); |
| 486 } | 487 } |
| 487 | 488 |
| 488 void PortableDeviceWatcherWin::Init(HWND hwnd) { | 489 void PortableDeviceWatcherWin::Init(HWND hwnd) { |
| 489 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 490 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 490 notifications_ = RegisterPortableDeviceNotification(hwnd); | 491 notifications_ = RegisterPortableDeviceNotification(hwnd); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 539 |
| 539 // static | 540 // static |
| 540 string16 PortableDeviceWatcherWin::GetStoragePathFromStorageId( | 541 string16 PortableDeviceWatcherWin::GetStoragePathFromStorageId( |
| 541 const std::string& storage_unique_id) { | 542 const std::string& storage_unique_id) { |
| 542 // Construct a dummy device path using the storage name. This is only used | 543 // Construct a dummy device path using the storage name. This is only used |
| 543 // for registering the device media file system. | 544 // for registering the device media file system. |
| 544 DCHECK(!storage_unique_id.empty()); | 545 DCHECK(!storage_unique_id.empty()); |
| 545 return UTF8ToUTF16("\\\\" + storage_unique_id); | 546 return UTF8ToUTF16("\\\\" + storage_unique_id); |
| 546 } | 547 } |
| 547 | 548 |
| 549 void PortableDeviceWatcherWin::SetNotifications( |
| 550 RemovableStorageNotifications::Receiver* notifications) { |
| 551 storage_notifications_ = notifications; |
| 552 } |
| 553 |
| 548 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { | 554 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { |
| 549 DCHECK(media_task_runner_.get()); | 555 DCHECK(media_task_runner_.get()); |
| 550 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 556 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 551 Devices* devices = new Devices; | 557 Devices* devices = new Devices; |
| 552 base::PostTaskAndReplyWithResult( | 558 base::PostTaskAndReplyWithResult( |
| 553 media_task_runner_, | 559 media_task_runner_, |
| 554 FROM_HERE, | 560 FROM_HERE, |
| 555 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), | 561 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), |
| 556 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, | 562 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, |
| 557 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); | 563 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 587 const DeviceDetails* device_details, const bool result) { | 593 const DeviceDetails* device_details, const bool result) { |
| 588 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 594 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 589 DCHECK(device_details); | 595 DCHECK(device_details); |
| 590 if (!result) | 596 if (!result) |
| 591 return; | 597 return; |
| 592 | 598 |
| 593 const StorageObjects& storage_objects = device_details->storage_objects; | 599 const StorageObjects& storage_objects = device_details->storage_objects; |
| 594 const string16& name = device_details->name; | 600 const string16& name = device_details->name; |
| 595 const string16& location = device_details->location; | 601 const string16& location = device_details->location; |
| 596 DCHECK(!ContainsKey(device_map_, location)); | 602 DCHECK(!ContainsKey(device_map_, location)); |
| 597 RemovableStorageNotifications* notifications = | |
| 598 RemovableStorageNotifications::GetInstance(); | |
| 599 DCHECK(notifications); | |
| 600 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); | 603 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); |
| 601 storage_iter != storage_objects.end(); ++storage_iter) { | 604 storage_iter != storage_objects.end(); ++storage_iter) { |
| 602 const std::string& storage_id = storage_iter->object_persistent_id; | 605 const std::string& storage_id = storage_iter->object_persistent_id; |
| 603 DCHECK(!ContainsKey(storage_map_, storage_id)); | 606 DCHECK(!ContainsKey(storage_map_, storage_id)); |
| 604 | 607 |
| 605 // Keep track of storage id and storage name to see how often we receive | 608 // Keep track of storage id and storage name to see how often we receive |
| 606 // empty values. | 609 // empty values. |
| 607 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); | 610 MediaStorageUtil::RecordDeviceInfoHistogram(false, storage_id, name); |
| 608 if (storage_id.empty() || name.empty()) | 611 if (storage_id.empty() || name.empty()) |
| 609 return; | 612 return; |
| 610 | 613 |
| 611 // Device can have several data partitions. Therefore, add the | 614 // Device can have several data partitions. Therefore, add the |
| 612 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" | 615 // partition identifier to the storage name. E.g.: "Nexus 7 (s10001)" |
| 613 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + | 616 string16 storage_name(name + L" (" + storage_iter->object_temporary_id + |
| 614 L')'); | 617 L')'); |
| 615 storage_map_[storage_id] = RemovableStorageNotifications::StorageInfo( | 618 storage_map_[storage_id] = RemovableStorageNotifications::StorageInfo( |
| 616 storage_id, storage_name, location); | 619 storage_id, storage_name, location); |
| 617 notifications->ProcessAttach( | 620 if (storage_notifications_) { |
| 618 storage_id, storage_name, GetStoragePathFromStorageId(storage_id)); | 621 storage_notifications_->ProcessAttach( |
| 622 storage_id, storage_name, |
| 623 GetStoragePathFromStorageId(storage_id)); |
| 624 } |
| 619 } | 625 } |
| 620 device_map_[location] = storage_objects; | 626 device_map_[location] = storage_objects; |
| 621 } | 627 } |
| 622 | 628 |
| 623 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( | 629 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( |
| 624 const string16& pnp_device_id) { | 630 const string16& pnp_device_id) { |
| 625 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 631 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 626 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); | 632 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); |
| 627 if (device_iter == device_map_.end()) | 633 if (device_iter == device_map_.end()) |
| 628 return; | 634 return; |
| 629 | 635 |
| 630 RemovableStorageNotifications* notifications = | |
| 631 RemovableStorageNotifications::GetInstance(); | |
| 632 DCHECK(notifications); | |
| 633 | |
| 634 const StorageObjects& storage_objects = device_iter->second; | 636 const StorageObjects& storage_objects = device_iter->second; |
| 635 for (StorageObjects::const_iterator storage_object_iter = | 637 for (StorageObjects::const_iterator storage_object_iter = |
| 636 storage_objects.begin(); storage_object_iter != storage_objects.end(); | 638 storage_objects.begin(); storage_object_iter != storage_objects.end(); |
| 637 ++storage_object_iter) { | 639 ++storage_object_iter) { |
| 638 std::string storage_id = storage_object_iter->object_persistent_id; | 640 std::string storage_id = storage_object_iter->object_persistent_id; |
| 639 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 641 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 640 DCHECK(storage_map_iter != storage_map_.end()); | 642 DCHECK(storage_map_iter != storage_map_.end()); |
| 641 notifications->ProcessDetach(storage_map_iter->second.device_id); | 643 if (storage_notifications_) |
| 644 storage_notifications_->ProcessDetach(storage_map_iter->second.device_id); |
| 642 storage_map_.erase(storage_map_iter); | 645 storage_map_.erase(storage_map_iter); |
| 643 } | 646 } |
| 644 device_map_.erase(device_iter); | 647 device_map_.erase(device_iter); |
| 645 } | 648 } |
| 646 | 649 |
| 647 } // namespace chrome | 650 } // namespace chrome |
| OLD | NEW |