Chromium Code Reviews| Index: base/files/file_path_watcher_win.cc |
| diff --git a/base/files/file_path_watcher_win.cc b/base/files/file_path_watcher_win.cc |
| index 37b1e7b3f9feeaeef4d37558c8e01fa799f91dba..d42b86ae934e5c22f5a9f24cc3949ac3ba4b8c8d 100644 |
| --- a/base/files/file_path_watcher_win.cc |
| +++ b/base/files/file_path_watcher_win.cc |
| @@ -26,6 +26,7 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| // FilePathWatcher::PlatformDelegate overrides. |
| virtual bool Watch(const FilePath& path, |
| + bool recursive, |
| FilePathWatcher::Delegate* delegate) OVERRIDE; |
| virtual void Cancel() OVERRIDE; |
| @@ -40,11 +41,13 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| private: |
| virtual ~FilePathWatcherImpl() {} |
| - // Setup a watch handle for directory |dir|. Returns true if no fatal error |
| - // occurs. |handle| will receive the handle value if |dir| is watchable, |
| - // otherwise INVALID_HANDLE_VALUE. |
| - static bool SetupWatchHandle(const FilePath& dir, HANDLE* handle) |
| - WARN_UNUSED_RESULT; |
| + // Setup a watch handle for directory |dir|. Set |recursive| to true to watch |
| + // the directory sub trees. Returns true if no fatal error occurs. |handle| |
| + // will receive the handle value if |dir| is watchable, otherwise |
| + // INVALID_HANDLE_VALUE. |
| + static bool SetupWatchHandle(const FilePath& dir, |
| + bool recursive, |
| + HANDLE* handle) WARN_UNUSED_RESULT; |
| // (Re-)Initialize the watch handle. |
| bool UpdateWatch() WARN_UNUSED_RESULT; |
| @@ -67,6 +70,9 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| // ObjectWatcher to watch handle_ for events. |
| base::win::ObjectWatcher watcher_; |
| + // Set to true to watch the sub trees of the specified directory file path. |
| + bool recursive_watch_; |
|
Lei Zhang
2012/11/21 03:36:49
You need to initialize this.
kmadhusu
2012/11/21 04:13:26
Done.
|
| + |
| // Keep track of the last modified time of the file. We use nulltime |
| // to represent the file not existing. |
| base::Time last_modified_; |
| @@ -79,12 +85,14 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| }; |
| bool FilePathWatcherImpl::Watch(const FilePath& path, |
| + bool recursive, |
| FilePathWatcher::Delegate* delegate) { |
| DCHECK(target_.value().empty()); // Can only watch one path. |
| set_message_loop(base::MessageLoopProxy::current()); |
| delegate_ = delegate; |
| target_ = path; |
| + recursive_watch_ = recursive; |
| MessageLoop::current()->AddDestructionObserver(this); |
| if (!UpdateWatch()) |
| @@ -179,16 +187,17 @@ void FilePathWatcherImpl::OnObjectSignaled(HANDLE object) { |
| // static |
| bool FilePathWatcherImpl::SetupWatchHandle(const FilePath& dir, |
| + bool recursive, |
| HANDLE* handle) { |
| *handle = FindFirstChangeNotification( |
| dir.value().c_str(), |
| - false, // Don't watch subtrees |
| + recursive, |
| FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | |
| FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_DIR_NAME | |
| FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SECURITY); |
| if (*handle != INVALID_HANDLE_VALUE) { |
| // Make sure the handle we got points to an existing directory. It seems |
| - // that windows sometimes hands out watches to direectories that are |
| + // that windows sometimes hands out watches to directories that are |
| // about to go away, but doesn't sent notifications if that happens. |
| if (!file_util::DirectoryExists(dir)) { |
| FindCloseChangeNotification(*handle); |
| @@ -232,7 +241,7 @@ bool FilePathWatcherImpl::UpdateWatch() { |
| std::vector<FilePath> child_dirs; |
| FilePath watched_path(target_); |
| while (true) { |
| - if (!SetupWatchHandle(watched_path, &handle_)) |
| + if (!SetupWatchHandle(watched_path, recursive_watch_, &handle_)) |
| return false; |
| // Break if a valid handle is returned. Try the parent directory otherwise. |
| @@ -256,7 +265,7 @@ bool FilePathWatcherImpl::UpdateWatch() { |
| watched_path = watched_path.Append(child_dirs.back()); |
| child_dirs.pop_back(); |
| HANDLE temp_handle = INVALID_HANDLE_VALUE; |
| - if (!SetupWatchHandle(watched_path, &temp_handle)) |
| + if (!SetupWatchHandle(watched_path, recursive_watch_, &temp_handle)) |
| return false; |
| if (temp_handle == INVALID_HANDLE_VALUE) |
| break; |