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

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

Issue 11297002: [Media Gallery] Added code to support mtp device media file system on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed DCHECK, added lock in PortableDeviceWatcherWin and fixed tests. Created 8 years 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 | Annotate | Revision Log
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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 if (!IsPortableDeviceStructure(data)) 509 if (!IsPortableDeviceStructure(data))
510 return; 510 return;
511 511
512 string16 device_id = GetPnpDeviceId(data); 512 string16 device_id = GetPnpDeviceId(data);
513 if (event_type == DBT_DEVICEARRIVAL) 513 if (event_type == DBT_DEVICEARRIVAL)
514 HandleDeviceAttachEvent(device_id); 514 HandleDeviceAttachEvent(device_id);
515 else if (event_type == DBT_DEVICEREMOVECOMPLETE) 515 else if (event_type == DBT_DEVICEREMOVECOMPLETE)
516 HandleDeviceDetachEvent(device_id); 516 HandleDeviceDetachEvent(device_id);
517 } 517 }
518 518
519 bool PortableDeviceWatcherWin::GetMTPStorageInfoFromDeviceId(
520 const std::string& storage_device_id,
521 string16* device_location,
522 string16* storage_object_id) {
523 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
Peter Kasting 2012/12/21 18:13:30 This is scary. What if the UI thread deletes the
kmadhusu 2013/01/02 19:48:31 There is a chance that the UI thread may delete th
Peter Kasting 2013/01/04 21:13:38 It might be nice to have DCHECKs that you're on th
kmadhusu 2013/01/04 22:14:32 Done.
524 DCHECK(device_location);
525 DCHECK(storage_object_id);
526 base::AutoLock locked(lock_);
527 MTPStorageMap::const_iterator storage_map_iter =
528 storage_map_.find(storage_device_id);
529 if (storage_map_iter == storage_map_.end())
530 return false;
531
532 *device_location = storage_map_iter->second.location;
533 MTPDeviceMap::const_iterator device_iter = device_map_.find(*device_location);
534 DCHECK(device_iter != device_map_.end());
535 const StorageObjects& storage_objects = device_iter->second;
536 for (StorageObjects::const_iterator storage_object_iter =
537 storage_objects.begin(); storage_object_iter != storage_objects.end();
538 ++storage_object_iter) {
539 if (storage_device_id == storage_object_iter->object_persistent_id) {
540 *storage_object_id = storage_object_iter->object_temporary_id;
541 break;
542 }
543 }
544 return !storage_object_id->empty();
545 }
546
519 void PortableDeviceWatcherWin::EnumerateAttachedDevices() { 547 void PortableDeviceWatcherWin::EnumerateAttachedDevices() {
520 DCHECK(media_task_runner_.get()); 548 DCHECK(media_task_runner_.get());
521 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 549 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
522 Devices* devices = new Devices; 550 Devices* devices = new Devices;
523 base::PostTaskAndReplyWithResult( 551 base::PostTaskAndReplyWithResult(
524 media_task_runner_, 552 media_task_runner_,
525 FROM_HERE, 553 FROM_HERE,
526 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices), 554 base::Bind(&EnumerateAttachedDevicesOnBlockingThread, devices),
527 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices, 555 base::Bind(&PortableDeviceWatcherWin::OnDidEnumerateAttachedDevices,
528 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices))); 556 weak_ptr_factory_.GetWeakPtr(), base::Owned(devices)));
(...skipping 24 matching lines...) Expand all
553 base::Bind(&PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent, 581 base::Bind(&PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent,
554 weak_ptr_factory_.GetWeakPtr(), base::Owned(device_details))); 582 weak_ptr_factory_.GetWeakPtr(), base::Owned(device_details)));
555 } 583 }
556 584
557 void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent( 585 void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent(
558 const DeviceDetails* device_details, const bool result) { 586 const DeviceDetails* device_details, const bool result) {
559 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 587 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
560 DCHECK(device_details); 588 DCHECK(device_details);
561 if (!result) 589 if (!result)
562 return; 590 return;
563 591 base::AutoLock locked(lock_);
564 const StorageObjects& storage_objects = device_details->storage_objects; 592 const StorageObjects& storage_objects = device_details->storage_objects;
565 const string16& name = device_details->name; 593 const string16& name = device_details->name;
566 const string16& location = device_details->location; 594 const string16& location = device_details->location;
567 DCHECK(!ContainsKey(device_map_, location)); 595 DCHECK(!ContainsKey(device_map_, location));
568 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); 596 base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
569 DCHECK(system_monitor); 597 DCHECK(system_monitor);
570 for (StorageObjects::const_iterator storage_iter = storage_objects.begin(); 598 for (StorageObjects::const_iterator storage_iter = storage_objects.begin();
571 storage_iter != storage_objects.end(); ++storage_iter) { 599 storage_iter != storage_objects.end(); ++storage_iter) {
572 const std::string& storage_id = storage_iter->object_persistent_id; 600 const std::string& storage_id = storage_iter->object_persistent_id;
573 DCHECK(!ContainsKey(storage_map_, storage_id)); 601 DCHECK(!ContainsKey(storage_map_, storage_id));
(...skipping 13 matching lines...) Expand all
587 location); 615 location);
588 system_monitor->ProcessRemovableStorageAttached( 616 system_monitor->ProcessRemovableStorageAttached(
589 storage_id, storage_name, GetStoragePathFromStorageId(storage_id)); 617 storage_id, storage_name, GetStoragePathFromStorageId(storage_id));
590 } 618 }
591 device_map_[location] = storage_objects; 619 device_map_[location] = storage_objects;
592 } 620 }
593 621
594 void PortableDeviceWatcherWin::HandleDeviceDetachEvent( 622 void PortableDeviceWatcherWin::HandleDeviceDetachEvent(
595 const string16& pnp_device_id) { 623 const string16& pnp_device_id) {
596 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 624 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
625 base::AutoLock locked(lock_);
597 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id); 626 MTPDeviceMap::iterator device_iter = device_map_.find(pnp_device_id);
598 if (device_iter == device_map_.end()) 627 if (device_iter == device_map_.end())
599 return; 628 return;
600 629
601 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); 630 base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
602 DCHECK(system_monitor); 631 DCHECK(system_monitor);
603 632
604 const StorageObjects& storage_objects = device_iter->second; 633 const StorageObjects& storage_objects = device_iter->second;
605 for (StorageObjects::const_iterator storage_object_iter = 634 for (StorageObjects::const_iterator storage_object_iter =
606 storage_objects.begin(); storage_object_iter != storage_objects.end(); 635 storage_objects.begin(); storage_object_iter != storage_objects.end();
607 ++storage_object_iter) { 636 ++storage_object_iter) {
608 std::string storage_id = storage_object_iter->object_persistent_id; 637 std::string storage_id = storage_object_iter->object_persistent_id;
609 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); 638 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id);
610 DCHECK(storage_map_iter != storage_map_.end()); 639 DCHECK(storage_map_iter != storage_map_.end());
611 system_monitor->ProcessRemovableStorageDetached( 640 system_monitor->ProcessRemovableStorageDetached(
612 storage_map_iter->second.device_id); 641 storage_map_iter->second.device_id);
613 storage_map_.erase(storage_map_iter); 642 storage_map_.erase(storage_map_iter);
614 } 643 }
615 device_map_.erase(device_iter); 644 device_map_.erase(device_iter);
616 } 645 }
617 646
618 } // namespace chrome 647 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698