| 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 #ifndef NET_FILE_PATH_WATCHER_CALLBACK_H_ | 5 #ifndef NET_FILE_PATH_WATCHER_CALLBACK_H_ |
| 6 #define NET_FILE_PATH_WATCHER_WRAPPER_H_ | 6 #define NET_FILE_PATH_WATCHER_WRAPPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Convenience wrapper which holds a FilePathWatcher and a | 27 // Convenience wrapper which holds a FilePathWatcher and a |
| 28 // FilePathWatcher::Delegate which forwards its calls to a Callback. | 28 // FilePathWatcher::Delegate which forwards its calls to a Callback. |
| 29 class NET_EXPORT FilePathWatcherWrapper | 29 class NET_EXPORT FilePathWatcherWrapper |
| 30 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 30 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 31 public: | 31 public: |
| 32 FilePathWatcherWrapper(); | 32 FilePathWatcherWrapper(); |
| 33 // When deleted, automatically cancels the FilePathWatcher. | 33 // When deleted, automatically cancels the FilePathWatcher. |
| 34 virtual ~FilePathWatcherWrapper(); | 34 virtual ~FilePathWatcherWrapper(); |
| 35 | 35 |
| 36 // Starts watching the file at |path|. Returns true if Watch succeeds. | 36 // Starts watching the file at |path|. Returns true if Watch succeeds. |
| 37 // If so, the delegate will call callback.Run(true) from OnFilePathChanged and | 37 // If so, |callback| will be called with true on change and false on error. |
| 38 // callback.Run(false) from OnFilePathError. After failure the watch is | 38 // After failure the watch is cancelled and will have to be restarted. |
| 39 // cancelled and will have to be restarted. If called again, the previous | |
| 40 // watch is cancelled. | |
| 41 bool Watch(const FilePath& path, | 39 bool Watch(const FilePath& path, |
| 42 const base::Callback<void(bool succeeded)>& callback); | 40 const base::Callback<void(bool succeeded)>& callback); |
| 43 | 41 |
| 44 bool IsWatching() const; | 42 bool IsWatching() const; |
| 45 | 43 |
| 46 // Cancels the current watch. | 44 // Cancels the current watch. |
| 47 void Cancel(); | 45 void Cancel(); |
| 48 | 46 |
| 49 protected: | 47 protected: |
| 50 // Creates a FilePathWatcher. Override to provide a different implementation. | 48 // Creates a FilePathWatcher. Override to provide a different implementation. |
| 51 virtual scoped_ptr<base::files::FilePathWatcher> CreateFilePathWatcher(); | 49 virtual scoped_ptr<base::files::FilePathWatcher> CreateFilePathWatcher(); |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 class WatcherDelegate; | 52 class WatcherDelegate; |
| 55 | 53 |
| 56 void OnFilePathChanged(); | 54 void OnFilePathChanged(); |
| 57 void OnFilePathError(); | 55 void OnFilePathError(); |
| 58 | 56 |
| 59 base::Callback<void(bool succeeded)> callback_; | 57 base::Callback<void(bool succeeded)> callback_; |
| 60 scoped_ptr<base::files::FilePathWatcher> watcher_; | 58 scoped_ptr<base::files::FilePathWatcher> watcher_; |
| 61 scoped_refptr<WatcherDelegate> delegate_; | 59 scoped_refptr<WatcherDelegate> delegate_; |
| 62 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherWrapper); | 60 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherWrapper); |
| 63 }; | 61 }; |
| 64 | 62 |
| 65 } // namespace net | 63 } // namespace net |
| 66 | 64 |
| 67 #endif // NET_FILE_PATH_WATCHER_CALLBACK_H_ | 65 #endif // NET_FILE_PATH_WATCHER_CALLBACK_H_ |
| 68 | 66 |
| OLD | NEW |