| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_FILE_PATH_WATCHER_CALLBACK_H_ |
| 6 #define NET_FILE_PATH_WATCHER_CALLBACK_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/file_path.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/threading/non_thread_safe.h" |
| 17 |
| 18 namespace base { |
| 19 namespace files { |
| 20 class FilePathWatcher; |
| 21 } |
| 22 } |
| 23 |
| 24 namespace net { |
| 25 |
| 26 // Convenience wrapper which holds a FilePathWatcher and a |
| 27 // FilePathWatcher::Delegate which forwards its calls to a Callback. |
| 28 class FilePathWatcherCallback : public base::NonThreadSafe { |
| 29 public: |
| 30 FilePathWatcherCallback(); |
| 31 // When deleted, automatically cancels the FilePathWatcher. |
| 32 virtual ~FilePathWatcherCallback(); |
| 33 |
| 34 // Starts watching the file at |path|. Returns true if Watch succeeds. |
| 35 // If so, the delegate will call callback.Run(true) from OnFilePathChanged and |
| 36 // callback.Run(false) from OnFilePathError. After failure the watch is |
| 37 // cancelled and will have to be restarted. If called again, the previous |
| 38 // watch is cancelled. |
| 39 bool Watch(const FilePath& path, |
| 40 const base::Callback<void(bool succeeded)>& callback); |
| 41 |
| 42 // Cancels the current watch. |
| 43 void Cancel(); |
| 44 |
| 45 private: |
| 46 class WatcherDelegate; |
| 47 |
| 48 void OnFilePathChanged(); |
| 49 void OnFilePathError(); |
| 50 |
| 51 base::Callback<void(bool succeeded)> callback_; |
| 52 scoped_ptr<base::files::FilePathWatcher> watcher_; |
| 53 scoped_refptr<WatcherDelegate> delegate_; |
| 54 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherCallback); |
| 55 }; |
| 56 |
| 57 } // namespace net |
| 58 |
| 59 #endif // NET_FILE_PATH_WATCHER_CALLBACK_H_ |
| 60 |
| OLD | NEW |