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" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 | 18 |
19 // This class lets you register interest in changes on a FilePath. | 19 // This class lets you register interest in changes on a FilePath. |
20 // The delegate will get called whenever the file or directory referenced by the | 20 // The callback will get called whenever the file or directory referenced by the |
21 // FilePath is changed, including created or deleted. Due to limitations in the | 21 // FilePath is changed, including created or deleted. Due to limitations in the |
22 // underlying OS APIs, FilePathWatcher has slightly different semantics on OS X | 22 // underlying OS APIs, FilePathWatcher has slightly different semantics on OS X |
23 // than on Windows or Linux. FilePathWatcher on Linux and Windows will detect | 23 // than on Windows or Linux. FilePathWatcher on Linux and Windows will detect |
24 // modifications to files in a watched directory. FilePathWatcher on Mac will | 24 // modifications to files in a watched directory. FilePathWatcher on Mac will |
25 // detect the creation and deletion of files in a watched directory, but will | 25 // detect the creation and deletion of files in a watched directory, but will |
26 // not detect modifications to those files. See file_path_watcher_kqueue.cc for | 26 // not detect modifications to those files. See file_path_watcher_kqueue.cc for |
27 // details. | 27 // details. |
28 class BASE_EXPORT FilePathWatcher { | 28 class BASE_EXPORT FilePathWatcher { |
29 public: | 29 public: |
30 // Callback type for Watch(). |path| points to the file that was updated, | 30 // Callback type for Watch(). |path| points to the file that was updated, |
31 // and |error| is true if the platform specific code detected an error. In | 31 // and |error| is true if the platform specific code detected an error. In |
32 // that case, the callback won't be invoked again. | 32 // that case, the callback won't be invoked again. |
33 typedef base::Callback<void(const FilePath& path, bool error)> Callback; | 33 typedef base::Callback<void(const FilePath& path, bool error)> Callback; |
34 | 34 |
35 // Used internally to encapsulate different members on different platforms. | 35 // Used internally to encapsulate different members on different platforms. |
36 // TODO(jhawkins): Move this into its own file. Also fix the confusing naming | |
37 // wrt Delegate vs PlatformDelegate. | |
38 class PlatformDelegate : public base::RefCountedThreadSafe<PlatformDelegate> { | 36 class PlatformDelegate : public base::RefCountedThreadSafe<PlatformDelegate> { |
39 public: | 37 public: |
40 PlatformDelegate(); | 38 PlatformDelegate(); |
41 | 39 |
42 // Start watching for the given |path| and notify |delegate| about changes. | 40 // Start watching for the given |path| and notify |delegate| about changes. |
43 virtual bool Watch(const FilePath& path, | 41 virtual bool Watch(const FilePath& path, |
44 bool recursive, | 42 bool recursive, |
45 const Callback& callback) WARN_UNUSED_RESULT = 0; | 43 const Callback& callback) WARN_UNUSED_RESULT = 0; |
46 | 44 |
47 // Stop watching. This is called from FilePathWatcher's dtor in order to | 45 // Stop watching. This is called from FilePathWatcher's dtor in order to |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 99 |
102 private: | 100 private: |
103 scoped_refptr<PlatformDelegate> impl_; | 101 scoped_refptr<PlatformDelegate> impl_; |
104 | 102 |
105 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); | 103 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); |
106 }; | 104 }; |
107 | 105 |
108 } // namespace base | 106 } // namespace base |
109 | 107 |
110 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ | 108 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ |
OLD | NEW |