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 <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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // |created| is true if the object appears. | 98 // |created| is true if the object appears. |
99 // |deleted| is true if the object disappears. | 99 // |deleted| is true if the object disappears. |
100 // |is_dir| is true if the object is a directory. | 100 // |is_dir| is true if the object is a directory. |
101 void OnFilePathChanged(InotifyReader::Watch fired_watch, | 101 void OnFilePathChanged(InotifyReader::Watch fired_watch, |
102 const FilePath::StringType& child, | 102 const FilePath::StringType& child, |
103 bool created, | 103 bool created, |
104 bool deleted, | 104 bool deleted, |
105 bool is_dir); | 105 bool is_dir); |
106 | 106 |
107 protected: | 107 protected: |
108 virtual ~FilePathWatcherImpl() {} | 108 ~FilePathWatcherImpl() override {} |
109 | 109 |
110 private: | 110 private: |
111 // Start watching |path| for changes and notify |delegate| on each change. | 111 // Start watching |path| for changes and notify |delegate| on each change. |
112 // Returns true if watch for |path| has been added successfully. | 112 // Returns true if watch for |path| has been added successfully. |
113 virtual bool Watch(const FilePath& path, | 113 bool Watch(const FilePath& path, |
114 bool recursive, | 114 bool recursive, |
115 const FilePathWatcher::Callback& callback) override; | 115 const FilePathWatcher::Callback& callback) override; |
116 | 116 |
117 // Cancel the watch. This unregisters the instance with InotifyReader. | 117 // Cancel the watch. This unregisters the instance with InotifyReader. |
118 virtual void Cancel() override; | 118 void Cancel() override; |
119 | 119 |
120 // Cleans up and stops observing the message_loop() thread. | 120 // Cleans up and stops observing the message_loop() thread. |
121 virtual void CancelOnMessageLoopThread() override; | 121 void CancelOnMessageLoopThread() override; |
122 | 122 |
123 // Deletion of the FilePathWatcher will call Cancel() to dispose of this | 123 // Deletion of the FilePathWatcher will call Cancel() to dispose of this |
124 // object in the right thread. This also observes destruction of the required | 124 // object in the right thread. This also observes destruction of the required |
125 // cleanup thread, in case it quits before Cancel() is called. | 125 // cleanup thread, in case it quits before Cancel() is called. |
126 virtual void WillDestroyCurrentMessageLoop() override; | 126 void WillDestroyCurrentMessageLoop() override; |
127 | 127 |
128 // Inotify watches are installed for all directory components of |target_|. A | 128 // Inotify watches are installed for all directory components of |target_|. A |
129 // WatchEntry instance holds the watch descriptor for a component and the | 129 // WatchEntry instance holds the watch descriptor for a component and the |
130 // subdirectory for that identifies the next component. If a symbolic link | 130 // subdirectory for that identifies the next component. If a symbolic link |
131 // is being watched, the target of the link is also kept. | 131 // is being watched, the target of the link is also kept. |
132 struct WatchEntry { | 132 struct WatchEntry { |
133 explicit WatchEntry(const FilePath::StringType& dirname) | 133 explicit WatchEntry(const FilePath::StringType& dirname) |
134 : watch(InotifyReader::kInvalidWatch), | 134 : watch(InotifyReader::kInvalidWatch), |
135 subdir(dirname) {} | 135 subdir(dirname) {} |
136 | 136 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 return watches_[watches_.size() - 1].subdir.empty(); | 660 return watches_[watches_.size() - 1].subdir.empty(); |
661 } | 661 } |
662 | 662 |
663 } // namespace | 663 } // namespace |
664 | 664 |
665 FilePathWatcher::FilePathWatcher() { | 665 FilePathWatcher::FilePathWatcher() { |
666 impl_ = new FilePathWatcherImpl(); | 666 impl_ = new FilePathWatcherImpl(); |
667 } | 667 } |
668 | 668 |
669 } // namespace base | 669 } // namespace base |
OLD | NEW |