| 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 <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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // The kqueue implementation will handle all of the items in the list above | 39 // The kqueue implementation will handle all of the items in the list above |
| 40 // except for detecting modifications to files in a watched directory. It will | 40 // except for detecting modifications to files in a watched directory. It will |
| 41 // detect the creation and deletion of files, just not the modification of | 41 // detect the creation and deletion of files, just not the modification of |
| 42 // files. It does however detect the attribute changes that the FSEvents impl | 42 // files. It does however detect the attribute changes that the FSEvents impl |
| 43 // would miss. | 43 // would miss. |
| 44 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, | 44 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| 45 public MessageLoopForIO::Watcher, | 45 public MessageLoopForIO::Watcher, |
| 46 public MessageLoop::DestructionObserver { | 46 public MessageLoop::DestructionObserver { |
| 47 public: | 47 public: |
| 48 FilePathWatcherImpl() : kqueue_(-1) {} | 48 FilePathWatcherImpl() : kqueue_(-1) {} |
| 49 virtual ~FilePathWatcherImpl() {} | |
| 50 | 49 |
| 51 // MessageLoopForIO::Watcher overrides. | 50 // MessageLoopForIO::Watcher overrides. |
| 52 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 51 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 53 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 52 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 54 | 53 |
| 55 // MessageLoop::DestructionObserver overrides. | 54 // MessageLoop::DestructionObserver overrides. |
| 56 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 55 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 57 | 56 |
| 58 // FilePathWatcher::PlatformDelegate overrides. | 57 // FilePathWatcher::PlatformDelegate overrides. |
| 59 virtual bool Watch(const FilePath& path, | 58 virtual bool Watch(const FilePath& path, |
| 60 FilePathWatcher::Delegate* delegate) OVERRIDE; | 59 FilePathWatcher::Delegate* delegate) OVERRIDE; |
| 61 virtual void Cancel() OVERRIDE; | 60 virtual void Cancel() OVERRIDE; |
| 62 | 61 |
| 62 protected: |
| 63 virtual ~FilePathWatcherImpl() {} |
| 64 |
| 63 private: | 65 private: |
| 64 class EventData { | 66 class EventData { |
| 65 public: | 67 public: |
| 66 EventData(const FilePath& path, const FilePath::StringType& subdir) | 68 EventData(const FilePath& path, const FilePath::StringType& subdir) |
| 67 : path_(path), subdir_(subdir) { } | 69 : path_(path), subdir_(subdir) { } |
| 68 FilePath path_; // Full path to this item. | 70 FilePath path_; // Full path to this item. |
| 69 FilePath::StringType subdir_; // Path to any sub item. | 71 FilePath::StringType subdir_; // Path to any sub item. |
| 70 }; | 72 }; |
| 71 typedef std::vector<struct kevent> EventVector; | 73 typedef std::vector<struct kevent> EventVector; |
| 72 | 74 |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 487 } |
| 486 | 488 |
| 487 } // namespace | 489 } // namespace |
| 488 | 490 |
| 489 FilePathWatcher::FilePathWatcher() { | 491 FilePathWatcher::FilePathWatcher() { |
| 490 impl_ = new FilePathWatcherImpl(); | 492 impl_ = new FilePathWatcherImpl(); |
| 491 } | 493 } |
| 492 | 494 |
| 493 } // namespace files | 495 } // namespace files |
| 494 } // namespace base | 496 } // namespace base |
| OLD | NEW |