Index: chrome/browser/media_galleries/fileapi/data_provider_helper.cc |
diff --git a/chrome/browser/media_galleries/fileapi/data_provider_helper.cc b/chrome/browser/media_galleries/fileapi/data_provider_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a387d1dfa1b048fc521ffca61914e7cafc36f1e6 |
--- /dev/null |
+++ b/chrome/browser/media_galleries/fileapi/data_provider_helper.cc |
@@ -0,0 +1,68 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/media_galleries/fileapi/data_provider_helper.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/format_macros.h" |
vandebo (ex-Chrome)
2013/08/29 23:19:22
What's this for?
tommycli
2013/09/03 20:20:43
Done.
|
+#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 chrome { |
+ |
+namespace { |
+ |
+// Bounces |path| and |error| to |callback| from the FILE thread to the media |
+// task runner. |
+void OnFilePathChangedOnFileThread( |
+ 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)); |
vandebo (ex-Chrome)
2013/08/29 23:19:22
nit: PostTask( on the previous line.
tommycli
2013/09/03 20:20:43
Done.
|
+} |
+ |
+// 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 StartFilePathWatchOnFileThread( |
+ const base::FilePath& path, |
+ bool recursive, |
+ const FileWatchStartedCallback& watch_started_callback, |
+ const base::FilePathWatcher::Callback& path_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 file watcher to a different thread. |
+ scoped_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher); |
+ bool success = watcher->Watch( |
+ path, |
+ recursive, |
+ 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))); |
+} |
+ |
+} // namespace |
+ |
+void StartFilePathWatchOnMediaTaskRunner( |
+ const base::FilePath& path, |
+ bool recursive, |
+ 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, |
+ recursive, |
+ watch_started_callback, |
+ path_changed_callback)); |
+} |
+ |
+} // namespace chrome |