OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> | 7 #include <errno.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/inotify.h> | 10 #include <sys/inotify.h> |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 248 |
249 InotifyReader::InotifyReader() | 249 InotifyReader::InotifyReader() |
250 : thread_("inotify_reader"), | 250 : thread_("inotify_reader"), |
251 inotify_fd_(inotify_init()), | 251 inotify_fd_(inotify_init()), |
252 valid_(false) { | 252 valid_(false) { |
253 if (inotify_fd_ < 0) | 253 if (inotify_fd_ < 0) |
254 PLOG(ERROR) << "inotify_init() failed"; | 254 PLOG(ERROR) << "inotify_init() failed"; |
255 | 255 |
256 if (inotify_fd_ >= 0 && thread_.Start()) { | 256 if (inotify_fd_ >= 0 && thread_.Start()) { |
257 thread_.task_runner()->PostTask( | 257 thread_.task_runner()->PostTask( |
258 FROM_HERE, | 258 FROM_HERE, BindOnce(&InotifyReaderCallback, this, inotify_fd_)); |
259 Bind(&InotifyReaderCallback, this, inotify_fd_)); | |
260 valid_ = true; | 259 valid_ = true; |
261 } | 260 } |
262 } | 261 } |
263 | 262 |
264 InotifyReader::Watch InotifyReader::AddWatch( | 263 InotifyReader::Watch InotifyReader::AddWatch( |
265 const FilePath& path, FilePathWatcherImpl* watcher) { | 264 const FilePath& path, FilePathWatcherImpl* watcher) { |
266 if (!valid_) | 265 if (!valid_) |
267 return kInvalidWatch; | 266 return kInvalidWatch; |
268 | 267 |
269 AutoLock auto_lock(lock_); | 268 AutoLock auto_lock(lock_); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 const FilePath::StringType& child, | 323 const FilePath::StringType& child, |
325 bool created, | 324 bool created, |
326 bool deleted, | 325 bool deleted, |
327 bool is_dir) { | 326 bool is_dir) { |
328 DCHECK(!task_runner()->RunsTasksOnCurrentThread()); | 327 DCHECK(!task_runner()->RunsTasksOnCurrentThread()); |
329 | 328 |
330 // This method is invoked on the Inotify thread. Switch to task_runner() to | 329 // This method is invoked on the Inotify thread. Switch to task_runner() to |
331 // access |watches_| safely. Use a WeakPtr to prevent the callback from | 330 // access |watches_| safely. Use a WeakPtr to prevent the callback from |
332 // running after |this| is destroyed (i.e. after the watch is cancelled). | 331 // running after |this| is destroyed (i.e. after the watch is cancelled). |
333 task_runner()->PostTask( | 332 task_runner()->PostTask( |
334 FROM_HERE, Bind(&FilePathWatcherImpl::OnFilePathChangedOnOriginSequence, | 333 FROM_HERE, |
335 weak_factory_.GetWeakPtr(), fired_watch, child, created, | 334 BindOnce(&FilePathWatcherImpl::OnFilePathChangedOnOriginSequence, |
336 deleted, is_dir)); | 335 weak_factory_.GetWeakPtr(), fired_watch, child, created, deleted, |
| 336 is_dir)); |
337 } | 337 } |
338 | 338 |
339 void FilePathWatcherImpl::OnFilePathChangedOnOriginSequence( | 339 void FilePathWatcherImpl::OnFilePathChangedOnOriginSequence( |
340 InotifyReader::Watch fired_watch, | 340 InotifyReader::Watch fired_watch, |
341 const FilePath::StringType& child, | 341 const FilePath::StringType& child, |
342 bool created, | 342 bool created, |
343 bool deleted, | 343 bool deleted, |
344 bool is_dir) { | 344 bool is_dir) { |
345 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 345 DCHECK(task_runner()->RunsTasksOnCurrentThread()); |
346 DCHECK(!watches_.empty()); | 346 DCHECK(!watches_.empty()); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 } | 644 } |
645 | 645 |
646 } // namespace | 646 } // namespace |
647 | 647 |
648 FilePathWatcher::FilePathWatcher() { | 648 FilePathWatcher::FilePathWatcher() { |
649 sequence_checker_.DetachFromSequence(); | 649 sequence_checker_.DetachFromSequence(); |
650 impl_ = MakeUnique<FilePathWatcherImpl>(); | 650 impl_ = MakeUnique<FilePathWatcherImpl>(); |
651 } | 651 } |
652 | 652 |
653 } // namespace base | 653 } // namespace base |
OLD | NEW |