| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/event.h> | 8 #include <sys/event.h> |
| 9 #include <sys/param.h> | 9 #include <sys/param.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/logging.h" |
| 15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 16 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
| 17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 18 | 19 |
| 19 // On some platforms these are not defined. | 20 // On some platforms these are not defined. |
| 20 #if !defined(EV_RECEIPT) | 21 #if !defined(EV_RECEIPT) |
| 21 #define EV_RECEIPT 0 | 22 #define EV_RECEIPT 0 |
| 22 #endif | 23 #endif |
| 23 #if !defined(O_EVTONLY) | 24 #if !defined(O_EVTONLY) |
| 24 #define O_EVTONLY O_RDONLY | 25 #define O_EVTONLY O_RDONLY |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 58 |
| 58 // MessageLoopForIO::Watcher overrides. | 59 // MessageLoopForIO::Watcher overrides. |
| 59 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 60 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 60 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 61 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 61 | 62 |
| 62 // MessageLoop::DestructionObserver overrides. | 63 // MessageLoop::DestructionObserver overrides. |
| 63 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 64 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 64 | 65 |
| 65 // FilePathWatcher::PlatformDelegate overrides. | 66 // FilePathWatcher::PlatformDelegate overrides. |
| 66 virtual bool Watch(const FilePath& path, | 67 virtual bool Watch(const FilePath& path, |
| 68 bool recursive, |
| 67 FilePathWatcher::Delegate* delegate) OVERRIDE; | 69 FilePathWatcher::Delegate* delegate) OVERRIDE; |
| 68 virtual void Cancel() OVERRIDE; | 70 virtual void Cancel() OVERRIDE; |
| 69 | 71 |
| 70 protected: | 72 protected: |
| 71 virtual ~FilePathWatcherImpl() {} | 73 virtual ~FilePathWatcherImpl() {} |
| 72 | 74 |
| 73 private: | 75 private: |
| 74 class EventData { | 76 class EventData { |
| 75 public: | 77 public: |
| 76 EventData(const FilePath& path, const FilePath::StringType& subdir) | 78 EventData(const FilePath& path, const FilePath::StringType& subdir) |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 423 |
| 422 void FilePathWatcherImpl::OnFileCanWriteWithoutBlocking(int fd) { | 424 void FilePathWatcherImpl::OnFileCanWriteWithoutBlocking(int fd) { |
| 423 NOTREACHED(); | 425 NOTREACHED(); |
| 424 } | 426 } |
| 425 | 427 |
| 426 void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() { | 428 void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() { |
| 427 CancelOnMessageLoopThread(); | 429 CancelOnMessageLoopThread(); |
| 428 } | 430 } |
| 429 | 431 |
| 430 bool FilePathWatcherImpl::Watch(const FilePath& path, | 432 bool FilePathWatcherImpl::Watch(const FilePath& path, |
| 433 bool recursive, |
| 431 FilePathWatcher::Delegate* delegate) { | 434 FilePathWatcher::Delegate* delegate) { |
| 432 DCHECK(MessageLoopForIO::current()); | 435 DCHECK(MessageLoopForIO::current()); |
| 433 DCHECK(target_.value().empty()); // Can only watch one path. | 436 DCHECK(target_.value().empty()); // Can only watch one path. |
| 434 DCHECK(delegate); | 437 DCHECK(delegate); |
| 435 DCHECK_EQ(kqueue_, -1); | 438 DCHECK_EQ(kqueue_, -1); |
| 436 | 439 |
| 440 if (recursive) { |
| 441 // Recursive watch is not supported on this platform. |
| 442 NOTIMPLEMENTED(); |
| 443 return false; |
| 444 } |
| 445 |
| 437 delegate_ = delegate; | 446 delegate_ = delegate; |
| 438 target_ = path; | 447 target_ = path; |
| 439 | 448 |
| 440 MessageLoop::current()->AddDestructionObserver(this); | 449 MessageLoop::current()->AddDestructionObserver(this); |
| 441 io_message_loop_ = base::MessageLoopProxy::current(); | 450 io_message_loop_ = base::MessageLoopProxy::current(); |
| 442 | 451 |
| 443 kqueue_ = kqueue(); | 452 kqueue_ = kqueue(); |
| 444 if (kqueue_ == -1) { | 453 if (kqueue_ == -1) { |
| 445 DPLOG(ERROR) << "kqueue"; | 454 DPLOG(ERROR) << "kqueue"; |
| 446 return false; | 455 return false; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 504 } |
| 496 | 505 |
| 497 } // namespace | 506 } // namespace |
| 498 | 507 |
| 499 FilePathWatcher::FilePathWatcher() { | 508 FilePathWatcher::FilePathWatcher() { |
| 500 impl_ = new FilePathWatcherImpl(); | 509 impl_ = new FilePathWatcherImpl(); |
| 501 } | 510 } |
| 502 | 511 |
| 503 } // namespace files | 512 } // namespace files |
| 504 } // namespace base | 513 } // namespace base |
| OLD | NEW |