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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 (change_on_target_path && file_util::PathExists(target_))) { | 363 (change_on_target_path && file_util::PathExists(target_))) { |
364 delegate_->OnFilePathChanged(target_); | 364 delegate_->OnFilePathChanged(target_); |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 bool FilePathWatcherImpl::Watch(const FilePath& path, | 368 bool FilePathWatcherImpl::Watch(const FilePath& path, |
369 FilePathWatcher::Delegate* delegate) { | 369 FilePathWatcher::Delegate* delegate) { |
370 DCHECK(target_.empty()); | 370 DCHECK(target_.empty()); |
371 DCHECK(MessageLoopForIO::current()); | 371 DCHECK(MessageLoopForIO::current()); |
372 | 372 |
373 set_message_loop(base::MessageLoopProxy::CreateForCurrentThread()); | 373 set_message_loop(base::MessageLoopProxy::current()); |
374 delegate_ = delegate; | 374 delegate_ = delegate; |
375 target_ = path; | 375 target_ = path; |
376 MessageLoop::current()->AddDestructionObserver(this); | 376 MessageLoop::current()->AddDestructionObserver(this); |
377 | 377 |
378 std::vector<FilePath::StringType> comps; | 378 std::vector<FilePath::StringType> comps; |
379 target_.GetComponents(&comps); | 379 target_.GetComponents(&comps); |
380 DCHECK(!comps.empty()); | 380 DCHECK(!comps.empty()); |
381 for (std::vector<FilePath::StringType>::const_iterator comp(++comps.begin()); | 381 for (std::vector<FilePath::StringType>::const_iterator comp(++comps.begin()); |
382 comp != comps.end(); ++comp) { | 382 comp != comps.end(); ++comp) { |
383 watches_.push_back(WatchEntry(InotifyReader::kInvalidWatch, *comp)); | 383 watches_.push_back(WatchEntry(InotifyReader::kInvalidWatch, *comp)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 453 } |
454 | 454 |
455 } // namespace | 455 } // namespace |
456 | 456 |
457 FilePathWatcher::FilePathWatcher() { | 457 FilePathWatcher::FilePathWatcher() { |
458 impl_ = new FilePathWatcherImpl(); | 458 impl_ = new FilePathWatcherImpl(); |
459 } | 459 } |
460 | 460 |
461 } // namespace files | 461 } // namespace files |
462 } // namespace base | 462 } // namespace base |
OLD | NEW |