| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/directory_watcher.h" | 5 #include "base/directory_watcher.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/object_watcher.h" | 9 #include "base/object_watcher.h" |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class DirectoryWatcherImpl : public DirectoryWatcher::PlatformDelegate, | 14 class DirectoryWatcherImpl : public DirectoryWatcher::PlatformDelegate, |
| 15 public base::ObjectWatcher::Delegate { | 15 public base::ObjectWatcher::Delegate { |
| 16 public: | 16 public: |
| 17 DirectoryWatcherImpl() : handle_(INVALID_HANDLE_VALUE) {} | 17 DirectoryWatcherImpl() : handle_(INVALID_HANDLE_VALUE) {} |
| 18 virtual ~DirectoryWatcherImpl(); | 18 virtual ~DirectoryWatcherImpl(); |
| 19 | 19 |
| 20 virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, | 20 virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, |
| 21 bool recursive); | 21 MessageLoop* backend_loop, bool recursive); |
| 22 | 22 |
| 23 // Callback from MessageLoopForIO. | 23 // Callback from MessageLoopForIO. |
| 24 virtual void OnObjectSignaled(HANDLE object); | 24 virtual void OnObjectSignaled(HANDLE object); |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 // Delegate to notify upon changes. | 27 // Delegate to notify upon changes. |
| 28 DirectoryWatcher::Delegate* delegate_; | 28 DirectoryWatcher::Delegate* delegate_; |
| 29 // Path we're watching (passed to delegate). | 29 // Path we're watching (passed to delegate). |
| 30 FilePath path_; | 30 FilePath path_; |
| 31 // Handle for FindFirstChangeNotification. | 31 // Handle for FindFirstChangeNotification. |
| 32 HANDLE handle_; | 32 HANDLE handle_; |
| 33 // ObjectWatcher to watch handle_ for events. | 33 // ObjectWatcher to watch handle_ for events. |
| 34 base::ObjectWatcher watcher_; | 34 base::ObjectWatcher watcher_; |
| 35 | 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(DirectoryWatcherImpl); | 36 DISALLOW_COPY_AND_ASSIGN(DirectoryWatcherImpl); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 DirectoryWatcherImpl::~DirectoryWatcherImpl() { | 39 DirectoryWatcherImpl::~DirectoryWatcherImpl() { |
| 40 if (handle_ != INVALID_HANDLE_VALUE) { | 40 if (handle_ != INVALID_HANDLE_VALUE) { |
| 41 watcher_.StopWatching(); | 41 watcher_.StopWatching(); |
| 42 FindCloseChangeNotification(handle_); | 42 FindCloseChangeNotification(handle_); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool DirectoryWatcherImpl::Watch(const FilePath& path, | 46 bool DirectoryWatcherImpl::Watch(const FilePath& path, |
| 47 DirectoryWatcher::Delegate* delegate, bool recursive) { | 47 DirectoryWatcher::Delegate* delegate, |
| 48 MessageLoop* backend_loop, bool recursive) { |
| 48 DCHECK(path_.value().empty()); // Can only watch one path. | 49 DCHECK(path_.value().empty()); // Can only watch one path. |
| 49 | 50 |
| 50 handle_ = FindFirstChangeNotification( | 51 handle_ = FindFirstChangeNotification( |
| 51 path.value().c_str(), | 52 path.value().c_str(), |
| 52 recursive, | 53 recursive, |
| 53 FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | | 54 FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | |
| 54 FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_DIR_NAME); | 55 FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_DIR_NAME); |
| 55 if (handle_ == INVALID_HANDLE_VALUE) | 56 if (handle_ == INVALID_HANDLE_VALUE) |
| 56 return false; | 57 return false; |
| 57 | 58 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 BOOL ok = FindNextChangeNotification(object); | 74 BOOL ok = FindNextChangeNotification(object); |
| 74 DCHECK(ok); | 75 DCHECK(ok); |
| 75 watcher_.StartWatching(object, this); | 76 watcher_.StartWatching(object, this); |
| 76 } | 77 } |
| 77 | 78 |
| 78 } // namespace | 79 } // namespace |
| 79 | 80 |
| 80 DirectoryWatcher::DirectoryWatcher() { | 81 DirectoryWatcher::DirectoryWatcher() { |
| 81 impl_ = new DirectoryWatcherImpl(); | 82 impl_ = new DirectoryWatcherImpl(); |
| 82 } | 83 } |
| OLD | NEW |