Chromium Code Reviews| 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 // MediaFileSystemRegistry implementation. | 5 // MediaFileSystemRegistry implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 7 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 void MediaFileSystemRegistry::GetMediaFileSystemsForExtension( | 475 void MediaFileSystemRegistry::GetMediaFileSystemsForExtension( |
| 476 const content::RenderViewHost* rvh, | 476 const content::RenderViewHost* rvh, |
| 477 const extensions::Extension* extension, | 477 const extensions::Extension* extension, |
| 478 const MediaFileSystemsCallback& callback) { | 478 const MediaFileSystemsCallback& callback) { |
| 479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 480 | 480 |
| 481 Profile* profile = | 481 Profile* profile = |
| 482 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); | 482 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
| 483 MediaGalleriesPreferences* preferences = | 483 MediaGalleriesPreferences* preferences = |
| 484 MediaGalleriesPreferencesFactory::GetForProfile(profile); | 484 MediaGalleriesPreferencesFactory::GetForProfile(profile); |
| 485 | |
| 486 if (!ContainsKey(extension_hosts_map_, profile)) | |
| 487 AddAttachedMediaDeviceGalleries(preferences); | |
|
vandebo (ex-Chrome)
2012/10/27 19:57:57
Maybe we should still call the new function here?
kmadhusu
2012/10/28 01:13:43
I don't think this call is required here. This fu
| |
| 488 MediaGalleryPrefIdSet galleries = | 485 MediaGalleryPrefIdSet galleries = |
| 489 preferences->GalleriesForExtension(*extension); | 486 preferences->GalleriesForExtension(*extension); |
| 490 | 487 |
| 491 // If the extension has no galleries and it didn't have any last time, just | 488 // If the extension has no galleries and it didn't have any last time, just |
| 492 // return the empty list. The second check is needed because of | 489 // return the empty list. The second check is needed because of |
| 493 // http://crbug.com/145855. | 490 // http://crbug.com/145855. |
| 494 bool has_extension_host = ContainsKey(extension_hosts_map_, profile) && | 491 bool has_extension_host = ContainsKey(extension_hosts_map_, profile) && |
| 495 ContainsKey(extension_hosts_map_[profile], extension->id()); | 492 ContainsKey(extension_hosts_map_[profile], extension->id()); |
| 496 if (galleries.empty() && !has_extension_host) { | 493 if (galleries.empty() && !has_extension_host) { |
| 497 callback.Run(std::vector<MediaFileSystemInfo>()); | 494 callback.Run(std::vector<MediaFileSystemInfo>()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 for (std::set<MediaGalleryPrefId>::const_iterator pref_id_it = | 568 for (std::set<MediaGalleryPrefId>::const_iterator pref_id_it = |
| 572 invalid_galleries_info[i].pref_ids.begin(); | 569 invalid_galleries_info[i].pref_ids.begin(); |
| 573 pref_id_it != invalid_galleries_info[i].pref_ids.end(); | 570 pref_id_it != invalid_galleries_info[i].pref_ids.end(); |
| 574 ++pref_id_it) { | 571 ++pref_id_it) { |
| 575 (*extension_host_it)->RevokeGalleryByPrefId(*pref_id_it); | 572 (*extension_host_it)->RevokeGalleryByPrefId(*pref_id_it); |
| 576 } | 573 } |
| 577 } | 574 } |
| 578 } | 575 } |
| 579 } | 576 } |
| 580 | 577 |
| 578 void MediaFileSystemRegistry::AddAttachedMediaDeviceGalleries( | |
| 579 const content::RenderViewHost* rvh) { | |
| 580 Profile* profile = | |
| 581 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); | |
| 582 if (ContainsKey(extension_hosts_map_, profile)) | |
| 583 return; // Devices already enumerated. | |
| 584 | |
| 585 // SystemMonitor may be NULL in unit tests. | |
| 586 SystemMonitor* system_monitor = SystemMonitor::Get(); | |
| 587 if (!system_monitor) | |
| 588 return; | |
| 589 | |
| 590 std::vector<SystemMonitor::RemovableStorageInfo> existing_devices = | |
| 591 system_monitor->GetAttachedRemovableStorage(); | |
| 592 MediaGalleriesPreferences* preferences = | |
| 593 MediaGalleriesPreferencesFactory::GetForProfile(profile); | |
| 594 DCHECK(preferences); | |
| 595 for (size_t i = 0; i < existing_devices.size(); i++) { | |
| 596 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) | |
| 597 continue; | |
| 598 preferences->AddGallery(existing_devices[i].device_id, | |
| 599 existing_devices[i].name, FilePath(), | |
| 600 false /*not user added*/); | |
| 601 } | |
| 602 } | |
| 603 | |
| 581 /****************** | 604 /****************** |
| 582 * Private methods | 605 * Private methods |
| 583 ******************/ | 606 ******************/ |
| 584 | 607 |
| 585 class MediaFileSystemRegistry::MediaFileSystemContextImpl | 608 class MediaFileSystemRegistry::MediaFileSystemContextImpl |
| 586 : public MediaFileSystemContext { | 609 : public MediaFileSystemContext { |
| 587 public: | 610 public: |
| 588 explicit MediaFileSystemContextImpl(MediaFileSystemRegistry* registry) | 611 explicit MediaFileSystemContextImpl(MediaFileSystemRegistry* registry) |
| 589 : registry_(registry) { | 612 : registry_(registry) { |
| 590 DCHECK(registry_); // Suppresses unused warning on Android. | 613 DCHECK(registry_); // Suppresses unused warning on Android. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 | 694 |
| 672 void MediaFileSystemRegistry::RemoveScopedMtpDeviceMapEntry( | 695 void MediaFileSystemRegistry::RemoveScopedMtpDeviceMapEntry( |
| 673 const FilePath::StringType& device_location) { | 696 const FilePath::StringType& device_location) { |
| 674 MTPDeviceDelegateMap::iterator delegate_it = | 697 MTPDeviceDelegateMap::iterator delegate_it = |
| 675 mtp_delegate_map_.find(device_location); | 698 mtp_delegate_map_.find(device_location); |
| 676 DCHECK(delegate_it != mtp_delegate_map_.end()); | 699 DCHECK(delegate_it != mtp_delegate_map_.end()); |
| 677 mtp_delegate_map_.erase(delegate_it); | 700 mtp_delegate_map_.erase(delegate_it); |
| 678 } | 701 } |
| 679 #endif | 702 #endif |
| 680 | 703 |
| 681 void MediaFileSystemRegistry::AddAttachedMediaDeviceGalleries( | |
| 682 MediaGalleriesPreferences* preferences) { | |
| 683 // SystemMonitor may be NULL in unit tests. | |
| 684 SystemMonitor* system_monitor = SystemMonitor::Get(); | |
| 685 if (!system_monitor) | |
| 686 return; | |
| 687 | |
| 688 std::vector<SystemMonitor::RemovableStorageInfo> existing_devices = | |
| 689 system_monitor->GetAttachedRemovableStorage(); | |
| 690 for (size_t i = 0; i < existing_devices.size(); i++) { | |
| 691 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) | |
| 692 continue; | |
| 693 preferences->AddGallery(existing_devices[i].device_id, | |
| 694 existing_devices[i].name, FilePath(), | |
| 695 false /*not user added*/); | |
| 696 } | |
| 697 } | |
| 698 | |
| 699 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( | 704 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( |
| 700 Profile* profile, const std::string& extension_id) { | 705 Profile* profile, const std::string& extension_id) { |
| 701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 702 | 707 |
| 703 ExtensionGalleriesHostMap::iterator extension_hosts = | 708 ExtensionGalleriesHostMap::iterator extension_hosts = |
| 704 extension_hosts_map_.find(profile); | 709 extension_hosts_map_.find(profile); |
| 705 DCHECK(extension_hosts != extension_hosts_map_.end()); | 710 DCHECK(extension_hosts != extension_hosts_map_.end()); |
| 706 ExtensionHostMap::size_type erase_count = | 711 ExtensionHostMap::size_type erase_count = |
| 707 extension_hosts->second.erase(extension_id); | 712 extension_hosts->second.erase(extension_id); |
| 708 DCHECK_EQ(1U, erase_count); | 713 DCHECK_EQ(1U, erase_count); |
| 709 if (extension_hosts->second.empty()) | 714 if (extension_hosts->second.empty()) |
| 710 extension_hosts_map_.erase(extension_hosts); | 715 extension_hosts_map_.erase(extension_hosts); |
| 711 } | 716 } |
| 712 | 717 |
| 713 } // namespace chrome | 718 } // namespace chrome |
| OLD | NEW |