1 --- base/files/file_path_watcher_bsd.cc.orig 2022-02-07 13:39:41 UTC 2 +++ base/files/file_path_watcher_bsd.cc 3 @@ -0,0 +1,54 @@ 4 +// Copyright 2021 The Chromium Authors. All rights reserved. 5 +// Use of this source code is governed by a BSD-style license that can be 6 +// found in the LICENSE file. 7 + 8 +#include <memory> 9 + 10 +#include "base/files/file_path_watcher.h" 11 +#include "base/files/file_path_watcher_kqueue.h" 12 +#include "base/memory/ptr_util.h" 13 +#include "build/build_config.h" 14 + 15 +namespace base { 16 + 17 +namespace { 18 + 19 +class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { 20 + public: 21 + FilePathWatcherImpl() = default; 22 + FilePathWatcherImpl(const FilePathWatcherImpl&) = delete; 23 + FilePathWatcherImpl& operator=(const FilePathWatcherImpl&) = delete; 24 + ~FilePathWatcherImpl() override = default; 25 + 26 + bool Watch(const FilePath& path, 27 + Type type, 28 + const FilePathWatcher::Callback& callback) override { 29 + DCHECK(!impl_.get()); 30 + if (type == Type::kRecursive) { 31 + if (!FilePathWatcher::RecursiveWatchAvailable()) 32 + return false; 33 + } else { 34 + impl_ = std::make_unique<FilePathWatcherKQueue>(); 35 + } 36 + DCHECK(impl_.get()); 37 + return impl_->Watch(path, type, callback); 38 + } 39 + 40 + void Cancel() override { 41 + if (impl_.get()) 42 + impl_->Cancel(); 43 + set_cancelled(); 44 + } 45 + 46 + private: 47 + std::unique_ptr<PlatformDelegate> impl_; 48 +}; 49 + 50 +} // namespace 51 + 52 +FilePathWatcher::FilePathWatcher() { 53 + sequence_checker_.DetachFromSequence(); 54 + impl_ = std::make_unique<FilePathWatcherImpl>(); 55 +} 56 + 57 +} // namespace base 58