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_FILEAPI_IPHOTO_DATA_PROVIDER_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_DATA_PROVIDER_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 12 #include "base/basictypes.h" 13 #include "base/callback_forward.h" 14 #include "base/containers/hash_tables.h" 15 #include "base/files/file_path.h" 16 #include "base/files/file_path_watcher.h" 17 #include "base/memory/weak_ptr.h" 18 #include "chrome/browser/media_galleries/fileapi/iapps_data_provider.h" 19 #include "chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h" 20 #include "chrome/common/media_galleries/iphoto_library.h" 21 22 namespace iphoto { 23 24 // This class is the holder for iPhoto parsed data. Given a path to the iPhoto 25 // library XML file it will read it in, parse the data, and provide convenient 26 // methods to access it. When the file changes, it will update the data. 27 // It is not thread safe, but can be run on any thread with IO access. 28 class IPhotoDataProvider : public iapps::IAppsDataProvider { 29 public: 30 explicit IPhotoDataProvider(const base::FilePath& library_path); 31 virtual ~IPhotoDataProvider(); 32 33 // Parse the library xml file. 34 virtual void DoParseLibrary(const base::FilePath& library_path, 35 const ReadyCallback& ready_callback) OVERRIDE; 36 37 virtual std::vector<std::string> GetAlbumNames() const; 38 virtual std::map<std::string, base::FilePath> GetAlbumContents( 39 const std::string& album) const; 40 virtual base::FilePath GetPhotoLocationInAlbum( 41 const std::string& album, 42 const std::string& filename) const; 43 44 virtual bool HasOriginals(const std::string& album) const; 45 virtual std::map<std::string, base::FilePath> GetOriginals( 46 const std::string& album) const; 47 virtual base::FilePath GetOriginalPhotoLocation( 48 const std::string& album, 49 const std::string& filename) const; 50 51 private: 52 typedef base::hash_map<std::string, base::FilePath> FileIndex; 53 // Map from album name to a map of filename to path. 54 typedef base::hash_map<std::string, FileIndex> DirIndex; 55 56 void OnLibraryParsed(const ReadyCallback& ready_callback, 57 bool result, 58 const parser::Library& library); 59 60 void BuildIndices(const parser::Library& library); 61 62 // Index for library data as it is presented in the virtual FS. 63 DirIndex dir_index_; 64 65 // Index for originals data. 66 DirIndex originals_index_; 67 68 scoped_refptr<iapps::SafeIAppsLibraryParser> xml_parser_; 69 70 base::WeakPtrFactory<IPhotoDataProvider> weak_factory_; 71 72 DISALLOW_COPY_AND_ASSIGN(IPhotoDataProvider); 73 }; 74 75 } // namespace iphoto 76 77 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IPHOTO_DATA_PROVIDER_H_ 78