| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 File::Info file_info; | 100 File::Info file_info; |
| 101 if (GetFileInfo(target_, &file_info)) { | 101 if (GetFileInfo(target_, &file_info)) { |
| 102 last_modified_ = file_info.last_modified; | 102 last_modified_ = file_info.last_modified; |
| 103 first_notification_ = Time::Now(); | 103 first_notification_ = Time::Now(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (!UpdateWatch()) | 106 if (!UpdateWatch()) |
| 107 return false; | 107 return false; |
| 108 | 108 |
| 109 watcher_.StartWatching(handle_, this); | 109 watcher_.StartWatching(handle_, this, false); |
| 110 | 110 |
| 111 return true; | 111 return true; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void FilePathWatcherImpl::Cancel() { | 114 void FilePathWatcherImpl::Cancel() { |
| 115 if (callback_.is_null()) { | 115 if (callback_.is_null()) { |
| 116 // Watch was never called, or the |task_runner_| has already quit. | 116 // Watch was never called, or the |task_runner_| has already quit. |
| 117 set_cancelled(); | 117 set_cancelled(); |
| 118 return; | 118 return; |
| 119 } | 119 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 first_notification_ = Time(); | 191 first_notification_ = Time(); |
| 192 } | 192 } |
| 193 callback_.Run(target_, false); | 193 callback_.Run(target_, false); |
| 194 } else if (!file_exists && !last_modified_.is_null()) { | 194 } else if (!file_exists && !last_modified_.is_null()) { |
| 195 last_modified_ = Time(); | 195 last_modified_ = Time(); |
| 196 callback_.Run(target_, false); | 196 callback_.Run(target_, false); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // The watch may have been cancelled by the callback. | 199 // The watch may have been cancelled by the callback. |
| 200 if (handle_ != INVALID_HANDLE_VALUE) | 200 if (handle_ != INVALID_HANDLE_VALUE) |
| 201 watcher_.StartWatching(handle_, this); | 201 watcher_.StartWatching(handle_, this, false); |
| 202 } | 202 } |
| 203 | 203 |
| 204 // static | 204 // static |
| 205 bool FilePathWatcherImpl::SetupWatchHandle(const FilePath& dir, | 205 bool FilePathWatcherImpl::SetupWatchHandle(const FilePath& dir, |
| 206 bool recursive, | 206 bool recursive, |
| 207 HANDLE* handle) { | 207 HANDLE* handle) { |
| 208 *handle = FindFirstChangeNotification( | 208 *handle = FindFirstChangeNotification( |
| 209 dir.value().c_str(), | 209 dir.value().c_str(), |
| 210 recursive, | 210 recursive, |
| 211 FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | | 211 FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 handle_ = INVALID_HANDLE_VALUE; | 291 handle_ = INVALID_HANDLE_VALUE; |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace | 294 } // namespace |
| 295 | 295 |
| 296 FilePathWatcher::FilePathWatcher() { | 296 FilePathWatcher::FilePathWatcher() { |
| 297 impl_ = new FilePathWatcherImpl(); | 297 impl_ = new FilePathWatcherImpl(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace base | 300 } // namespace base |
| OLD | NEW |