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 DCHECK(mtp_device_delegate_map_.empty()); | |
681 } | 680 } |
682 | 681 |
683 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( | 682 void MediaFileSystemRegistry::OnMediaGalleriesRememberedGalleriesChanged( |
684 PrefServiceBase* prefs) { | 683 PrefServiceBase* prefs) { |
685 // Find the Profile that contains the source PrefService. | 684 // Find the Profile that contains the source PrefService. |
686 PrefChangeRegistrarMap::iterator pref_change_it = | 685 PrefChangeRegistrarMap::iterator pref_change_it = |
687 pref_change_registrar_map_.begin(); | 686 pref_change_registrar_map_.begin(); |
688 for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) { | 687 for (; pref_change_it != pref_change_registrar_map_.end(); ++pref_change_it) { |
689 if (pref_change_it->first->GetPrefs() == prefs) | 688 if (pref_change_it->first->GetPrefs() == prefs) |
690 break; | 689 break; |
(...skipping 23 matching lines...) Expand all Loading... | |
714 gallery_host_it->second->RevokeOldGalleries( | 713 gallery_host_it->second->RevokeOldGalleries( |
715 preferences->GalleriesForExtension(*extension)); | 714 preferences->GalleriesForExtension(*extension)); |
716 } | 715 } |
717 } | 716 } |
718 | 717 |
719 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 718 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
720 ScopedMTPDeviceMapEntry* | 719 ScopedMTPDeviceMapEntry* |
721 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry( | 720 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry( |
722 const FilePath::StringType& device_location) { | 721 const FilePath::StringType& device_location) { |
723 MTPDeviceDelegateMap::iterator delegate_it = | 722 MTPDeviceDelegateMap::iterator delegate_it = |
724 mtp_delegate_map_.find(device_location); | 723 mtp_device_delegate_map_.find(device_location); |
725 if (delegate_it != mtp_delegate_map_.end() && delegate_it->second.get()) | 724 if (delegate_it != mtp_device_delegate_map_.end()) |
726 return delegate_it->second; | 725 return delegate_it->second; |
727 ScopedMTPDeviceMapEntry* mtp_device_host = new ScopedMTPDeviceMapEntry( | 726 ScopedMTPDeviceMapEntry* mtp_device_host = new ScopedMTPDeviceMapEntry( |
728 device_location, base::Bind( | 727 device_location, base::Bind( |
Lei Zhang
2012/11/22 02:25:25
Why not just pass in |mtp_device_delegate_map_| in
kmadhusu
2012/11/22 02:41:10
MediaFileSystemRegistry owns |mtp_device_delegate_
Lei Zhang
2012/11/22 03:09:42
Sometimes it's ok for a class to give its private
| |
729 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry, | 728 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry, |
730 base::Unretained(this), device_location)); | 729 base::Unretained(this), device_location)); |
731 mtp_delegate_map_[device_location] = mtp_device_host->AsWeakPtr(); | 730 mtp_device_delegate_map_[device_location] = mtp_device_host; |
732 return mtp_device_host; | 731 return mtp_device_host; |
733 } | 732 } |
734 | 733 |
735 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry( | 734 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry( |
736 const FilePath::StringType& device_location) { | 735 const FilePath::StringType& device_location) { |
737 MTPDeviceDelegateMap::iterator delegate_it = | 736 MTPDeviceDelegateMap::iterator delegate_it = |
738 mtp_delegate_map_.find(device_location); | 737 mtp_device_delegate_map_.find(device_location); |
739 DCHECK(delegate_it != mtp_delegate_map_.end()); | 738 DCHECK(delegate_it != mtp_device_delegate_map_.end()); |
740 mtp_delegate_map_.erase(delegate_it); | 739 mtp_device_delegate_map_.erase(delegate_it); |
741 } | 740 } |
742 #endif | 741 #endif |
743 | 742 |
744 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( | 743 void MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty( |
745 Profile* profile, const std::string& extension_id) { | 744 Profile* profile, const std::string& extension_id) { |
746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
747 | 746 |
748 ExtensionGalleriesHostMap::iterator extension_hosts = | 747 ExtensionGalleriesHostMap::iterator extension_hosts = |
749 extension_hosts_map_.find(profile); | 748 extension_hosts_map_.find(profile); |
750 DCHECK(extension_hosts != extension_hosts_map_.end()); | 749 DCHECK(extension_hosts != extension_hosts_map_.end()); |
751 ExtensionHostMap::size_type erase_count = | 750 ExtensionHostMap::size_type erase_count = |
752 extension_hosts->second.erase(extension_id); | 751 extension_hosts->second.erase(extension_id); |
753 DCHECK_EQ(1U, erase_count); | 752 DCHECK_EQ(1U, erase_count); |
754 if (extension_hosts->second.empty()) { | 753 if (extension_hosts->second.empty()) { |
755 extension_hosts_map_.erase(extension_hosts); | 754 extension_hosts_map_.erase(extension_hosts); |
756 | 755 |
757 PrefChangeRegistrarMap::iterator pref_it = | 756 PrefChangeRegistrarMap::iterator pref_it = |
758 pref_change_registrar_map_.find(profile); | 757 pref_change_registrar_map_.find(profile); |
759 DCHECK(pref_it != pref_change_registrar_map_.end()); | 758 DCHECK(pref_it != pref_change_registrar_map_.end()); |
760 delete pref_it->second; | 759 delete pref_it->second; |
761 pref_change_registrar_map_.erase(pref_it); | 760 pref_change_registrar_map_.erase(pref_it); |
762 } | 761 } |
763 } | 762 } |
764 | 763 |
765 } // namespace chrome | 764 } // namespace chrome |
OLD | NEW |