| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 17 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 18 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | |
| 19 #include "chrome/browser/media_galleries/gallery_watch_manager.h" | 18 #include "chrome/browser/media_galleries/gallery_watch_manager.h" |
| 20 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 19 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
| 21 #include "chrome/browser/media_galleries/media_file_system_context.h" | 20 #include "chrome/browser/media_galleries/media_file_system_context.h" |
| 22 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | 21 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
| 23 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 22 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
| 24 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" | 23 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.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/keyed_service/content/browser_context_keyed_service_shutdow
n_notifier_factory.h" | 27 #include "components/keyed_service/content/browser_context_keyed_service_shutdow
n_notifier_factory.h" |
| 29 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
| 30 #include "components/storage_monitor/media_storage_util.h" | 29 #include "components/storage_monitor/media_storage_util.h" |
| 31 #include "components/storage_monitor/storage_monitor.h" | 30 #include "components/storage_monitor/storage_monitor.h" |
| 32 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/navigation_details.h" | 32 #include "content/public/browser/navigation_details.h" |
| 34 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/browser/render_process_host_observer.h" | 34 #include "content/public/browser/render_process_host_observer.h" |
| 36 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 37 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/browser/web_contents_observer.h" | 37 #include "content/public/browser/web_contents_observer.h" |
| 39 #include "extensions/browser/extension_registry.h" | 38 #include "extensions/browser/extension_registry.h" |
| 40 #include "extensions/common/extension.h" | 39 #include "extensions/common/extension.h" |
| 41 #include "extensions/common/extension_set.h" | 40 #include "extensions/common/extension_set.h" |
| 42 #include "storage/browser/fileapi/external_mount_points.h" | 41 #include "storage/browser/fileapi/external_mount_points.h" |
| 43 #include "storage/common/fileapi/file_system_mount_option.h" | 42 #include "storage/common/fileapi/file_system_mount_option.h" |
| 44 #include "storage/common/fileapi/file_system_types.h" | 43 #include "storage/common/fileapi/file_system_types.h" |
| 45 | 44 |
| 45 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 46 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 47 #endif |
| 48 |
| 46 using content::BrowserThread; | 49 using content::BrowserThread; |
| 47 using content::NavigationController; | 50 using content::NavigationController; |
| 48 using content::RenderProcessHost; | 51 using content::RenderProcessHost; |
| 49 using content::WebContents; | 52 using content::WebContents; |
| 50 using storage::ExternalMountPoints; | 53 using storage::ExternalMountPoints; |
| 51 using storage_monitor::MediaStorageUtil; | 54 using storage_monitor::MediaStorageUtil; |
| 52 using storage_monitor::StorageInfo; | 55 using storage_monitor::StorageInfo; |
| 53 using storage_monitor::StorageMonitor; | 56 using storage_monitor::StorageMonitor; |
| 54 | 57 |
| 55 namespace { | 58 namespace { |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 659 |
| 657 class MediaFileSystemRegistry::MediaFileSystemContextImpl | 660 class MediaFileSystemRegistry::MediaFileSystemContextImpl |
| 658 : public MediaFileSystemContext { | 661 : public MediaFileSystemContext { |
| 659 public: | 662 public: |
| 660 MediaFileSystemContextImpl() {} | 663 MediaFileSystemContextImpl() {} |
| 661 ~MediaFileSystemContextImpl() override {} | 664 ~MediaFileSystemContextImpl() override {} |
| 662 | 665 |
| 663 bool RegisterFileSystem(const std::string& device_id, | 666 bool RegisterFileSystem(const std::string& device_id, |
| 664 const std::string& fs_name, | 667 const std::string& fs_name, |
| 665 const base::FilePath& path) override { | 668 const base::FilePath& path) override { |
| 666 if (StorageInfo::IsMassStorageDevice(device_id)) { | 669 if (StorageInfo::IsMassStorageDevice(device_id)) |
| 667 return RegisterFileSystemForMassStorage(device_id, fs_name, path); | 670 return RegisterFileSystemForMassStorage(device_id, fs_name, path); |
| 668 } else { | 671 return RegisterFileSystemForMTPDevice(device_id, fs_name, path); |
| 669 return RegisterFileSystemForMTPDevice(device_id, fs_name, path); | |
| 670 } | |
| 671 } | 672 } |
| 672 | 673 |
| 673 void RevokeFileSystem(const std::string& fs_name) override { | 674 void RevokeFileSystem(const std::string& fs_name) override { |
| 674 ImportedMediaGalleryRegistry* imported_registry = | 675 ImportedMediaGalleryRegistry* imported_registry = |
| 675 ImportedMediaGalleryRegistry::GetInstance(); | 676 ImportedMediaGalleryRegistry::GetInstance(); |
| 676 if (imported_registry->RevokeImportedFilesystemOnUIThread(fs_name)) | 677 if (imported_registry->RevokeImportedFilesystemOnUIThread(fs_name)) |
| 677 return; | 678 return; |
| 678 | 679 |
| 679 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name); | 680 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name); |
| 680 | 681 |
| 682 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 681 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 683 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 682 &MTPDeviceMapService::RevokeMTPFileSystem, | 684 &MTPDeviceMapService::RevokeMTPFileSystem, |
| 683 base::Unretained(MTPDeviceMapService::GetInstance()), | 685 base::Unretained(MTPDeviceMapService::GetInstance()), |
| 684 fs_name)); | 686 fs_name)); |
| 687 #endif |
| 685 } | 688 } |
| 686 | 689 |
| 687 base::FilePath GetRegisteredPath(const std::string& fs_name) const override { | 690 base::FilePath GetRegisteredPath(const std::string& fs_name) const override { |
| 688 base::FilePath result; | 691 base::FilePath result; |
| 689 if (!ExternalMountPoints::GetSystemInstance()->GetRegisteredPath(fs_name, | 692 if (!ExternalMountPoints::GetSystemInstance()->GetRegisteredPath(fs_name, |
| 690 &result)) { | 693 &result)) { |
| 691 return base::FilePath(); | 694 return base::FilePath(); |
| 692 } | 695 } |
| 693 return result; | 696 return result; |
| 694 } | 697 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 725 storage::kFileSystemTypeNativeMedia, | 728 storage::kFileSystemTypeNativeMedia, |
| 726 storage::FileSystemMountOption(), | 729 storage::FileSystemMountOption(), |
| 727 path); | 730 path); |
| 728 } | 731 } |
| 729 return result; | 732 return result; |
| 730 } | 733 } |
| 731 | 734 |
| 732 bool RegisterFileSystemForMTPDevice(const std::string& device_id, | 735 bool RegisterFileSystemForMTPDevice(const std::string& device_id, |
| 733 const std::string fs_name, | 736 const std::string fs_name, |
| 734 const base::FilePath& path) { | 737 const base::FilePath& path) { |
| 738 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 735 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 739 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 736 DCHECK(!StorageInfo::IsMassStorageDevice(device_id)); | 740 DCHECK(!StorageInfo::IsMassStorageDevice(device_id)); |
| 737 | 741 |
| 738 // Sanity checks for |path|. | 742 // Sanity checks for |path|. |
| 739 CHECK(MediaStorageUtil::CanCreateFileSystem(device_id, path)); | 743 CHECK(MediaStorageUtil::CanCreateFileSystem(device_id, path)); |
| 740 bool result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 744 bool result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 741 fs_name, | 745 fs_name, |
| 742 storage::kFileSystemTypeDeviceMedia, | 746 storage::kFileSystemTypeDeviceMedia, |
| 743 storage::FileSystemMountOption(), | 747 storage::FileSystemMountOption(), |
| 744 path); | 748 path); |
| 745 CHECK(result); | 749 CHECK(result); |
| 746 BrowserThread::PostTask( | 750 BrowserThread::PostTask( |
| 747 BrowserThread::IO, FROM_HERE, | 751 BrowserThread::IO, FROM_HERE, |
| 748 base::Bind(&MTPDeviceMapService::RegisterMTPFileSystem, | 752 base::Bind(&MTPDeviceMapService::RegisterMTPFileSystem, |
| 749 base::Unretained(MTPDeviceMapService::GetInstance()), | 753 base::Unretained(MTPDeviceMapService::GetInstance()), |
| 750 path.value(), fs_name, true /* read only */)); | 754 path.value(), fs_name, true /* read only */)); |
| 751 return result; | 755 return result; |
| 756 #else |
| 757 NOTREACHED(); |
| 758 return false; |
| 759 #endif |
| 752 } | 760 } |
| 753 | 761 |
| 754 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); | 762 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); |
| 755 }; | 763 }; |
| 756 | 764 |
| 757 // Constructor in 'private' section because depends on private class definition. | 765 // Constructor in 'private' section because depends on private class definition. |
| 758 MediaFileSystemRegistry::MediaFileSystemRegistry() | 766 MediaFileSystemRegistry::MediaFileSystemRegistry() |
| 759 : file_system_context_(new MediaFileSystemContextImpl) { | 767 : file_system_context_(new MediaFileSystemContextImpl) { |
| 760 StorageMonitor::GetInstance()->AddObserver(this); | 768 StorageMonitor::GetInstance()->AddObserver(this); |
| 761 } | 769 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 878 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 871 | 879 |
| 872 auto extension_hosts_it = extension_hosts_map_.find(profile); | 880 auto extension_hosts_it = extension_hosts_map_.find(profile); |
| 873 DCHECK(extension_hosts_it != extension_hosts_map_.end()); | 881 DCHECK(extension_hosts_it != extension_hosts_map_.end()); |
| 874 extension_hosts_map_.erase(extension_hosts_it); | 882 extension_hosts_map_.erase(extension_hosts_it); |
| 875 | 883 |
| 876 auto profile_subscription_it = profile_subscription_map_.find(profile); | 884 auto profile_subscription_it = profile_subscription_map_.find(profile); |
| 877 DCHECK(profile_subscription_it != profile_subscription_map_.end()); | 885 DCHECK(profile_subscription_it != profile_subscription_map_.end()); |
| 878 profile_subscription_map_.erase(profile_subscription_it); | 886 profile_subscription_map_.erase(profile_subscription_it); |
| 879 } | 887 } |
| OLD | NEW |