| 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 virtual 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 virtual 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 virtual void TearDown() override { |
| 158 RunLoop().RunUntilIdle(); | 158 RunLoop().RunUntilIdle(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void DeleteDelegateOnFileThread(TestDelegate* delegate) { | 161 void DeleteDelegateOnFileThread(TestDelegate* delegate) { |
| 162 file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, delegate); | 162 file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, delegate); |
| 163 } | 163 } |
| 164 | 164 |
| 165 FilePath test_file() { | 165 FilePath test_file() { |
| 166 return temp_dir_.path().AppendASCII("FilePathWatcherTest"); | 166 return temp_dir_.path().AppendASCII("FilePathWatcherTest"); |
| 167 } | 167 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual ~Deleter() {} |
| 276 | 276 |
| 277 virtual void OnFileChanged(const FilePath&, bool) OVERRIDE { | 277 virtual 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 |