Home | History | Annotate | Download | only in media_galleries
      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 itunes {
     17 class ITunesDataProvider;
     18 class ITunesDataProviderTest;
     19 }
     20 
     21 namespace picasa {
     22 class PicasaDataProvider;
     23 }
     24 
     25 namespace chrome {
     26 
     27 // This class lives on the MediaTaskRunner thread. It has some static
     28 // methods which are called on the UI thread.
     29 //
     30 // MediaTaskRunner is not guaranteed to be one thread, but it is guaranteed
     31 // to be a series of sequential calls. See SequencedTaskRunner for details.
     32 class ImportedMediaGalleryRegistry {
     33  public:
     34   static ImportedMediaGalleryRegistry* GetInstance();
     35 
     36   // Should be called on the UI thread only.
     37   std::string RegisterPicasaFilesystemOnUIThread(
     38       const base::FilePath& database_path);
     39 
     40   std::string RegisterITunesFilesystemOnUIThread(
     41       const base::FilePath& xml_library_path);
     42 
     43   bool RevokeImportedFilesystemOnUIThread(const std::string& fsid);
     44 
     45   // Should be called on the MediaTaskRunner thread only.
     46 #if defined(OS_WIN) || defined(OS_MACOSX)
     47   static picasa::PicasaDataProvider* PicasaDataProvider();
     48   static itunes::ITunesDataProvider* ITunesDataProvider();
     49 #endif  // defined(OS_WIN) || defined(OS_MACOSX)
     50 
     51  private:
     52   friend struct base::DefaultLazyInstanceTraits<ImportedMediaGalleryRegistry>;
     53   friend class itunes::ITunesDataProviderTest;
     54 
     55   ImportedMediaGalleryRegistry();
     56   virtual ~ImportedMediaGalleryRegistry();
     57 
     58 #if defined(OS_WIN) || defined(OS_MACOSX)
     59   void RegisterPicasaFileSystem(const base::FilePath& database_path);
     60   void RevokePicasaFileSystem();
     61 
     62   void RegisterITunesFileSystem(const base::FilePath& xml_library_path);
     63   void RevokeITunesFileSystem();
     64 
     65   // The data providers are only set or accessed on the task runner thread.
     66   scoped_ptr<picasa::PicasaDataProvider> picasa_data_provider_;
     67   scoped_ptr<itunes::ITunesDataProvider> itunes_data_provider_;
     68 
     69   // The remaining members are only accessed on the IO thread.
     70   std::set<std::string> picasa_fsids_;
     71   std::set<std::string> itunes_fsids_;
     72 
     73 #ifndef NDEBUG
     74   base::FilePath picasa_database_path_;
     75   base::FilePath itunes_xml_library_path_;
     76 #endif
     77 #endif  // defined(OS_WIN) || defined(OS_MACOSX)
     78 
     79   DISALLOW_COPY_AND_ASSIGN(ImportedMediaGalleryRegistry);
     80 };
     81 
     82 }  // namespace chrome
     83 
     84 #endif  // CHROME_BROWSER_MEDIA_GALLERIES_IMPORTED_MEDIA_GALLERY_REGISTRY_H_
     85