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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // thread-safe for setting expectations. Thus the test code cannot safely | 104 // thread-safe for setting expectations. Thus the test code cannot safely |
105 // reset expectations while the file watcher is running. | 105 // reset expectations while the file watcher is running. |
106 // Instead, TestDelegate gets the notifications from FilePathWatcher and uses | 106 // Instead, TestDelegate gets the notifications from FilePathWatcher and uses |
107 // NotificationCollector to aggregate the results. | 107 // NotificationCollector to aggregate the results. |
108 class TestDelegate : public TestDelegateBase { | 108 class TestDelegate : public TestDelegateBase { |
109 public: | 109 public: |
110 explicit TestDelegate(NotificationCollector* collector) | 110 explicit TestDelegate(NotificationCollector* collector) |
111 : collector_(collector) { | 111 : collector_(collector) { |
112 collector_->Register(this); | 112 collector_->Register(this); |
113 } | 113 } |
114 virtual ~TestDelegate() {} | 114 ~TestDelegate() override {} |
115 | 115 |
116 virtual void OnFileChanged(const FilePath& path, bool error) override { | 116 void OnFileChanged(const FilePath& path, bool error) override { |
117 if (error) | 117 if (error) |
118 ADD_FAILURE() << "Error " << path.value(); | 118 ADD_FAILURE() << "Error " << path.value(); |
119 else | 119 else |
120 collector_->OnChange(this); | 120 collector_->OnChange(this); |
121 } | 121 } |
122 | 122 |
123 private: | 123 private: |
124 scoped_refptr<NotificationCollector> collector_; | 124 scoped_refptr<NotificationCollector> collector_; |
125 | 125 |
126 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 126 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 265 } |
266 | 266 |
267 // Used by the DeleteDuringNotify test below. | 267 // Used by the DeleteDuringNotify test below. |
268 // Deletes the FilePathWatcher when it's notified. | 268 // Deletes the FilePathWatcher when it's notified. |
269 class Deleter : public TestDelegateBase { | 269 class Deleter : public TestDelegateBase { |
270 public: | 270 public: |
271 Deleter(FilePathWatcher* watcher, MessageLoop* loop) | 271 Deleter(FilePathWatcher* watcher, MessageLoop* loop) |
272 : watcher_(watcher), | 272 : watcher_(watcher), |
273 loop_(loop) { | 273 loop_(loop) { |
274 } | 274 } |
275 virtual ~Deleter() {} | 275 ~Deleter() override {} |
276 | 276 |
277 virtual void OnFileChanged(const FilePath&, bool) override { | 277 void OnFileChanged(const FilePath&, bool) override { |
278 watcher_.reset(); | 278 watcher_.reset(); |
279 loop_->PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); | 279 loop_->PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); |
280 } | 280 } |
281 | 281 |
282 FilePathWatcher* watcher() const { return watcher_.get(); } | 282 FilePathWatcher* watcher() const { return watcher_.get(); } |
283 | 283 |
284 private: | 284 private: |
285 scoped_ptr<FilePathWatcher> watcher_; | 285 scoped_ptr<FilePathWatcher> watcher_; |
286 MessageLoop* loop_; | 286 MessageLoop* loop_; |
287 | 287 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 863 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
864 ASSERT_TRUE(WaitForEvents()); | 864 ASSERT_TRUE(WaitForEvents()); |
865 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 865 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
866 DeleteDelegateOnFileThread(delegate.release()); | 866 DeleteDelegateOnFileThread(delegate.release()); |
867 } | 867 } |
868 | 868 |
869 #endif // OS_MACOSX | 869 #endif // OS_MACOSX |
870 } // namespace | 870 } // namespace |
871 | 871 |
872 } // namespace base | 872 } // namespace base |
OLD | NEW |