Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1245)

Unified Diff: chrome/browser/media_galleries/fileapi/itunes_data_provider.cc

Issue 23499006: Media Galleries API Picasa: Add file watch to invalidate database data on disk write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f246454e673d2b5bcfde337183b9247c6f29b87e..b23ed221ee5b3cc21c89eea0e1c8171b7c92ba86 100644
--- a/chrome/browser/media_galleries/fileapi/itunes_data_provider.cc
+++ b/chrome/browser/media_galleries/fileapi/itunes_data_provider.cc
@@ -16,6 +16,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
+#include "chrome/browser/media_galleries/fileapi/file_path_watcher_util.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"
@@ -29,9 +30,6 @@ namespace itunes {
namespace {
-typedef base::Callback<void(scoped_ptr<base::FilePathWatcher> watcher)>
- FileWatchStartedCallback;
-
// Colon and slash are not allowed in filenames, replace them with underscore.
std::string EscapeBadCharacters(const std::string& input) {
std::string result;
@@ -82,36 +80,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(
@@ -220,15 +188,12 @@ 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_,
+ base::Bind(&ITunesDataProvider::OnLibraryWatchStarted,
+ weak_factory_.GetWeakPtr()),
+ base::Bind(&ITunesDataProvider::OnLibraryChanged,
+ weak_factory_.GetWeakPtr()));
}
ITunesDataProvider::~ITunesDataProvider() {}

Powered by Google App Engine
This is Rietveld 408576698