| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 const FilePath& fs_path, | 123 const FilePath& fs_path, |
| 124 const std::string& filesystem_id) | 124 const std::string& filesystem_id) |
| 125 : name(fs_name), | 125 : name(fs_name), |
| 126 path(fs_path), | 126 path(fs_path), |
| 127 fsid(filesystem_id) { | 127 fsid(filesystem_id) { |
| 128 } | 128 } |
| 129 | 129 |
| 130 MediaFileSystemInfo::MediaFileSystemInfo() {} | 130 MediaFileSystemInfo::MediaFileSystemInfo() {} |
| 131 | 131 |
| 132 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 132 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 133 | |
| 134 ScopedMTPDeviceMapEntry::ScopedMTPDeviceMapEntry( | 133 ScopedMTPDeviceMapEntry::ScopedMTPDeviceMapEntry( |
| 135 const FilePath::StringType& device_location, | 134 const FilePath::StringType& device_location, |
| 136 const base::Closure& no_references_callback) | 135 const base::Closure& no_references_callback) |
| 137 : device_location_(device_location), | 136 : device_location_(device_location), |
| 138 delegate_(new MTPDeviceDelegateImpl(device_location)), | |
| 139 no_references_callback_(no_references_callback) { | 137 no_references_callback_(no_references_callback) { |
| 140 BrowserThread::PostTask( | 138 BrowserThread::PostTask( |
| 141 BrowserThread::IO, FROM_HERE, | 139 BrowserThread::IO, FROM_HERE, |
| 142 Bind(&MTPDeviceMapService::AddDelegate, | 140 Bind(&MTPDeviceMapService::AddDelegate, |
| 143 base::Unretained(MTPDeviceMapService::GetInstance()), | 141 base::Unretained(MTPDeviceMapService::GetInstance()), |
| 144 device_location_, make_scoped_refptr(delegate_))); | 142 device_location_, |
| 143 new MTPDeviceDelegateImpl(device_location_))); |
| 145 } | 144 } |
| 146 | 145 |
| 147 ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() { | 146 ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() { |
| 148 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
| 149 BrowserThread::IO, FROM_HERE, | 148 BrowserThread::IO, FROM_HERE, |
| 150 Bind(&MTPDeviceMapService::RemoveDelegate, | 149 Bind(&MTPDeviceMapService::RemoveDelegate, |
| 151 base::Unretained(MTPDeviceMapService::GetInstance()), | 150 base::Unretained(MTPDeviceMapService::GetInstance()), |
| 152 device_location_)); | 151 device_location_)); |
| 153 no_references_callback_.Run(); | 152 no_references_callback_.Run(); |
| 154 } | 153 } |
| 155 | |
| 156 #endif // defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 154 #endif // defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 157 | 155 |
| 158 // The main owner of this class is | 156 // The main owner of this class is |
| 159 // |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may | 157 // |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may |
| 160 // temporarily hold a reference. | 158 // temporarily hold a reference. |
| 161 class ExtensionGalleriesHost | 159 class ExtensionGalleriesHost |
| 162 : public base::RefCountedThreadSafe<ExtensionGalleriesHost>, | 160 : public base::RefCountedThreadSafe<ExtensionGalleriesHost>, |
| 163 public content::NotificationObserver { | 161 public content::NotificationObserver { |
| 164 public: | 162 public: |
| 165 // |no_references_callback| is called when the last RenderViewHost reference | 163 // |no_references_callback| is called when the last RenderViewHost reference |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 SystemMonitor* system_monitor = SystemMonitor::Get(); | 669 SystemMonitor* system_monitor = SystemMonitor::Get(); |
| 672 if (system_monitor) | 670 if (system_monitor) |
| 673 system_monitor->AddDevicesChangedObserver(this); | 671 system_monitor->AddDevicesChangedObserver(this); |
| 674 } | 672 } |
| 675 | 673 |
| 676 MediaFileSystemRegistry::~MediaFileSystemRegistry() { | 674 MediaFileSystemRegistry::~MediaFileSystemRegistry() { |
| 677 // SystemMonitor may be NULL in unit tests. | 675 // SystemMonitor may be NULL in unit tests. |
| 678 SystemMonitor* system_monitor = SystemMonitor::Get(); | 676 SystemMonitor* system_monitor = SystemMonitor::Get(); |
| 679 if (system_monitor) | 677 if (system_monitor) |
| 680 system_monitor->RemoveDevicesChangedObserver(this); | 678 system_monitor->RemoveDevicesChangedObserver(this); |
| 679 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 680 DCHECK(mtp_device_delegate_map_.empty()); |
| 681 #endif |
| 681 } | 682 } |
| 682 | 683 |
| 683 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( | 684 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( |
| 684 PrefServiceBase* prefs) { | 685 PrefServiceBase* prefs) { |
| 685 // Find the Profile that contains the source PrefService. | 686 // Find the Profile that contains the source PrefService. |
| 686 PrefChangeRegistrarMap::iterator pref_change_it = | 687 PrefChangeRegistrarMap::iterator pref_change_it = |
| 687 pref_change_registrar_map_.begin(); | 688 pref_change_registrar_map_.begin(); |
| 688 for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) { | 689 for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) { |
| 689 if (pref_change_it->first->GetPrefs() == prefs) | 690 if (pref_change_it->first->GetPrefs() == prefs) |
| 690 break; | 691 break; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 714 gallery_host_it->second->RevokeOldGalleries( | 715 gallery_host_it->second->RevokeOldGalleries( |
| 715 preferences->GalleriesForExtension(*extension)); | 716 preferences->GalleriesForExtension(*extension)); |
| 716 } | 717 } |
| 717 } | 718 } |
| 718 | 719 |
| 719 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 720 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 720 ScopedMTPDeviceMapEntry* | 721 ScopedMTPDeviceMapEntry* |
| 721 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry( | 722 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry( |
| 722 const FilePath::StringType& device_location) { | 723 const FilePath::StringType& device_location) { |
| 723 MTPDeviceDelegateMap::iterator delegate_it = | 724 MTPDeviceDelegateMap::iterator delegate_it = |
| 724 mtp_delegate_map_.find(device_location); | 725 mtp_device_delegate_map_.find(device_location); |
| 725 if (delegate_it != mtp_delegate_map_.end() && delegate_it->second.get()) | 726 if (delegate_it != mtp_device_delegate_map_.end()) |
| 726 return delegate_it->second; | 727 return delegate_it->second; |
| 727 ScopedMTPDeviceMapEntry* mtp_device_host = new ScopedMTPDeviceMapEntry( | 728 ScopedMTPDeviceMapEntry* mtp_device_host = new ScopedMTPDeviceMapEntry( |
| 728 device_location, base::Bind( | 729 device_location, base::Bind( |
| 729 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry, | 730 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry, |
| 730 base::Unretained(this), device_location)); | 731 base::Unretained(this), device_location)); |
| 731 mtp_delegate_map_[device_location] = mtp_device_host->AsWeakPtr(); | 732 mtp_device_delegate_map_[device_location] = mtp_device_host; |
| 732 return mtp_device_host; | 733 return mtp_device_host; |
| 733 } | 734 } |
| 734 | 735 |
| 735 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry( | 736 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry( |
| 736 const FilePath::StringType& device_location) { | 737 const FilePath::StringType& device_location) { |
| 737 MTPDeviceDelegateMap::iterator delegate_it = | 738 MTPDeviceDelegateMap::iterator delegate_it = |
| 738 mtp_delegate_map_.find(device_location); | 739 mtp_device_delegate_map_.find(device_location); |
| 739 DCHECK(delegate_it != mtp_delegate_map_.end()); | 740 DCHECK(delegate_it != mtp_device_delegate_map_.end()); |
| 740 mtp_delegate_map_.erase(delegate_it); | 741 mtp_device_delegate_map_.erase(delegate_it); |
| 741 } | 742 } |
| 742 #endif | 743 #endif |
| 743 | 744 |
| 744 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( | 745 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( |
| 745 Profile* profile, const std::string& extension_id) { | 746 Profile* profile, const std::string& extension_id) { |
| 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 747 | 748 |
| 748 ExtensionGalleriesHostMap::iterator extension_hosts = | 749 ExtensionGalleriesHostMap::iterator extension_hosts = |
| 749 extension_hosts_map_.find(profile); | 750 extension_hosts_map_.find(profile); |
| 750 DCHECK(extension_hosts != extension_hosts_map_.end()); | 751 DCHECK(extension_hosts != extension_hosts_map_.end()); |
| 751 ExtensionHostMap::size_type erase_count = | 752 ExtensionHostMap::size_type erase_count = |
| 752 extension_hosts->second.erase(extension_id); | 753 extension_hosts->second.erase(extension_id); |
| 753 DCHECK_EQ(1U, erase_count); | 754 DCHECK_EQ(1U, erase_count); |
| 754 if (extension_hosts->second.empty()) { | 755 if (extension_hosts->second.empty()) { |
| 755 extension_hosts_map_.erase(extension_hosts); | 756 extension_hosts_map_.erase(extension_hosts); |
| 756 | 757 |
| 757 PrefChangeRegistrarMap::iterator pref_it = | 758 PrefChangeRegistrarMap::iterator pref_it = |
| 758 pref_change_registrar_map_.find(profile); | 759 pref_change_registrar_map_.find(profile); |
| 759 DCHECK(pref_it != pref_change_registrar_map_.end()); | 760 DCHECK(pref_it != pref_change_registrar_map_.end()); |
| 760 delete pref_it->second; | 761 delete pref_it->second; |
| 761 pref_change_registrar_map_.erase(pref_it); | 762 pref_change_registrar_map_.erase(pref_it); |
| 762 } | 763 } |
| 763 } | 764 } |
| 764 | 765 |
| 765 } // namespace chrome | 766 } // namespace chrome |
| OLD | NEW |