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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 callback); | 538 callback); |
539 } | 539 } |
540 | 540 |
541 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( | 541 MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences( |
542 Profile* profile) { | 542 Profile* profile) { |
543 MediaGalleriesPreferences* preferences = | 543 MediaGalleriesPreferences* preferences = |
544 MediaGalleriesPreferencesFactory::GetForProfile(profile); | 544 MediaGalleriesPreferencesFactory::GetForProfile(profile); |
545 if (ContainsKey(extension_hosts_map_, profile)) | 545 if (ContainsKey(extension_hosts_map_, profile)) |
546 return preferences; | 546 return preferences; |
547 | 547 |
| 548 // Create an empty entry so the initialization code below only gets called |
| 549 // once per profile. |
| 550 extension_hosts_map_[profile] = ExtensionHostMap(); |
| 551 |
548 // RemovableStorageNotifications may be NULL in unit tests. | 552 // RemovableStorageNotifications may be NULL in unit tests. |
549 RemovableStorageNotifications* notifications = | 553 RemovableStorageNotifications* notifications = |
550 RemovableStorageNotifications::GetInstance(); | 554 RemovableStorageNotifications::GetInstance(); |
551 if (!notifications) | 555 if (!notifications) |
552 return preferences; | 556 return preferences; |
553 std::vector<RemovableStorageNotifications::StorageInfo> | 557 std::vector<RemovableStorageNotifications::StorageInfo> |
554 existing_devices = notifications->GetAttachedStorage(); | 558 existing_devices = notifications->GetAttachedStorage(); |
555 for (size_t i = 0; i < existing_devices.size(); i++) { | 559 for (size_t i = 0; i < existing_devices.size(); i++) { |
556 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) | 560 if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id)) |
557 continue; | 561 continue; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 for (std::set<MediaGalleryPrefId>::const_iterator pref_id_it = | 622 for (std::set<MediaGalleryPrefId>::const_iterator pref_id_it = |
619 invalid_galleries_info[i].pref_ids.begin(); | 623 invalid_galleries_info[i].pref_ids.begin(); |
620 pref_id_it != invalid_galleries_info[i].pref_ids.end(); | 624 pref_id_it != invalid_galleries_info[i].pref_ids.end(); |
621 ++pref_id_it) { | 625 ++pref_id_it) { |
622 (*extension_host_it)->RevokeGalleryByPrefId(*pref_id_it); | 626 (*extension_host_it)->RevokeGalleryByPrefId(*pref_id_it); |
623 } | 627 } |
624 } | 628 } |
625 } | 629 } |
626 } | 630 } |
627 | 631 |
628 size_t MediaFileSystemRegistry::GetExtensionHostCountForTests() const { | 632 size_t MediaFileSystemRegistry::GetExtensionGalleriesHostCountForTests() const { |
629 return extension_hosts_map_.size(); | 633 size_t extension_galleries_host_count = 0; |
| 634 for (ExtensionGalleriesHostMap::const_iterator it = |
| 635 extension_hosts_map_.begin(); |
| 636 it != extension_hosts_map_.end(); |
| 637 ++it) { |
| 638 extension_galleries_host_count += it->second.size(); |
| 639 } |
| 640 return extension_galleries_host_count; |
630 } | 641 } |
631 | 642 |
632 uint64 MediaFileSystemRegistry::GetTransientIdForDeviceId( | 643 uint64 MediaFileSystemRegistry::GetTransientIdForDeviceId( |
633 const std::string& device_id) { | 644 const std::string& device_id) { |
634 return transient_device_ids_.GetTransientIdForDeviceId(device_id); | 645 return transient_device_ids_.GetTransientIdForDeviceId(device_id); |
635 } | 646 } |
636 | 647 |
637 /****************** | 648 /****************** |
638 * Private methods | 649 * Private methods |
639 ******************/ | 650 ******************/ |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 Profile* profile, const std::string& extension_id) { | 808 Profile* profile, const std::string& extension_id) { |
798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
799 | 810 |
800 ExtensionGalleriesHostMap::iterator extension_hosts = | 811 ExtensionGalleriesHostMap::iterator extension_hosts = |
801 extension_hosts_map_.find(profile); | 812 extension_hosts_map_.find(profile); |
802 DCHECK(extension_hosts != extension_hosts_map_.end()); | 813 DCHECK(extension_hosts != extension_hosts_map_.end()); |
803 ExtensionHostMap::size_type erase_count = | 814 ExtensionHostMap::size_type erase_count = |
804 extension_hosts->second.erase(extension_id); | 815 extension_hosts->second.erase(extension_id); |
805 DCHECK_EQ(1U, erase_count); | 816 DCHECK_EQ(1U, erase_count); |
806 if (extension_hosts->second.empty()) { | 817 if (extension_hosts->second.empty()) { |
807 extension_hosts_map_.erase(extension_hosts); | 818 // When a profile has no ExtensionGalleriesHosts left, remove the |
808 | 819 // matching PrefChangeRegistrar since it is no longer needed. Leave the |
| 820 // |extension_hosts| entry alone, since it indicates the profile has been |
| 821 // previously used. |
809 PrefChangeRegistrarMap::iterator pref_it = | 822 PrefChangeRegistrarMap::iterator pref_it = |
810 pref_change_registrar_map_.find(profile); | 823 pref_change_registrar_map_.find(profile); |
811 DCHECK(pref_it != pref_change_registrar_map_.end()); | 824 DCHECK(pref_it != pref_change_registrar_map_.end()); |
812 delete pref_it->second; | 825 delete pref_it->second; |
813 pref_change_registrar_map_.erase(pref_it); | 826 pref_change_registrar_map_.erase(pref_it); |
814 } | 827 } |
815 } | 828 } |
816 | 829 |
817 } // namespace chrome | 830 } // namespace chrome |
OLD | NEW |