OLD | NEW |
(Empty) | |
| 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_ITUNES_DATA_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_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/files/file_path.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/itunes_library_parser.h" |
| 16 |
| 17 namespace itunes { |
| 18 |
| 19 // This class is the holder for iTunes parsed data. Given a path to the iTunes |
| 20 // library xml file it will read it in, parse the data, and provide convenient |
| 21 // methods to access it. When the file changes, it will update the data. |
| 22 // It is not thread safe, but can be run on any thread with IO access. |
| 23 class ITunesDataProvider { |
| 24 public: |
| 25 typedef std::string ArtistName; |
| 26 typedef std::string AlbumName; |
| 27 typedef std::string TrackName; |
| 28 typedef std::map<TrackName, base::FilePath> Album; |
| 29 |
| 30 explicit ITunesDataProvider(const base::FilePath& library_path); |
| 31 ~ITunesDataProvider(); |
| 32 |
| 33 // Ask the data provider to refresh the data if necessary. |ready_callback| |
| 34 // will be called when the data is up to date. |
| 35 void RefreshData(const base::Closure& ready_callback); |
| 36 |
| 37 // Get the platform path for the library xml file. |
| 38 const base::FilePath& library_path() const; |
| 39 |
| 40 // Returns true if |artist| exists in the library. |
| 41 bool KnownArtist(const ArtistName& artist) const; |
| 42 |
| 43 // Returns true if |artist| has an album by the name |album| in the library. |
| 44 bool KnownAlbum(const ArtistName& artist, const AlbumName& album) const; |
| 45 |
| 46 // Get the track named (filename basename) |track| in |album| by |artist|. |
| 47 // If no such track exists, an empty FilePath is returned. |
| 48 base::FilePath GetTrackLocation(const ArtistName& artist, |
| 49 const AlbumName& album, |
| 50 const TrackName& track) const; |
| 51 |
| 52 // Get the set of artists. |
| 53 std::set<ArtistName> GetArtistNames() const; |
| 54 |
| 55 // Get the set of albums for |artist|. |
| 56 std::set<AlbumName> GetAlbumNames(const ArtistName& artist) const; |
| 57 |
| 58 // Get the tracks for the |album| by |artist|. |
| 59 Album GetAlbum(const ArtistName& artist, const AlbumName& album) const; |
| 60 |
| 61 private: |
| 62 typedef std::map<AlbumName, Album> Artist; |
| 63 typedef std::map<ArtistName, Artist> Library; |
| 64 |
| 65 void ParseLibrary(); |
| 66 |
| 67 const base::FilePath library_path_; |
| 68 |
| 69 Library library_; |
| 70 |
| 71 bool needs_refresh_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(ITunesDataProvider); |
| 74 }; |
| 75 |
| 76 } // namespace itunes |
| 77 |
| 78 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ |
OLD | NEW |