| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // doesn't exist, access is denied (happens if the file is already gone but | 199 // doesn't exist, access is denied (happens if the file is already gone but |
| 200 // there are still handles open), or the target is not a directory, try the | 200 // there are still handles open), or the target is not a directory, try the |
| 201 // immediate parent directory instead. | 201 // immediate parent directory instead. |
| 202 DWORD error_code = GetLastError(); | 202 DWORD error_code = GetLastError(); |
| 203 if (error_code != ERROR_FILE_NOT_FOUND && | 203 if (error_code != ERROR_FILE_NOT_FOUND && |
| 204 error_code != ERROR_PATH_NOT_FOUND && | 204 error_code != ERROR_PATH_NOT_FOUND && |
| 205 error_code != ERROR_ACCESS_DENIED && | 205 error_code != ERROR_ACCESS_DENIED && |
| 206 error_code != ERROR_SHARING_VIOLATION && | 206 error_code != ERROR_SHARING_VIOLATION && |
| 207 error_code != ERROR_DIRECTORY) { | 207 error_code != ERROR_DIRECTORY) { |
| 208 using ::operator<<; // Pick the right operator<< below. | 208 using ::operator<<; // Pick the right operator<< below. |
| 209 PLOG(ERROR) << "FindFirstChangeNotification failed for " | 209 DPLOG(ERROR) << "FindFirstChangeNotification failed for " |
| 210 << dir.value(); | 210 << dir.value(); |
| 211 return false; | 211 return false; |
| 212 } | 212 } |
| 213 | 213 |
| 214 return true; | 214 return true; |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool FilePathWatcherImpl::UpdateWatch() { | 217 bool FilePathWatcherImpl::UpdateWatch() { |
| 218 if (handle_ != INVALID_HANDLE_VALUE) | 218 if (handle_ != INVALID_HANDLE_VALUE) |
| 219 DestroyWatch(); | 219 DestroyWatch(); |
| 220 | 220 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 234 return false; | 234 return false; |
| 235 | 235 |
| 236 // Break if a valid handle is returned. Try the parent directory otherwise. | 236 // Break if a valid handle is returned. Try the parent directory otherwise. |
| 237 if (handle_ != INVALID_HANDLE_VALUE) | 237 if (handle_ != INVALID_HANDLE_VALUE) |
| 238 break; | 238 break; |
| 239 | 239 |
| 240 // Abort if we hit the root directory. | 240 // Abort if we hit the root directory. |
| 241 child_dirs.push_back(watched_path.BaseName()); | 241 child_dirs.push_back(watched_path.BaseName()); |
| 242 FilePath parent(watched_path.DirName()); | 242 FilePath parent(watched_path.DirName()); |
| 243 if (parent == watched_path) { | 243 if (parent == watched_path) { |
| 244 LOG(ERROR) << "Reached the root directory"; | 244 DLOG(ERROR) << "Reached the root directory"; |
| 245 return false; | 245 return false; |
| 246 } | 246 } |
| 247 watched_path = parent; | 247 watched_path = parent; |
| 248 } | 248 } |
| 249 | 249 |
| 250 // At this point, handle_ is valid. However, the bottom-up search that the | 250 // At this point, handle_ is valid. However, the bottom-up search that the |
| 251 // above code performs races against directory creation. So try to walk back | 251 // above code performs races against directory creation. So try to walk back |
| 252 // down and see whether any children appeared in the mean time. | 252 // down and see whether any children appeared in the mean time. |
| 253 while (!child_dirs.empty()) { | 253 while (!child_dirs.empty()) { |
| 254 watched_path = watched_path.Append(child_dirs.back()); | 254 watched_path = watched_path.Append(child_dirs.back()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace | 274 } // namespace |
| 275 | 275 |
| 276 FilePathWatcher::FilePathWatcher() { | 276 FilePathWatcher::FilePathWatcher() { |
| 277 impl_ = new FilePathWatcherImpl(); | 277 impl_ = new FilePathWatcherImpl(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace files | 280 } // namespace files |
| 281 } // namespace base | 281 } // namespace base |
| OLD | NEW |