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.h b/base/files/file_path_watcher.h
index 3795c9e..5919994 100644
--- a/base/files/file_path_watcher.h
+++ b/base/files/file_path_watcher.h
@@ -10,6 +10,7 @@
 
 #include "base/base_export.h"
 #include "base/basictypes.h"
+#include "base/callback.h"
 #include "base/file_path.h"
 #include "base/memory/ref_counted.h"
 #include "base/message_loop_proxy.h"
@@ -28,9 +29,16 @@
 // details.
 class BASE_EXPORT FilePathWatcher {
  public:
+  // Callback type for Watch(). |path| points to the file that was updated,
+  // and |error| is true if the platform specific code detected an error. In
+  // that case, the callback won't be invoked again.
+  typedef base::Callback<void(const FilePath& path, bool error)> Callback;
+
   // Declares the callback client code implements to receive notifications. Note
   // that implementations of this interface should not keep a reference to the
   // corresponding FileWatcher object to prevent a reference cycle.
+  //
+  // Deprecated: see comment on Watch() below.
   class Delegate : public base::RefCountedThreadSafe<Delegate> {
    public:
     virtual void OnFilePathChanged(const FilePath& path) = 0;
@@ -104,9 +112,18 @@
   // back for each change. Returns true on success.
   // OnFilePathChanged() will be called on the same thread as Watch() is called,
   // which should have a MessageLoop of TYPE_IO.
+  //
+  // Deprecated: new code should use the callback interface, declared below.
+  // The FilePathWatcher::Delegate interface will be removed once all client
+  // code has been updated. http://crbug.com/130980
   virtual bool Watch(const FilePath& path, Delegate* delegate)
       WARN_UNUSED_RESULT;
 
+  // Invokes |callback| whenever updates to |path| are detected. This should be
+  // called at most once, and from a MessageLoop of TYPE_IO. The callback will
+  // be invoked on the same loop. Returns true on success.
+  bool Watch(const FilePath& path, const Callback& callback);
+
  private:
   scoped_refptr<PlatformDelegate> impl_;