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 <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/inotify.h> | 9 #include <sys/inotify.h> |
10 #include <sys/ioctl.h> | 10 #include <sys/ioctl.h> |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // Switch to the message_loop_ if necessary so we can access |watches_|. | 397 // Switch to the message_loop_ if necessary so we can access |watches_|. |
398 if (!message_loop()->BelongsToCurrentThread()) { | 398 if (!message_loop()->BelongsToCurrentThread()) { |
399 message_loop()->PostTask(FROM_HERE, | 399 message_loop()->PostTask(FROM_HERE, |
400 new FilePathWatcher::CancelTask(this)); | 400 new FilePathWatcher::CancelTask(this)); |
401 } else { | 401 } else { |
402 CancelOnMessageLoopThread(); | 402 CancelOnMessageLoopThread(); |
403 } | 403 } |
404 } | 404 } |
405 | 405 |
406 void FilePathWatcherImpl::CancelOnMessageLoopThread() { | 406 void FilePathWatcherImpl::CancelOnMessageLoopThread() { |
407 if (!is_cancelled()) { | 407 if (!is_cancelled()) |
408 set_cancelled(); | 408 set_cancelled(); |
| 409 |
| 410 if (delegate_) { |
409 MessageLoop::current()->RemoveDestructionObserver(this); | 411 MessageLoop::current()->RemoveDestructionObserver(this); |
| 412 delegate_ = NULL; |
| 413 } |
410 | 414 |
411 for (WatchVector::iterator watch_entry(watches_.begin()); | 415 for (WatchVector::iterator watch_entry(watches_.begin()); |
412 watch_entry != watches_.end(); ++watch_entry) { | 416 watch_entry != watches_.end(); ++watch_entry) { |
413 if (watch_entry->watch_ != InotifyReader::kInvalidWatch) | 417 if (watch_entry->watch_ != InotifyReader::kInvalidWatch) |
414 g_inotify_reader.Get().RemoveWatch(watch_entry->watch_, this); | 418 g_inotify_reader.Get().RemoveWatch(watch_entry->watch_, this); |
415 } | |
416 watches_.clear(); | |
417 delegate_ = NULL; | |
418 target_.clear(); | |
419 } | 419 } |
| 420 watches_.clear(); |
| 421 target_.clear(); |
420 } | 422 } |
421 | 423 |
422 void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() { | 424 void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() { |
423 CancelOnMessageLoopThread(); | 425 CancelOnMessageLoopThread(); |
424 } | 426 } |
425 | 427 |
426 bool FilePathWatcherImpl::UpdateWatches() { | 428 bool FilePathWatcherImpl::UpdateWatches() { |
427 // Ensure this runs on the message_loop_ exclusively in order to avoid | 429 // Ensure this runs on the message_loop_ exclusively in order to avoid |
428 // concurrency issues. | 430 // concurrency issues. |
429 DCHECK(message_loop()->BelongsToCurrentThread()); | 431 DCHECK(message_loop()->BelongsToCurrentThread()); |
(...skipping 23 matching lines...) Expand all Loading... |
453 } | 455 } |
454 | 456 |
455 } // namespace | 457 } // namespace |
456 | 458 |
457 FilePathWatcher::FilePathWatcher() { | 459 FilePathWatcher::FilePathWatcher() { |
458 impl_ = new FilePathWatcherImpl(); | 460 impl_ = new FilePathWatcherImpl(); |
459 } | 461 } |
460 | 462 |
461 } // namespace files | 463 } // namespace files |
462 } // namespace base | 464 } // namespace base |
OLD | NEW |