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