1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <map> 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <set> 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string> 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/basictypes.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/callback_forward.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/files/file_path.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/files/file_path_watcher.h" 164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/media_galleries/fileapi/iapps_data_provider.h" 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h" 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace itunes { 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 21ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass TestITunesDataProvider; 22ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// This class is the holder for iTunes parsed data. Given a path to the iTunes 247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// library XML file it will read it in, parse the data, and provide convenient 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// methods to access it. When the file changes, it will update the data. 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// It is not thread safe, but can be run on any thread with IO access. 274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class ITunesDataProvider : public iapps::IAppsDataProvider { 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public: 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::string ArtistName; 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::string AlbumName; 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::string TrackName; 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::map<TrackName, base::FilePath> Album; 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) explicit ITunesDataProvider(const base::FilePath& library_path); 35ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch virtual ~ITunesDataProvider(); 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Get the platform path for the auto-add directory. 383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual const base::FilePath& auto_add_path() const; 393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns true if |artist| exists in the library. 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool KnownArtist(const ArtistName& artist) const; 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns true if |artist| has an album by the name |album| in the library. 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool KnownAlbum(const ArtistName& artist, const AlbumName& album) const; 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Get the track named (filename basename) |track| in |album| by |artist|. 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // If no such track exists, an empty FilePath is returned. 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::FilePath GetTrackLocation(const ArtistName& artist, 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const AlbumName& album, 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const TrackName& track) const; 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Get the set of artists. 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::set<ArtistName> GetArtistNames() const; 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Get the set of albums for |artist|. 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::set<AlbumName> GetAlbumNames(const ArtistName& artist) const; 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Get the tracks for the |album| by |artist|. 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Album GetAlbum(const ArtistName& artist, const AlbumName& album) const; 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private: 62ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch friend class TestITunesDataProvider; 63ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::map<AlbumName, Album> Artist; 65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::map<ArtistName, Artist> Library; 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Parse the library xml file. 684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void DoParseLibrary(const base::FilePath& library_path, 694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const ReadyCallback& ready_callback) OVERRIDE; 707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Called when the utility process finishes parsing the library XML file. 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void OnLibraryParsed(const ReadyCallback& ready_callback, 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool result, 74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const parser::Library& library); 75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Path to the auto-add directory. 773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const base::FilePath auto_add_path_; 783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // The parsed and uniquified data. 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Library library_; 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_refptr<iapps::SafeIAppsLibraryParser> xml_parser_; 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Hides parent class member, but it is private, and there's no way to get a 854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // WeakPtr<Derived> from a WeakPtr<Base> without using SupportsWeakPtr. 863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::WeakPtrFactory<ITunesDataProvider> weak_factory_; 873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ITunesDataProvider); 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace itunes 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_ITUNES_DATA_PROVIDER_H_ 94