Index: chrome/browser/media_galleries/fileapi/itunes_data_provider.cc |
diff --git a/chrome/browser/media_galleries/fileapi/itunes_data_provider.cc b/chrome/browser/media_galleries/fileapi/itunes_data_provider.cc |
index 2a2619855c1bb0caf2e3c18479dd99b5c275c1fa..39067488441bd21bbe00a006c5071ef9411e63b2 100644 |
--- a/chrome/browser/media_galleries/fileapi/itunes_data_provider.cc |
+++ b/chrome/browser/media_galleries/fileapi/itunes_data_provider.cc |
@@ -15,6 +15,7 @@ |
#include "base/stl_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/threading/thread_restrictions.h" |
+#include "chrome/browser/media_galleries/fileapi/data_provider_helper.h" |
#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
#include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
#include "chrome/common/media_galleries/itunes_library.h" |
@@ -28,9 +29,6 @@ namespace itunes { |
namespace { |
-typedef base::Callback<void(scoped_ptr<base::FilePathWatcher> watcher)> |
- FileWatchStartedCallback; |
- |
ITunesDataProvider::Album MakeUniqueTrackNames(const parser::Album& album) { |
// TODO(vandebo): It would be nice to ensure that names returned from here |
// are stable, but aside from persisting every name returned, it's not |
@@ -70,36 +68,6 @@ ITunesDataProvider::Album MakeUniqueTrackNames(const parser::Album& album) { |
return result; |
} |
-// Bounces |path| and |error| to |callback| from the FILE thread to the media |
-// task runner. |
-void OnLibraryChanged(const base::FilePathWatcher::Callback& callback, |
- const base::FilePath& path, |
- bool error) { |
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
- MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
- FROM_HERE, base::Bind(callback, path, error)); |
-} |
- |
-// The watch has to be started on the FILE thread, and the callback called by |
-// the FilePathWatcher also needs to run on the FILE thread. |
-void StartLibraryWatchOnFileThread( |
- const base::FilePath& library_path, |
- const FileWatchStartedCallback& watch_started_callback, |
- const base::FilePathWatcher::Callback& library_changed_callback) { |
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
- // The watcher is created on the FILE thread because it is very difficult |
- // to safely pass an already-created member to a different thread. |
- scoped_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher); |
- bool success = watcher->Watch( |
- library_path, false /*recursive*/, |
- base::Bind(&OnLibraryChanged, library_changed_callback)); |
- if (!success) |
- LOG(ERROR) << "Adding watch for " << library_path.value() << " failed"; |
- MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
- FROM_HERE, |
- base::Bind(watch_started_callback, base::Passed(&watcher))); |
-} |
- |
// |result_path| is set if |locale_string| maps to a localized directory name |
// and it exists in the filesystem. |
bool CheckLocaleStringAutoAddPath( |
@@ -208,15 +176,13 @@ ITunesDataProvider::ITunesDataProvider(const base::FilePath& library_path) |
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
DCHECK(!library_path_.empty()); |
- content::BrowserThread::PostTask( |
- content::BrowserThread::FILE, |
- FROM_HERE, |
- base::Bind(StartLibraryWatchOnFileThread, |
- library_path_, |
- base::Bind(&ITunesDataProvider::OnLibraryWatchStarted, |
- weak_factory_.GetWeakPtr()), |
- base::Bind(&ITunesDataProvider::OnLibraryChanged, |
- weak_factory_.GetWeakPtr()))); |
+ chrome::StartFilePathWatchOnMediaTaskRunner( |
+ library_path_, |
+ false /* recursive */, |
+ base::Bind(&ITunesDataProvider::OnLibraryWatchStarted, |
+ weak_factory_.GetWeakPtr()), |
+ base::Bind(&ITunesDataProvider::OnLibraryChanged, |
+ weak_factory_.GetWeakPtr())); |
} |
ITunesDataProvider::~ITunesDataProvider() {} |