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_fsevents.h" |
| 7 #include "base/files/file_path_watcher_kqueue.h" |
| 8 #include "base/mac/mac_util.h" |
| 9 |
| 10 namespace base { |
| 11 |
| 12 namespace { |
| 13 |
| 14 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { |
| 15 public: |
| 16 virtual bool Watch(const FilePath& path, |
| 17 bool recursive, |
| 18 const FilePathWatcher::Callback& callback) OVERRIDE { |
| 19 DCHECK(!impl_.get()); |
| 20 if (recursive) { |
| 21 // FSEvents is broken on 10.6 and earlier. See http://crbug.com/54822#c31 |
| 22 if (mac::IsOSSnowLeopard()) |
| 23 return false; |
| 24 |
| 25 impl_ = new FilePathWatcherFSEvents(); |
| 26 } else { |
| 27 impl_ = new FilePathWatcherKQueue(); |
| 28 } |
| 29 return impl_->Watch(path, recursive, callback); |
| 30 } |
| 31 |
| 32 virtual void Cancel() OVERRIDE { |
| 33 if (impl_) |
| 34 impl_->Cancel(); |
| 35 } |
| 36 |
| 37 virtual void CancelOnMessageLoopThread() OVERRIDE { |
| 38 if (impl_) |
| 39 impl_->Cancel(); |
| 40 } |
| 41 |
| 42 protected: |
| 43 virtual ~FilePathWatcherImpl() {} |
| 44 |
| 45 scoped_refptr<PlatformDelegate> impl_; |
| 46 }; |
| 47 |
| 48 } // namespace |
| 49 |
| 50 FilePathWatcher::FilePathWatcher() { |
| 51 impl_ = new FilePathWatcherImpl(); |
| 52 } |
| 53 |
| 54 } // namespace base |
OLD | NEW |