Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/system_monitor/portable_device_watcher_win.cc

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

Powered by Google App Engine
This is Rietveld 408576698