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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 static void CancelWatch(const scoped_refptr<PlatformDelegate>& delegate); | 109 static void CancelWatch(const scoped_refptr<PlatformDelegate>& delegate); |
109 | 110 |
110 // Register interest in any changes on |path|. OnPathChanged will be called | 111 // Register interest in any changes on |path|. OnPathChanged will be called |
111 // back for each change. Returns true on success. | 112 // back for each change. Returns true on success. |
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, bool recursive, Delegate* delegate) |
Mattias Nissler (ping if slow)
2012/11/21 09:28:48
Don't add recursive here, this is the deprecated i
kmadhusu
2012/11/22 01:39:41
Done. Modified new code to call the impl_->Watch()
| |
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. |
Mattias Nissler (ping if slow)
2012/11/21 09:28:48
Please put a note saying that recursive watches ar
kmadhusu
2012/11/22 01:39:41
Done.
| |
126 bool Watch(const FilePath& path, bool recursive, const Callback& callback); | |
125 | 127 |
126 private: | 128 private: |
127 scoped_refptr<PlatformDelegate> impl_; | 129 scoped_refptr<PlatformDelegate> impl_; |
128 | 130 |
129 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); | 131 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); |
130 }; | 132 }; |
131 | 133 |
132 } // namespace files | 134 } // namespace files |
133 } // namespace base | 135 } // namespace base |
134 | 136 |
135 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ | 137 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ |
OLD | NEW |