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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <aclapi.h> | 9 #include <aclapi.h> |
10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return write_size == static_cast<int>(content.length()); | 189 return write_size == static_cast<int>(content.length()); |
190 } | 190 } |
191 | 191 |
192 bool SetupWatch(const FilePath& target, | 192 bool SetupWatch(const FilePath& target, |
193 FilePathWatcher* watcher, | 193 FilePathWatcher* watcher, |
194 TestDelegateBase* delegate, | 194 TestDelegateBase* delegate, |
195 bool recursive_watch) WARN_UNUSED_RESULT; | 195 bool recursive_watch) WARN_UNUSED_RESULT; |
196 | 196 |
197 bool WaitForEvents() WARN_UNUSED_RESULT { | 197 bool WaitForEvents() WARN_UNUSED_RESULT { |
198 collector_->Reset(); | 198 collector_->Reset(); |
199 loop_.Run(); | 199 RunLoop().Run(); |
200 return collector_->Success(); | 200 return collector_->Success(); |
201 } | 201 } |
202 | 202 |
203 NotificationCollector* collector() { return collector_.get(); } | 203 NotificationCollector* collector() { return collector_.get(); } |
204 | 204 |
205 MessageLoop loop_; | 205 MessageLoop loop_; |
206 base::Thread file_thread_; | 206 base::Thread file_thread_; |
207 ScopedTempDir temp_dir_; | 207 ScopedTempDir temp_dir_; |
208 scoped_refptr<NotificationCollector> collector_; | 208 scoped_refptr<NotificationCollector> collector_; |
209 | 209 |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 ASSERT_TRUE(base::CreateDirectory(test_dir2)); | 883 ASSERT_TRUE(base::CreateDirectory(test_dir2)); |
884 ASSERT_TRUE(WriteFile(test_file, "content")); | 884 ASSERT_TRUE(WriteFile(test_file, "content")); |
885 | 885 |
886 FilePathWatcher watcher; | 886 FilePathWatcher watcher; |
887 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 887 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
888 ASSERT_TRUE(SetupWatch(test_file, &watcher, delegate.get(), false)); | 888 ASSERT_TRUE(SetupWatch(test_file, &watcher, delegate.get(), false)); |
889 | 889 |
890 // We should not get notified in this case as it hasn't affected our ability | 890 // We should not get notified in this case as it hasn't affected our ability |
891 // to access the file. | 891 // to access the file. |
892 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); | 892 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); |
893 loop_.PostDelayedTask(FROM_HERE, | 893 loop_.task_runner()->PostDelayedTask(FROM_HERE, |
894 MessageLoop::QuitWhenIdleClosure(), | 894 MessageLoop::QuitWhenIdleClosure(), |
895 TestTimeouts::tiny_timeout()); | 895 TestTimeouts::tiny_timeout()); |
896 ASSERT_FALSE(WaitForEvents()); | 896 ASSERT_FALSE(WaitForEvents()); |
897 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); | 897 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); |
898 | 898 |
899 // We should get notified in this case because filepathwatcher can no | 899 // We should get notified in this case because filepathwatcher can no |
900 // longer access the file | 900 // longer access the file |
901 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 901 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
902 ASSERT_TRUE(WaitForEvents()); | 902 ASSERT_TRUE(WaitForEvents()); |
903 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 903 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
904 DeleteDelegateOnFileThread(delegate.release()); | 904 DeleteDelegateOnFileThread(delegate.release()); |
905 } | 905 } |
906 | 906 |
907 #endif // OS_MACOSX | 907 #endif // OS_MACOSX |
908 } // namespace | 908 } // namespace |
909 | 909 |
910 } // namespace base | 910 } // namespace base |
OLD | NEW |