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

Unified Diff: base/files/file_path_watcher.h

Issue 10519003: Added a base::Callback interface to FilePathWatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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: base/files/file_path_watcher.h
diff --git a/base/files/file_path_watcher.h b/base/files/file_path_watcher.h
index 31406289fe376d2e4ae9a87dfa2ff20247c02f5d..f25da46720fc3c4766920cba57cad875fbb587b9 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 @@ namespace files {
// 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 @@ class BASE_EXPORT FilePathWatcher {
// 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
Mattias Nissler (ping if slow) 2012/06/04 12:26:39 I'm wondering whether it'd be better if we just al
Joao da Silva 2012/06/04 12:45:42 The Watch() implementations do IO operations, so t
+ // be invoked on the same loop. Returns true on success.
+ bool Watch(const FilePath& path, const Callback& callback);
+
private:
scoped_refptr<PlatformDelegate> impl_;

Powered by Google App Engine
This is Rietveld 408576698