Added a base::Callback interface to FilePathWatcher.

BUG=130980
TEST=browser_tests:FilePathWatcher* are green

Review URL: https://chromiumcodereview.appspot.com/10519003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140285 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 10e38b62dec4cd25b15439ea33df703d1285fc88
diff --git a/base/files/file_path_watcher.cc b/base/files/file_path_watcher.cc
index 086da1e..dd2b37f 100644
--- a/base/files/file_path_watcher.cc
+++ b/base/files/file_path_watcher.cc
@@ -13,6 +13,33 @@
 namespace base {
 namespace files {
 
+namespace {
+
+// A delegate implementation for the callback interface.
+class FilePathWatcherDelegate : public base::files::FilePathWatcher::Delegate {
+ public:
+  explicit FilePathWatcherDelegate(const FilePathWatcher::Callback& callback)
+      : callback_(callback) {}
+
+  // FilePathWatcher::Delegate implementation.
+  virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
+    callback_.Run(path, false);
+  }
+
+  virtual void OnFilePathError(const FilePath& path) OVERRIDE {
+    callback_.Run(path, true);
+  }
+
+ private:
+  virtual ~FilePathWatcherDelegate() {}
+
+  FilePathWatcher::Callback callback_;
+
+  DISALLOW_COPY_AND_ASSIGN(FilePathWatcherDelegate);
+};
+
+}  // namespace
+
 FilePathWatcher::~FilePathWatcher() {
   impl_->Cancel();
 }
@@ -35,5 +62,9 @@
   DCHECK(is_cancelled());
 }
 
+bool FilePathWatcher::Watch(const FilePath& path, const Callback& callback) {
+  return Watch(path, new FilePathWatcherDelegate(callback));
+}
+
 }  // namespace files
 }  // namespace base