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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~TestDelegate() {} |
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 12 matching lines...) Expand all Loading... |
139 } | 139 } |
140 | 140 |
141 class FilePathWatcherTest : public testing::Test { | 141 class FilePathWatcherTest : public testing::Test { |
142 public: | 142 public: |
143 FilePathWatcherTest() | 143 FilePathWatcherTest() |
144 : file_thread_("FilePathWatcherTest") {} | 144 : file_thread_("FilePathWatcherTest") {} |
145 | 145 |
146 virtual ~FilePathWatcherTest() {} | 146 virtual ~FilePathWatcherTest() {} |
147 | 147 |
148 protected: | 148 protected: |
149 virtual void SetUp() OVERRIDE { | 149 void SetUp() override { |
150 // Create a separate file thread in order to test proper thread usage. | 150 // Create a separate file thread in order to test proper thread usage. |
151 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 151 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
152 ASSERT_TRUE(file_thread_.StartWithOptions(options)); | 152 ASSERT_TRUE(file_thread_.StartWithOptions(options)); |
153 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 153 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
154 collector_ = new NotificationCollector(); | 154 collector_ = new NotificationCollector(); |
155 } | 155 } |
156 | 156 |
157 virtual void TearDown() OVERRIDE { | 157 void TearDown() override { RunLoop().RunUntilIdle(); } |
158 RunLoop().RunUntilIdle(); | |
159 } | |
160 | 158 |
161 void DeleteDelegateOnFileThread(TestDelegate* delegate) { | 159 void DeleteDelegateOnFileThread(TestDelegate* delegate) { |
162 file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, delegate); | 160 file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, delegate); |
163 } | 161 } |
164 | 162 |
165 FilePath test_file() { | 163 FilePath test_file() { |
166 return temp_dir_.path().AppendASCII("FilePathWatcherTest"); | 164 return temp_dir_.path().AppendASCII("FilePathWatcherTest"); |
167 } | 165 } |
168 | 166 |
169 FilePath test_link() { | 167 FilePath test_link() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Used by the DeleteDuringNotify test below. | 265 // Used by the DeleteDuringNotify test below. |
268 // Deletes the FilePathWatcher when it's notified. | 266 // Deletes the FilePathWatcher when it's notified. |
269 class Deleter : public TestDelegateBase { | 267 class Deleter : public TestDelegateBase { |
270 public: | 268 public: |
271 Deleter(FilePathWatcher* watcher, MessageLoop* loop) | 269 Deleter(FilePathWatcher* watcher, MessageLoop* loop) |
272 : watcher_(watcher), | 270 : watcher_(watcher), |
273 loop_(loop) { | 271 loop_(loop) { |
274 } | 272 } |
275 virtual ~Deleter() {} | 273 virtual ~Deleter() {} |
276 | 274 |
277 virtual void OnFileChanged(const FilePath&, bool) OVERRIDE { | 275 void OnFileChanged(const FilePath&, bool) override { |
278 watcher_.reset(); | 276 watcher_.reset(); |
279 loop_->PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); | 277 loop_->PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); |
280 } | 278 } |
281 | 279 |
282 FilePathWatcher* watcher() const { return watcher_.get(); } | 280 FilePathWatcher* watcher() const { return watcher_.get(); } |
283 | 281 |
284 private: | 282 private: |
285 scoped_ptr<FilePathWatcher> watcher_; | 283 scoped_ptr<FilePathWatcher> watcher_; |
286 MessageLoop* loop_; | 284 MessageLoop* loop_; |
287 | 285 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 861 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
864 ASSERT_TRUE(WaitForEvents()); | 862 ASSERT_TRUE(WaitForEvents()); |
865 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 863 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
866 DeleteDelegateOnFileThread(delegate.release()); | 864 DeleteDelegateOnFileThread(delegate.release()); |
867 } | 865 } |
868 | 866 |
869 #endif // OS_MACOSX | 867 #endif // OS_MACOSX |
870 } // namespace | 868 } // namespace |
871 | 869 |
872 } // namespace base | 870 } // namespace base |
OLD | NEW |