• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Cross platform methods for FilePathWatcher. See the various platform
6 // specific implementation files, too.
7 
8 #include "base/files/file_path_watcher.h"
9 
10 #include "base/check.h"
11 #include "base/files/file_path.h"
12 #include "build/build_config.h"
13 
14 namespace base {
15 
~FilePathWatcher()16 FilePathWatcher::~FilePathWatcher() {
17   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
18   impl_->Cancel();
19 }
20 
21 // static
RecursiveWatchAvailable()22 bool FilePathWatcher::RecursiveWatchAvailable() {
23 #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) ||        \
24     BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_AIX) || \
25     BUILDFLAG(IS_FUCHSIA)
26   return true;
27 #else
28   // FSEvents isn't available on iOS.
29   return false;
30 #endif
31 }
32 
33 FilePathWatcher::PlatformDelegate::PlatformDelegate() = default;
34 
~PlatformDelegate()35 FilePathWatcher::PlatformDelegate::~PlatformDelegate() {
36   DCHECK(is_cancelled());
37 }
38 
Watch(const FilePath & path,Type type,const Callback & callback)39 bool FilePathWatcher::Watch(const FilePath& path,
40                             Type type,
41                             const Callback& callback) {
42   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
43   DCHECK(path.IsAbsolute());
44   return impl_->Watch(path, type, callback);
45 }
46 
WatchWithOptions(const FilePath & path,const WatchOptions & options,const Callback & callback)47 bool FilePathWatcher::WatchWithOptions(const FilePath& path,
48                                        const WatchOptions& options,
49                                        const Callback& callback) {
50   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
51   DCHECK(path.IsAbsolute());
52   return impl_->WatchWithOptions(path, options, callback);
53 }
54 
WatchWithOptions(const FilePath & path,const WatchOptions & options,const Callback & callback)55 bool FilePathWatcher::PlatformDelegate::WatchWithOptions(
56     const FilePath& path,
57     const WatchOptions& options,
58     const Callback& callback) {
59   return Watch(path, options.type, callback);
60 }
61 
62 }  // namespace base
63