OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This module provides a way to monitor a file or directory for changes. | 5 // This module provides a way to monitor a file or directory for changes. |
6 | 6 |
7 #ifndef BASE_FILES_FILE_PATH_WATCHER_H_ | 7 #ifndef BASE_FILES_FILE_PATH_WATCHER_H_ |
8 #define BASE_FILES_FILE_PATH_WATCHER_H_ | 8 #define BASE_FILES_FILE_PATH_WATCHER_H_ |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 // Used internally to encapsulate different members on different platforms. | 53 // Used internally to encapsulate different members on different platforms. |
54 // TODO(jhawkins): Move this into its own file. Also fix the confusing naming | 54 // TODO(jhawkins): Move this into its own file. Also fix the confusing naming |
55 // wrt Delegate vs PlatformDelegate. | 55 // wrt Delegate vs PlatformDelegate. |
56 class PlatformDelegate : public base::RefCountedThreadSafe<PlatformDelegate> { | 56 class PlatformDelegate : public base::RefCountedThreadSafe<PlatformDelegate> { |
57 public: | 57 public: |
58 PlatformDelegate(); | 58 PlatformDelegate(); |
59 | 59 |
60 // Start watching for the given |path| and notify |delegate| about changes. | 60 // Start watching for the given |path| and notify |delegate| about changes. |
61 virtual bool Watch(const FilePath& path, | 61 virtual bool Watch(const FilePath& path, |
62 bool recursive, | |
62 Delegate* delegate) WARN_UNUSED_RESULT = 0; | 63 Delegate* delegate) WARN_UNUSED_RESULT = 0; |
63 | 64 |
64 // Stop watching. This is called from FilePathWatcher's dtor in order to | 65 // Stop watching. This is called from FilePathWatcher's dtor in order to |
65 // allow to shut down properly while the object is still alive. | 66 // allow to shut down properly while the object is still alive. |
66 // It can be called from any thread. | 67 // It can be called from any thread. |
67 virtual void Cancel() = 0; | 68 virtual void Cancel() = 0; |
68 | 69 |
69 protected: | 70 protected: |
70 friend class base::RefCountedThreadSafe<PlatformDelegate>; | 71 friend class base::RefCountedThreadSafe<PlatformDelegate>; |
71 friend class FilePathWatcher; | 72 friend class FilePathWatcher; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // OnFilePathChanged() will be called on the same thread as Watch() is called, | 113 // OnFilePathChanged() will be called on the same thread as Watch() is called, |
113 // which should have a MessageLoop of TYPE_IO. | 114 // which should have a MessageLoop of TYPE_IO. |
114 // | 115 // |
115 // Deprecated: new code should use the callback interface, declared below. | 116 // Deprecated: new code should use the callback interface, declared below. |
116 // The FilePathWatcher::Delegate interface will be removed once all client | 117 // The FilePathWatcher::Delegate interface will be removed once all client |
117 // code has been updated. http://crbug.com/130980 | 118 // code has been updated. http://crbug.com/130980 |
118 virtual bool Watch(const FilePath& path, Delegate* delegate) | 119 virtual bool Watch(const FilePath& path, Delegate* delegate) |
119 WARN_UNUSED_RESULT; | 120 WARN_UNUSED_RESULT; |
120 | 121 |
121 // Invokes |callback| whenever updates to |path| are detected. This should be | 122 // Invokes |callback| whenever updates to |path| are detected. This should be |
122 // called at most once, and from a MessageLoop of TYPE_IO. The callback will | 123 // called at most once, and from a MessageLoop of TYPE_IO. Set |recursive| to |
123 // be invoked on the same loop. Returns true on success. | 124 // true, to watch |path| and its children. The callback will be invoked on |
124 bool Watch(const FilePath& path, const Callback& callback); | 125 // the same loop. Returns true on success. |
126 // | |
127 // NOTE: Recursive watch is not supported on all platforms. Watch() will | |
Lei Zhang
2012/12/03 21:44:39
Does it work on network shared on Windows? This ma
kmadhusu
2012/12/03 22:54:57
On Windows, notifications may not be returned when
Lei Zhang
2012/12/03 23:16:20
No, we should go into such details here, but I'm c
kmadhusu
2012/12/04 00:06:36
Rephrased the comment. Let me know your comments.
| |
128 // return false on those platforms that don't support it. | |
129 bool Watch(const FilePath& path, bool recursive, const Callback& callback); | |
125 | 130 |
126 private: | 131 private: |
127 scoped_refptr<PlatformDelegate> impl_; | 132 scoped_refptr<PlatformDelegate> impl_; |
128 | 133 |
129 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); | 134 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); |
130 }; | 135 }; |
131 | 136 |
132 } // namespace files | 137 } // namespace files |
133 } // namespace base | 138 } // namespace base |
134 | 139 |
135 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ | 140 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ |
OLD | NEW |