This source file includes following definitions.
- OnFilePathChangedOnFileThread
- StartFilePathWatchOnFileThread
- StartFilePathWatchOnMediaTaskRunner
#include "chrome/browser/media_galleries/fileapi/file_path_watcher_util.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
#include "content/public/browser/browser_thread.h"
namespace {
void OnFilePathChangedOnFileThread(
const base::FilePathWatcher::Callback& callback,
const base::FilePath& path,
bool error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
MediaFileSystemBackend::MediaTaskRunner()->PostTask(
FROM_HERE, base::Bind(callback, path, error));
}
void StartFilePathWatchOnFileThread(
const base::FilePath& path,
const FileWatchStartedCallback& watch_started_callback,
const base::FilePathWatcher::Callback& path_changed_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
scoped_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher);
bool success = watcher->Watch(
path,
false ,
base::Bind(&OnFilePathChangedOnFileThread, path_changed_callback));
if (!success)
LOG(ERROR) << "Adding watch for " << path.value() << " failed";
MediaFileSystemBackend::MediaTaskRunner()->PostTask(
FROM_HERE, base::Bind(watch_started_callback, base::Passed(&watcher)));
}
}
void StartFilePathWatchOnMediaTaskRunner(
const base::FilePath& path,
const FileWatchStartedCallback& watch_started_callback,
const base::FilePathWatcher::Callback& path_changed_callback) {
DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
content::BrowserThread::PostTask(content::BrowserThread::FILE,
FROM_HERE,
base::Bind(&StartFilePathWatchOnFileThread,
path,
watch_started_callback,
path_changed_callback));
}