| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/win/object_watcher.h" | 15 #include "base/win/object_watcher.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, | 21 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| 22 public base::win::ObjectWatcher::Delegate, | 22 public base::win::ObjectWatcher::Delegate, |
| 23 public MessageLoop::DestructionObserver { | 23 public MessageLoop::DestructionObserver { |
| 24 public: | 24 public: |
| 25 FilePathWatcherImpl() | 25 FilePathWatcherImpl() |
| 26 : handle_(INVALID_HANDLE_VALUE), | 26 : handle_(INVALID_HANDLE_VALUE), |
| 27 recursive_watch_(false) {} | 27 recursive_watch_(false) {} |
| 28 | 28 |
| 29 // FilePathWatcher::PlatformDelegate overrides. | 29 // FilePathWatcher::PlatformDelegate overrides. |
| 30 virtual bool Watch(const FilePath& path, | 30 bool Watch(const FilePath& path, |
| 31 bool recursive, | 31 bool recursive, |
| 32 const FilePathWatcher::Callback& callback) override; | 32 const FilePathWatcher::Callback& callback) override; |
| 33 virtual void Cancel() override; | 33 void Cancel() override; |
| 34 | 34 |
| 35 // Deletion of the FilePathWatcher will call Cancel() to dispose of this | 35 // Deletion of the FilePathWatcher will call Cancel() to dispose of this |
| 36 // object in the right thread. This also observes destruction of the required | 36 // object in the right thread. This also observes destruction of the required |
| 37 // cleanup thread, in case it quits before Cancel() is called. | 37 // cleanup thread, in case it quits before Cancel() is called. |
| 38 virtual void WillDestroyCurrentMessageLoop() override; | 38 void WillDestroyCurrentMessageLoop() override; |
| 39 | 39 |
| 40 // Callback from MessageLoopForIO. | 40 // Callback from MessageLoopForIO. |
| 41 virtual void OnObjectSignaled(HANDLE object) override; | 41 void OnObjectSignaled(HANDLE object) override; |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 virtual ~FilePathWatcherImpl() {} | 44 ~FilePathWatcherImpl() override {} |
| 45 | 45 |
| 46 // Setup a watch handle for directory |dir|. Set |recursive| to true to watch | 46 // Setup a watch handle for directory |dir|. Set |recursive| to true to watch |
| 47 // the directory sub trees. Returns true if no fatal error occurs. |handle| | 47 // the directory sub trees. Returns true if no fatal error occurs. |handle| |
| 48 // will receive the handle value if |dir| is watchable, otherwise | 48 // will receive the handle value if |dir| is watchable, otherwise |
| 49 // INVALID_HANDLE_VALUE. | 49 // INVALID_HANDLE_VALUE. |
| 50 static bool SetupWatchHandle(const FilePath& dir, | 50 static bool SetupWatchHandle(const FilePath& dir, |
| 51 bool recursive, | 51 bool recursive, |
| 52 HANDLE* handle) WARN_UNUSED_RESULT; | 52 HANDLE* handle) WARN_UNUSED_RESULT; |
| 53 | 53 |
| 54 // (Re-)Initialize the watch handle. | 54 // (Re-)Initialize the watch handle. |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 handle_ = INVALID_HANDLE_VALUE; | 292 handle_ = INVALID_HANDLE_VALUE; |
| 293 } | 293 } |
| 294 | 294 |
| 295 } // namespace | 295 } // namespace |
| 296 | 296 |
| 297 FilePathWatcher::FilePathWatcher() { | 297 FilePathWatcher::FilePathWatcher() { |
| 298 impl_ = new FilePathWatcherImpl(); | 298 impl_ = new FilePathWatcherImpl(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace base | 301 } // namespace base |
| OLD | NEW |