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 // Should be called on the UI thread only. 41 std::string RegisterPicasaFilesystemOnUIThread( 42 const base::FilePath& database_path); 43 44 std::string RegisterITunesFilesystemOnUIThread( 45 const base::FilePath& xml_library_path); 46 47 std::string RegisterIPhotoFilesystemOnUIThread( 48 const base::FilePath& xml_library_path); 49 50 bool RevokeImportedFilesystemOnUIThread(const std::string& fsid); 51 52 // Should be called on the MediaTaskRunner thread only. 53 #if defined(OS_WIN) || defined(OS_MACOSX) 54 static picasa::PicasaDataProvider* PicasaDataProvider(); 55 static itunes::ITunesDataProvider* ITunesDataProvider(); 56 #endif // defined(OS_WIN) || defined(OS_MACOSX) 57 58 #if defined(OS_MACOSX) 59 static iphoto::IPhotoDataProvider* IPhotoDataProvider(); 60 #endif // defined(OS_MACOSX) 61 62 private: 63 friend struct base::DefaultLazyInstanceTraits<ImportedMediaGalleryRegistry>; 64 friend class iphoto::IPhotoDataProviderTest; 65 friend class itunes::ITunesDataProviderTest; 66 friend class picasa::PicasaDataProviderTest; 67 68 ImportedMediaGalleryRegistry(); 69 virtual ~ImportedMediaGalleryRegistry(); 70 71 #if defined(OS_WIN) || defined(OS_MACOSX) 72 void RegisterPicasaFileSystem(const base::FilePath& database_path); 73 void RevokePicasaFileSystem(); 74 75 void RegisterITunesFileSystem(const base::FilePath& xml_library_path); 76 void RevokeITunesFileSystem(); 77 #endif // defined(OS_WIN) || defined(OS_MACOSX) 78 79 #if defined(OS_MACOSX) 80 void RegisterIPhotoFileSystem(const base::FilePath& xml_library_path); 81 void RevokeIPhotoFileSystem(); 82 #endif // defined(OS_MACOSX) 83 84 #if defined(OS_WIN) || defined(OS_MACOSX) 85 // The data providers are only set or accessed on the task runner thread. 86 scoped_ptr<picasa::PicasaDataProvider> picasa_data_provider_; 87 scoped_ptr<itunes::ITunesDataProvider> itunes_data_provider_; 88 89 // The remaining members are only accessed on the IO thread. 90 std::set<std::string> picasa_fsids_; 91 std::set<std::string> itunes_fsids_; 92 93 #ifndef NDEBUG 94 base::FilePath picasa_database_path_; 95 base::FilePath itunes_xml_library_path_; 96 #endif 97 #endif // defined(OS_WIN) || defined(OS_MACOSX) 98 99 #if defined(OS_MACOSX) 100 scoped_ptr<iphoto::IPhotoDataProvider> iphoto_data_provider_; 101 102 std::set<std::string> iphoto_fsids_; 103 104 #ifndef NDEBUG 105 base::FilePath iphoto_xml_library_path_; 106 #endif 107 #endif // defined(OS_MACOSX) 108 109 DISALLOW_COPY_AND_ASSIGN(ImportedMediaGalleryRegistry); 110 }; 111 112 #endif // CHROME_BROWSER_MEDIA_GALLERIES_IMPORTED_MEDIA_GALLERY_REGISTRY_H_ 113