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_IAPPS_DATA_PROVIDER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IAPPS_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 "base/memory/weak_ptr.h"
20 // 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
22 // 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.
24 class IAppsDataProvider
{
26 typedef base::Callback
<void(bool)> ReadyCallback
;
28 explicit IAppsDataProvider(const base::FilePath
& library_path
);
29 virtual ~IAppsDataProvider();
31 // Ask the data provider to refresh the data if necessary. |ready_callback|
32 // will be called with the result; false if unable to parse the XML file.
33 virtual void RefreshData(const ReadyCallback
& ready_callback
);
35 // Get the platform path for the library XML file.
36 const base::FilePath
& library_path() const;
41 // Subclass should set this to true if the last parse succeeded.
42 void set_valid(bool valid
);
44 // Signal to subclass to parse the |library_path|. The |ready_callback|
45 // should be called when parsing has finished.
46 virtual void DoParseLibrary(const base::FilePath
& library_path
,
47 const ReadyCallback
& ready_callback
) = 0;
49 // Called when |library_path_| has changed. Virtual for testing.
50 virtual void OnLibraryChanged(const base::FilePath
& path
, bool error
);
53 // Called when the FilePathWatcher for |library_path_| has tried to add an
55 void OnLibraryWatchStarted(scoped_ptr
<base::FilePathWatcher
> library_watcher
);
57 // Path to the library XML file.
58 const base::FilePath library_path_
;
60 // True if the data needs to be refreshed from disk.
63 // True if |library_| contains valid data. False at construction and if
64 // reading or parsing the XML file fails.
67 // A watcher on the library xml file.
68 scoped_ptr
<base::FilePathWatcher
> library_watcher_
;
70 base::WeakPtrFactory
<IAppsDataProvider
> weak_factory_
;
72 DISALLOW_COPY_AND_ASSIGN(IAppsDataProvider
);
77 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_IAPPS_DATA_PROVIDER_H_