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.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_
12 #include "base/basictypes.h"
13 #include "base/callback_forward.h"
14 #include "base/files/file_path.h"
15 #include "base/files/file_path_watcher.h"
16 #include "chrome/browser/media_galleries/fileapi/iapps_data_provider.h"
17 #include "chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h"
21 class TestITunesDataProvider
;
23 // This class is the holder for iTunes parsed data. Given a path to the iTunes
24 // library XML file it will read it in, parse the data, and provide convenient
25 // methods to access it. When the file changes, it will update the data.
26 // It is not thread safe, but can be run on any thread with IO access.
27 class ITunesDataProvider
: public iapps::IAppsDataProvider
{
29 typedef std::string ArtistName
;
30 typedef std::string AlbumName
;
31 typedef std::string TrackName
;
32 typedef std::map
<TrackName
, base::FilePath
> Album
;
34 explicit ITunesDataProvider(const base::FilePath
& library_path
);
35 ~ITunesDataProvider() override
;
37 // Get the platform path for the auto-add directory.
38 virtual const base::FilePath
& auto_add_path() const;
40 // Returns true if |artist| exists in the library.
41 bool KnownArtist(const ArtistName
& artist
) const;
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;
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;
52 // Get the set of artists.
53 std::set
<ArtistName
> GetArtistNames() const;
55 // Get the set of albums for |artist|.
56 std::set
<AlbumName
> GetAlbumNames(const ArtistName
& artist
) const;
58 // Get the tracks for the |album| by |artist|.
59 Album
GetAlbum(const ArtistName
& artist
, const AlbumName
& album
) const;
62 friend class TestITunesDataProvider
;
64 typedef std::map
<AlbumName
, Album
> Artist
;
65 typedef std::map
<ArtistName
, Artist
> Library
;
67 // Parse the library xml file.
68 void DoParseLibrary(const base::FilePath
& library_path
,
69 const ReadyCallback
& ready_callback
) override
;
71 // Called when the utility process finishes parsing the library XML file.
72 void OnLibraryParsed(const ReadyCallback
& ready_callback
,
74 const parser::Library
& library
);
76 // Path to the auto-add directory.
77 const base::FilePath auto_add_path_
;
79 // The parsed and uniquified data.
82 scoped_refptr
<iapps::SafeIAppsLibraryParser
> xml_parser_
;
84 // Hides parent class member, but it is private, and there's no way to get a
85 // WeakPtr<Derived> from a WeakPtr<Base> without using SupportsWeakPtr.
86 base::WeakPtrFactory
<ITunesDataProvider
> weak_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(ITunesDataProvider
);
93 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_