OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/files/file_path_watcher.h" |
| 6 #include "base/files/file_path_watcher_kqueue.h" |
| 7 |
| 8 #if !defined(OS_IOS) |
| 9 #include "base/files/file_path_watcher_fsevents.h" |
| 10 #include "base/mac/mac_util.h" |
| 11 #endif |
| 12 |
| 13 namespace base { |
| 14 |
| 15 namespace { |
| 16 |
| 17 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { |
| 18 public: |
| 19 virtual bool Watch(const FilePath& path, |
| 20 bool recursive, |
| 21 const FilePathWatcher::Callback& callback) OVERRIDE { |
| 22 // Use kqueue for non-recursive watches and FSEvents for recursive ones. |
| 23 DCHECK(!impl_.get()); |
| 24 if (recursive) { |
| 25 // FSEvents isn't available on iOS and is broken on OSX 10.6 and earlier. |
| 26 // See http://crbug.com/54822#c31 |
| 27 #if !defined(OS_IOS) |
| 28 if (mac::IsOSLionOrLater()) |
| 29 impl_ = new FilePathWatcherFSEvents(); |
| 30 #endif // OS_IOS |
| 31 |
| 32 if (!impl_) |
| 33 return false; |
| 34 } else { |
| 35 impl_ = new FilePathWatcherKQueue(); |
| 36 } |
| 37 return impl_->Watch(path, recursive, callback); |
| 38 } |
| 39 |
| 40 virtual void Cancel() OVERRIDE { |
| 41 if (impl_) |
| 42 impl_->Cancel(); |
| 43 } |
| 44 |
| 45 virtual void CancelOnMessageLoopThread() OVERRIDE { |
| 46 if (impl_) |
| 47 impl_->Cancel(); |
| 48 } |
| 49 |
| 50 protected: |
| 51 virtual ~FilePathWatcherImpl() {} |
| 52 |
| 53 scoped_refptr<PlatformDelegate> impl_; |
| 54 }; |
| 55 |
| 56 } // namespace |
| 57 |
| 58 FilePathWatcher::FilePathWatcher() { |
| 59 impl_ = new FilePathWatcherImpl(); |
| 60 } |
| 61 |
| 62 } // namespace base |
OLD | NEW |