OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_path_watcher.h" | 15 #include "base/files/file_path_watcher.h" |
16 #include "chrome/browser/media_galleries/fileapi/safe_itunes_library_parser.h" | 16 #include "chrome/browser/media_galleries/fileapi/safe_itunes_library_parser.h" |
17 | 17 |
18 namespace itunes { | 18 namespace itunes { |
19 | 19 |
20 class TestITunesDataProvider; | |
21 | |
20 // This class is the holder for iTunes parsed data. Given a path to the iTunes | 22 // This class is the holder for iTunes parsed data. Given a path to the iTunes |
21 // library XML file it will read it in, parse the data, and provide convenient | 23 // library XML file it will read it in, parse the data, and provide convenient |
22 // methods to access it. When the file changes, it will update the data. | 24 // methods to access it. When the file changes, it will update the data. |
23 // It is not thread safe, but can be run on any thread with IO access. | 25 // It is not thread safe, but can be run on any thread with IO access. |
24 class ITunesDataProvider { | 26 class ITunesDataProvider { |
25 public: | 27 public: |
26 typedef std::string ArtistName; | 28 typedef std::string ArtistName; |
27 typedef std::string AlbumName; | 29 typedef std::string AlbumName; |
28 typedef std::string TrackName; | 30 typedef std::string TrackName; |
29 typedef std::map<TrackName, base::FilePath> Album; | 31 typedef std::map<TrackName, base::FilePath> Album; |
30 typedef base::Callback<void(bool)> ReadyCallback; | 32 typedef base::Callback<void(bool)> ReadyCallback; |
31 | 33 |
32 explicit ITunesDataProvider(const base::FilePath& library_path); | 34 explicit ITunesDataProvider(const base::FilePath& library_path); |
33 ~ITunesDataProvider(); | 35 virtual ~ITunesDataProvider(); |
34 | 36 |
35 // Ask the data provider to refresh the data if necessary. |ready_callback| | 37 // Ask the data provider to refresh the data if necessary. |ready_callback| |
36 // will be called with the result; false if unable to parse the XML file. | 38 // will be called with the result; false if unable to parse the XML file. |
37 void RefreshData(const ReadyCallback& ready_callback); | 39 void RefreshData(const ReadyCallback& ready_callback); |
38 | 40 |
39 // Get the platform path for the library XML file. | 41 // Get the platform path for the library XML file. |
40 const base::FilePath& library_path() const; | 42 const base::FilePath& library_path() const; |
41 | 43 |
42 // Returns true if |artist| exists in the library. | 44 // Returns true if |artist| exists in the library. |
43 bool KnownArtist(const ArtistName& artist) const; | 45 bool KnownArtist(const ArtistName& artist) const; |
(...skipping 10 matching lines...) Expand all Loading... | |
54 // Get the set of artists. | 56 // Get the set of artists. |
55 std::set<ArtistName> GetArtistNames() const; | 57 std::set<ArtistName> GetArtistNames() const; |
56 | 58 |
57 // Get the set of albums for |artist|. | 59 // Get the set of albums for |artist|. |
58 std::set<AlbumName> GetAlbumNames(const ArtistName& artist) const; | 60 std::set<AlbumName> GetAlbumNames(const ArtistName& artist) const; |
59 | 61 |
60 // Get the tracks for the |album| by |artist|. | 62 // Get the tracks for the |album| by |artist|. |
61 Album GetAlbum(const ArtistName& artist, const AlbumName& album) const; | 63 Album GetAlbum(const ArtistName& artist, const AlbumName& album) const; |
62 | 64 |
63 private: | 65 private: |
66 friend class itunes::TestITunesDataProvider; | |
Lei Zhang
2013/07/17 02:21:35
nit: no need for itunes::
vandebo (ex-Chrome)
2013/07/17 04:22:18
Done.
| |
67 | |
64 typedef std::map<AlbumName, Album> Artist; | 68 typedef std::map<AlbumName, Album> Artist; |
65 typedef std::map<ArtistName, Artist> Library; | 69 typedef std::map<ArtistName, Artist> Library; |
66 | 70 |
67 // These are hacks to work around http://crbug.com/165590. Otherwise a | 71 // These are hacks to work around http://crbug.com/165590. Otherwise a |
68 // WeakPtrFactory would be the obvious answer here. | 72 // WeakPtrFactory would be the obvious answer here. |
69 // static so they can call their real counterparts. | 73 // static so they can call their real counterparts. |
70 // TODO(vandebo) Remove these when the bug is fixed. | 74 // TODO(vandebo) Remove these when the bug is fixed. |
71 static void OnLibraryWatchStartedCallback( | 75 static void OnLibraryWatchStartedCallback( |
72 scoped_ptr<base::FilePathWatcher> library_watcher); | 76 scoped_ptr<base::FilePathWatcher> library_watcher); |
73 static void OnLibraryChangedCallback(const base::FilePath& path, bool error); | 77 static void OnLibraryChangedCallback(const base::FilePath& path, bool error); |
74 static void OnLibraryParsedCallback(const ReadyCallback& ready_callback, | 78 static void OnLibraryParsedCallback(const ReadyCallback& ready_callback, |
75 bool result, | 79 bool result, |
76 const parser::Library& library); | 80 const parser::Library& library); |
77 | 81 |
78 // Called when the FilePathWatcher for |library_path_| has tried to add an | 82 // Called when the FilePathWatcher for |library_path_| has tried to add an |
79 // watch. | 83 // watch. |
80 void OnLibraryWatchStarted(scoped_ptr<base::FilePathWatcher> library_watcher); | 84 void OnLibraryWatchStarted(scoped_ptr<base::FilePathWatcher> library_watcher); |
81 | 85 |
82 // Called when |library_path_| has changed. | 86 // Called when |library_path_| has changed. Virtual for testing. |
83 void OnLibraryChanged(const base::FilePath& path, bool error); | 87 virtual void OnLibraryChanged(const base::FilePath& path, bool error); |
84 | 88 |
85 // Called when the utility process finishes parsing the library XML file. | 89 // Called when the utility process finishes parsing the library XML file. |
86 void OnLibraryParsed(const ReadyCallback& ready_callback, | 90 void OnLibraryParsed(const ReadyCallback& ready_callback, |
87 bool result, | 91 bool result, |
88 const parser::Library& library); | 92 const parser::Library& library); |
89 | 93 |
90 // Path to the library XML file. | 94 // Path to the library XML file. |
91 const base::FilePath library_path_; | 95 const base::FilePath library_path_; |
92 | 96 |
93 // The parsed and uniquified data. | 97 // The parsed and uniquified data. |
(...skipping 10 matching lines...) Expand all Loading... | |
104 scoped_ptr<base::FilePathWatcher> library_watcher_; | 108 scoped_ptr<base::FilePathWatcher> library_watcher_; |
105 | 109 |
106 scoped_refptr<SafeITunesLibraryParser> xml_parser_; | 110 scoped_refptr<SafeITunesLibraryParser> xml_parser_; |
107 | 111 |
108 DISALLOW_COPY_AND_ASSIGN(ITunesDataProvider); | 112 DISALLOW_COPY_AND_ASSIGN(ITunesDataProvider); |
109 }; | 113 }; |
110 | 114 |
111 } // namespace itunes | 115 } // namespace itunes |
112 | 116 |
113 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ | 117 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ |
OLD | NEW |