123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #ifndef BASE_FILES_FILE_PATH_WATCHER_H_
- #define BASE_FILES_FILE_PATH_WATCHER_H_
- #include <memory>
- #include "base/base_export.h"
- #include "base/callback.h"
- #include "base/files/file_path.h"
- #include "base/macros.h"
- #include "base/memory/ref_counted.h"
- #include "base/sequence_checker.h"
- #include "base/sequenced_task_runner.h"
- namespace base {
- class BASE_EXPORT FilePathWatcher {
- public:
-
-
-
- using Callback =
- base::RepeatingCallback<void(const FilePath& path, bool error)>;
-
- class PlatformDelegate {
- public:
- PlatformDelegate();
- virtual ~PlatformDelegate();
-
- virtual bool Watch(const FilePath& path,
- bool recursive,
- const Callback& callback) WARN_UNUSED_RESULT = 0;
-
-
- virtual void Cancel() = 0;
- protected:
- friend class FilePathWatcher;
- scoped_refptr<SequencedTaskRunner> task_runner() const {
- return task_runner_;
- }
- void set_task_runner(scoped_refptr<SequencedTaskRunner> runner) {
- task_runner_ = std::move(runner);
- }
-
- void set_cancelled() {
- cancelled_ = true;
- }
- bool is_cancelled() const {
- return cancelled_;
- }
- private:
- scoped_refptr<SequencedTaskRunner> task_runner_;
- bool cancelled_;
- DISALLOW_COPY_AND_ASSIGN(PlatformDelegate);
- };
- FilePathWatcher();
- ~FilePathWatcher();
-
- static bool RecursiveWatchAvailable();
-
-
-
-
-
-
-
-
-
-
- bool Watch(const FilePath& path, bool recursive, const Callback& callback);
- private:
- std::unique_ptr<PlatformDelegate> impl_;
- SequenceChecker sequence_checker_;
- DISALLOW_COPY_AND_ASSIGN(FilePathWatcher);
- };
- }
- #endif
|