| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <memory> |
| 6 |
| 5 #include "base/files/file_path_watcher.h" | 7 #include "base/files/file_path_watcher.h" |
| 6 #include "base/files/file_path_watcher_kqueue.h" | 8 #include "base/files/file_path_watcher_kqueue.h" |
| 9 #include "base/memory/ptr_util.h" |
| 7 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 8 | 11 |
| 9 #if !defined(OS_IOS) | 12 #if !defined(OS_IOS) |
| 10 #include "base/files/file_path_watcher_fsevents.h" | 13 #include "base/files/file_path_watcher_fsevents.h" |
| 11 #endif | 14 #endif |
| 12 | 15 |
| 13 namespace base { | 16 namespace base { |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { | 20 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { |
| 18 public: | 21 public: |
| 22 ~FilePathWatcherImpl() override = default; |
| 23 |
| 19 bool Watch(const FilePath& path, | 24 bool Watch(const FilePath& path, |
| 20 bool recursive, | 25 bool recursive, |
| 21 const FilePathWatcher::Callback& callback) override { | 26 const FilePathWatcher::Callback& callback) override { |
| 22 // Use kqueue for non-recursive watches and FSEvents for recursive ones. | 27 // Use kqueue for non-recursive watches and FSEvents for recursive ones. |
| 23 DCHECK(!impl_.get()); | 28 DCHECK(!impl_.get()); |
| 24 if (recursive) { | 29 if (recursive) { |
| 25 if (!FilePathWatcher::RecursiveWatchAvailable()) | 30 if (!FilePathWatcher::RecursiveWatchAvailable()) |
| 26 return false; | 31 return false; |
| 27 #if !defined(OS_IOS) | 32 #if !defined(OS_IOS) |
| 28 impl_ = new FilePathWatcherFSEvents(); | 33 impl_ = MakeUnique<FilePathWatcherFSEvents>(); |
| 29 #endif // OS_IOS | 34 #endif // OS_IOS |
| 30 } else { | 35 } else { |
| 31 impl_ = new FilePathWatcherKQueue(); | 36 impl_ = MakeUnique<FilePathWatcherKQueue>(); |
| 32 } | 37 } |
| 33 DCHECK(impl_.get()); | 38 DCHECK(impl_.get()); |
| 34 return impl_->Watch(path, recursive, callback); | 39 return impl_->Watch(path, recursive, callback); |
| 35 } | 40 } |
| 36 | 41 |
| 37 void Cancel() override { | 42 void Cancel() override { |
| 38 if (impl_.get()) | 43 if (impl_.get()) |
| 39 impl_->Cancel(); | 44 impl_->Cancel(); |
| 40 set_cancelled(); | 45 set_cancelled(); |
| 41 } | 46 } |
| 42 | 47 |
| 43 protected: | 48 private: |
| 44 ~FilePathWatcherImpl() override {} | 49 std::unique_ptr<PlatformDelegate> impl_; |
| 45 | |
| 46 scoped_refptr<PlatformDelegate> impl_; | |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 } // namespace | 52 } // namespace |
| 50 | 53 |
| 51 FilePathWatcher::FilePathWatcher() { | 54 FilePathWatcher::FilePathWatcher() { |
| 52 sequence_checker_.DetachFromSequence(); | 55 sequence_checker_.DetachFromSequence(); |
| 53 impl_ = new FilePathWatcherImpl(); | 56 impl_ = MakeUnique<FilePathWatcherImpl>(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 } // namespace base | 59 } // namespace base |
| OLD | NEW |