| 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 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 5 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | |
| 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 15 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 17 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 16 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 18 #include "chrome/browser/media_galleries/gallery_watch_manager.h" | 17 #include "chrome/browser/media_galleries/gallery_watch_manager.h" |
| 19 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 18 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
| 20 #include "chrome/browser/media_galleries/media_file_system_context.h" | 19 #include "chrome/browser/media_galleries/media_file_system_context.h" |
| 21 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | 20 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
| 22 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 21 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
| 23 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" | 22 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" |
| 24 #include "chrome/browser/media_galleries/media_scan_manager.h" | 23 #include "chrome/browser/media_galleries/media_scan_manager.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "components/storage_monitor/media_storage_util.h" | 27 #include "components/storage_monitor/media_storage_util.h" |
| 29 #include "components/storage_monitor/storage_monitor.h" | 28 #include "components/storage_monitor/storage_monitor.h" |
| 30 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/navigation_details.h" | 30 #include "content/public/browser/navigation_details.h" |
| 32 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/render_process_host_observer.h" | 32 #include "content/public/browser/render_process_host_observer.h" |
| 34 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
| 35 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
| 37 #include "extensions/browser/extension_system.h" | 36 #include "extensions/browser/extension_registry.h" |
| 38 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 39 #include "extensions/common/extension_set.h" | 38 #include "extensions/common/extension_set.h" |
| 40 #include "storage/browser/fileapi/external_mount_points.h" | 39 #include "storage/browser/fileapi/external_mount_points.h" |
| 41 #include "storage/common/fileapi/file_system_mount_option.h" | 40 #include "storage/common/fileapi/file_system_mount_option.h" |
| 42 #include "storage/common/fileapi/file_system_types.h" | 41 #include "storage/common/fileapi/file_system_types.h" |
| 43 | 42 |
| 44 using content::BrowserThread; | 43 using content::BrowserThread; |
| 45 using content::NavigationController; | 44 using content::NavigationController; |
| 46 using content::RenderProcessHost; | 45 using content::RenderProcessHost; |
| 47 using content::WebContents; | 46 using content::WebContents; |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 return; | 761 return; |
| 763 gallery_host_it->second->RevokeGalleryByPrefId(pref_id); | 762 gallery_host_it->second->RevokeGalleryByPrefId(pref_id); |
| 764 } | 763 } |
| 765 | 764 |
| 766 void MediaFileSystemRegistry::OnGalleryRemoved( | 765 void MediaFileSystemRegistry::OnGalleryRemoved( |
| 767 MediaGalleriesPreferences* prefs, | 766 MediaGalleriesPreferences* prefs, |
| 768 MediaGalleryPrefId pref_id) { | 767 MediaGalleryPrefId pref_id) { |
| 769 Profile* profile = prefs->profile(); | 768 Profile* profile = prefs->profile(); |
| 770 // Get the Extensions, MediaGalleriesPreferences and ExtensionHostMap for | 769 // Get the Extensions, MediaGalleriesPreferences and ExtensionHostMap for |
| 771 // |profile|. | 770 // |profile|. |
| 772 const ExtensionService* extension_service = | 771 const extensions::ExtensionRegistry* extension_registry = |
| 773 extensions::ExtensionSystem::Get(profile)->extension_service(); | 772 extensions::ExtensionRegistry::Get(profile); |
| 774 const extensions::ExtensionSet* extensions_set = | |
| 775 extension_service->extensions(); | |
| 776 ExtensionGalleriesHostMap::const_iterator host_map_it = | 773 ExtensionGalleriesHostMap::const_iterator host_map_it = |
| 777 extension_hosts_map_.find(profile); | 774 extension_hosts_map_.find(profile); |
| 778 DCHECK(host_map_it != extension_hosts_map_.end()); | 775 DCHECK(host_map_it != extension_hosts_map_.end()); |
| 779 const ExtensionHostMap& extension_host_map = host_map_it->second; | 776 const ExtensionHostMap& extension_host_map = host_map_it->second; |
| 780 | 777 |
| 781 // Go through ExtensionHosts, and remove indicated gallery, if any. | 778 // Go through ExtensionHosts, and remove indicated gallery, if any. |
| 782 // RevokeGalleryByPrefId() may end up deleting from |extension_host_map| and | 779 // RevokeGalleryByPrefId() may end up deleting from |extension_host_map| and |
| 783 // even delete |extension_host_map| altogether. So do this in two loops to | 780 // even delete |extension_host_map| altogether. So do this in two loops to |
| 784 // avoid using an invalidated iterator or deleted map. | 781 // avoid using an invalidated iterator or deleted map. |
| 785 std::vector<const extensions::Extension*> extensions; | 782 std::vector<const extensions::Extension*> extensions; |
| 786 for (ExtensionHostMap::const_iterator it = extension_host_map.begin(); | 783 for (ExtensionHostMap::const_iterator it = extension_host_map.begin(); |
| 787 it != extension_host_map.end(); | 784 it != extension_host_map.end(); |
| 788 ++it) { | 785 ++it) { |
| 789 extensions.push_back(extensions_set->GetByID(it->first)); | 786 extensions.push_back(extension_registry->GetExtensionById( |
| 787 it->first, extensions::ExtensionRegistry::ENABLED)); |
| 790 } | 788 } |
| 791 for (size_t i = 0; i < extensions.size(); ++i) { | 789 for (size_t i = 0; i < extensions.size(); ++i) { |
| 792 if (!ContainsKey(extension_hosts_map_, profile)) | 790 if (!ContainsKey(extension_hosts_map_, profile)) |
| 793 break; | 791 break; |
| 794 ExtensionHostMap::const_iterator gallery_host_it = | 792 ExtensionHostMap::const_iterator gallery_host_it = |
| 795 extension_host_map.find(extensions[i]->id()); | 793 extension_host_map.find(extensions[i]->id()); |
| 796 if (gallery_host_it == extension_host_map.end()) | 794 if (gallery_host_it == extension_host_map.end()) |
| 797 continue; | 795 continue; |
| 798 gallery_host_it->second->RevokeGalleryByPrefId(pref_id); | 796 gallery_host_it->second->RevokeGalleryByPrefId(pref_id); |
| 799 } | 797 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 DCHECK_EQ(1U, erase_count); | 836 DCHECK_EQ(1U, erase_count); |
| 839 if (extension_hosts->second.empty()) { | 837 if (extension_hosts->second.empty()) { |
| 840 // When a profile has no ExtensionGalleriesHosts left, remove the | 838 // When a profile has no ExtensionGalleriesHosts left, remove the |
| 841 // matching gallery-change-watcher since it is no longer needed. Leave the | 839 // matching gallery-change-watcher since it is no longer needed. Leave the |
| 842 // |extension_hosts| entry alone, since it indicates the profile has been | 840 // |extension_hosts| entry alone, since it indicates the profile has been |
| 843 // previously used. | 841 // previously used. |
| 844 MediaGalleriesPreferences* preferences = GetPreferences(profile); | 842 MediaGalleriesPreferences* preferences = GetPreferences(profile); |
| 845 preferences->RemoveGalleryChangeObserver(this); | 843 preferences->RemoveGalleryChangeObserver(this); |
| 846 } | 844 } |
| 847 } | 845 } |
| OLD | NEW |