1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_IMPORTED_MEDIA_GALLERY_REGISTRY_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_IMPORTED_MEDIA_GALLERY_REGISTRY_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "base/files/file_path.h" 13 #include "base/lazy_instance.h" 14 #include "base/memory/scoped_ptr.h" 15 16 namespace iphoto { 17 class IPhotoDataProvider; 18 class IPhotoDataProviderTest; 19 } 20 21 namespace itunes { 22 class ITunesDataProvider; 23 class ITunesDataProviderTest; 24 } 25 26 namespace picasa { 27 class PicasaDataProvider; 28 class PicasaDataProviderTest; 29 } 30 31 // This class lives on the MediaTaskRunner thread. It has some static 32 // methods which are called on the UI thread. 33 // 34 // MediaTaskRunner is not guaranteed to be one thread, but it is guaranteed 35 // to be a series of sequential calls. See SequencedTaskRunner for details. 36 class ImportedMediaGalleryRegistry { 37 public: 38 static ImportedMediaGalleryRegistry* GetInstance(); 39 40 void Initialize(); 41 42 // Should be called on the UI thread only. 43 bool RegisterPicasaFilesystemOnUIThread(const std::string& fs_name, 44 const base::FilePath& database_path); 45 46 bool RegisterITunesFilesystemOnUIThread( 47 const std::string& fs_name, 48 const base::FilePath& xml_library_path); 49 50 bool RegisterIPhotoFilesystemOnUIThread( 51 const std::string& fs_name, 52 const base::FilePath& xml_library_path); 53 54 bool RevokeImportedFilesystemOnUIThread(const std::string& fs_name); 55 56 // Path where all virtual file systems are "mounted." 57 base::FilePath ImportedRoot(); 58 59 // Should be called on the MediaTaskRunner thread only. 60 #if defined(OS_WIN) || defined(OS_MACOSX) 61 static picasa::PicasaDataProvider* PicasaDataProvider(); 62 static itunes::ITunesDataProvider* ITunesDataProvider(); 63 #endif // defined(OS_WIN) || defined(OS_MACOSX) 64 65 #if defined(OS_MACOSX) 66 static iphoto::IPhotoDataProvider* IPhotoDataProvider(); 67 #endif // defined(OS_MACOSX) 68 69 private: 70 friend struct base::DefaultLazyInstanceTraits<ImportedMediaGalleryRegistry>; 71 friend class iphoto::IPhotoDataProviderTest; 72 friend class itunes::ITunesDataProviderTest; 73 friend class picasa::PicasaDataProviderTest; 74 75 ImportedMediaGalleryRegistry(); 76 virtual ~ImportedMediaGalleryRegistry(); 77 78 #if defined(OS_WIN) || defined(OS_MACOSX) 79 void RegisterPicasaFileSystem(const base::FilePath& database_path); 80 void RevokePicasaFileSystem(); 81 82 void RegisterITunesFileSystem(const base::FilePath& xml_library_path); 83 void RevokeITunesFileSystem(); 84 #endif // defined(OS_WIN) || defined(OS_MACOSX) 85 86 #if defined(OS_MACOSX) 87 void RegisterIPhotoFileSystem(const base::FilePath& xml_library_path); 88 void RevokeIPhotoFileSystem(); 89 #endif // defined(OS_MACOSX) 90 91 base::FilePath imported_root_; 92 93 #if defined(OS_WIN) || defined(OS_MACOSX) 94 // The data providers are only set or accessed on the task runner thread. 95 scoped_ptr<picasa::PicasaDataProvider> picasa_data_provider_; 96 scoped_ptr<itunes::ITunesDataProvider> itunes_data_provider_; 97 98 // The remaining members are only accessed on the IO thread. 99 std::set<std::string> picasa_fs_names_; 100 std::set<std::string> itunes_fs_names_; 101 102 #ifndef NDEBUG 103 base::FilePath picasa_database_path_; 104 base::FilePath itunes_xml_library_path_; 105 #endif 106 #endif // defined(OS_WIN) || defined(OS_MACOSX) 107 108 #if defined(OS_MACOSX) 109 scoped_ptr<iphoto::IPhotoDataProvider> iphoto_data_provider_; 110 111 std::set<std::string> iphoto_fs_names_; 112 113 #ifndef NDEBUG 114 base::FilePath iphoto_xml_library_path_; 115 #endif 116 #endif // defined(OS_MACOSX) 117 118 DISALLOW_COPY_AND_ASSIGN(ImportedMediaGalleryRegistry); 119 }; 120 121 #endif // CHROME_BROWSER_MEDIA_GALLERIES_IMPORTED_MEDIA_GALLERY_REGISTRY_H_ 122