| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/files/file_path_watcher.h" | 5 #include "base/files/file_path_watcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 public base::win::ObjectWatcher::Delegate, | 23 public base::win::ObjectWatcher::Delegate, |
| 24 public MessageLoop::DestructionObserver { | 24 public MessageLoop::DestructionObserver { |
| 25 public: | 25 public: |
| 26 FilePathWatcherImpl() | 26 FilePathWatcherImpl() |
| 27 : handle_(INVALID_HANDLE_VALUE), | 27 : handle_(INVALID_HANDLE_VALUE), |
| 28 recursive_watch_(false) {} | 28 recursive_watch_(false) {} |
| 29 | 29 |
| 30 // FilePathWatcher::PlatformDelegate overrides. | 30 // FilePathWatcher::PlatformDelegate overrides. |
| 31 virtual bool Watch(const FilePath& path, | 31 virtual bool Watch(const FilePath& path, |
| 32 bool recursive, | 32 bool recursive, |
| 33 const FilePathWatcher::Callback& callback) OVERRIDE; | 33 const FilePathWatcher::Callback& callback) override; |
| 34 virtual void Cancel() OVERRIDE; | 34 virtual void Cancel() override; |
| 35 | 35 |
| 36 // Deletion of the FilePathWatcher will call Cancel() to dispose of this | 36 // Deletion of the FilePathWatcher will call Cancel() to dispose of this |
| 37 // object in the right thread. This also observes destruction of the required | 37 // object in the right thread. This also observes destruction of the required |
| 38 // cleanup thread, in case it quits before Cancel() is called. | 38 // cleanup thread, in case it quits before Cancel() is called. |
| 39 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 39 virtual void WillDestroyCurrentMessageLoop() override; |
| 40 | 40 |
| 41 // Callback from MessageLoopForIO. | 41 // Callback from MessageLoopForIO. |
| 42 virtual void OnObjectSignaled(HANDLE object); | 42 virtual void OnObjectSignaled(HANDLE object); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 virtual ~FilePathWatcherImpl() {} | 45 virtual ~FilePathWatcherImpl() {} |
| 46 | 46 |
| 47 // Setup a watch handle for directory |dir|. Set |recursive| to true to watch | 47 // Setup a watch handle for directory |dir|. Set |recursive| to true to watch |
| 48 // the directory sub trees. Returns true if no fatal error occurs. |handle| | 48 // the directory sub trees. Returns true if no fatal error occurs. |handle| |
| 49 // will receive the handle value if |dir| is watchable, otherwise | 49 // will receive the handle value if |dir| is watchable, otherwise |
| 50 // INVALID_HANDLE_VALUE. | 50 // INVALID_HANDLE_VALUE. |
| 51 static bool SetupWatchHandle(const FilePath& dir, | 51 static bool SetupWatchHandle(const FilePath& dir, |
| 52 bool recursive, | 52 bool recursive, |
| 53 HANDLE* handle) WARN_UNUSED_RESULT; | 53 HANDLE* handle) WARN_UNUSED_RESULT; |
| 54 | 54 |
| 55 // (Re-)Initialize the watch handle. | 55 // (Re-)Initialize the watch handle. |
| 56 bool UpdateWatch() WARN_UNUSED_RESULT; | 56 bool UpdateWatch() WARN_UNUSED_RESULT; |
| 57 | 57 |
| 58 // Destroy the watch handle. | 58 // Destroy the watch handle. |
| 59 void DestroyWatch(); | 59 void DestroyWatch(); |
| 60 | 60 |
| 61 // Cleans up and stops observing the |message_loop_| thread. | 61 // Cleans up and stops observing the |message_loop_| thread. |
| 62 void CancelOnMessageLoopThread() OVERRIDE; | 62 void CancelOnMessageLoopThread() override; |
| 63 | 63 |
| 64 // Callback to notify upon changes. | 64 // Callback to notify upon changes. |
| 65 FilePathWatcher::Callback callback_; | 65 FilePathWatcher::Callback callback_; |
| 66 | 66 |
| 67 // Path we're supposed to watch (passed to callback). | 67 // Path we're supposed to watch (passed to callback). |
| 68 FilePath target_; | 68 FilePath target_; |
| 69 | 69 |
| 70 // Handle for FindFirstChangeNotification. | 70 // Handle for FindFirstChangeNotification. |
| 71 HANDLE handle_; | 71 HANDLE handle_; |
| 72 | 72 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 handle_ = INVALID_HANDLE_VALUE; | 298 handle_ = INVALID_HANDLE_VALUE; |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace | 301 } // namespace |
| 302 | 302 |
| 303 FilePathWatcher::FilePathWatcher() { | 303 FilePathWatcher::FilePathWatcher() { |
| 304 impl_ = new FilePathWatcherImpl(); | 304 impl_ = new FilePathWatcherImpl(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace base | 307 } // namespace base |
| OLD | NEW |