1// Copyright (c) 2011 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// 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/logging.h"
11#include "base/message_loop/message_loop.h"
12#include "build/build_config.h"
13
14#if defined(OS_MACOSX) && !defined(OS_IOS)
15#include "base/mac/mac_util.h"
16#endif
17
18namespace base {
19
20FilePathWatcher::~FilePathWatcher() {
21  impl_->Cancel();
22}
23
24// static
25void FilePathWatcher::CancelWatch(
26    const scoped_refptr<PlatformDelegate>& delegate) {
27  delegate->CancelOnMessageLoopThread();
28}
29
30// static
31bool FilePathWatcher::RecursiveWatchAvailable() {
32#if defined(OS_MACOSX) && !defined(OS_IOS)
33  // FSEvents isn't available on iOS and is broken on OSX 10.6 and earlier.
34  // See http://crbug.com/54822#c31
35  return mac::IsOSLionOrLater();
36#elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_ANDROID)
37  return true;
38#else
39  return false;
40#endif
41}
42
43FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) {
44}
45
46FilePathWatcher::PlatformDelegate::~PlatformDelegate() {
47  DCHECK(is_cancelled());
48}
49
50bool FilePathWatcher::Watch(const FilePath& path,
51                            bool recursive,
52                            const Callback& callback) {
53  DCHECK(path.IsAbsolute());
54  return impl_->Watch(path, recursive, callback);
55}
56
57}  // namespace base
58