blob: 59ae7059cafef64e20e65099b5d245ab7950b503 [file] [log] [blame]
craig.schlenter@chromium.orgb2d581e2011-04-15 01:56:01 +09001// 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"
avi@chromium.orga043a862013-07-18 17:12:40 +090011#include "base/message_loop/message_loop.h"
craig.schlenter@chromium.orgb2d581e2011-04-15 01:56:01 +090012
vandebo@chromium.orgc185d782014-06-11 16:15:24 +090013#if defined(OS_MACOSX) && !defined(OS_IOS)
14#include "base/mac/mac_util.h"
15#endif
16
craig.schlenter@chromium.orgb2d581e2011-04-15 01:56:01 +090017namespace base {
craig.schlenter@chromium.orgb2d581e2011-04-15 01:56:01 +090018
19FilePathWatcher::~FilePathWatcher() {
20 impl_->Cancel();
21}
22
jhawkins@chromium.orgfce1f412011-11-24 05:44:00 +090023// static
24void FilePathWatcher::CancelWatch(
25 const scoped_refptr<PlatformDelegate>& delegate) {
26 delegate->CancelOnMessageLoopThread();
27}
28
vandebo@chromium.orgc185d782014-06-11 16:15:24 +090029// static
30bool FilePathWatcher::RecursiveWatchAvailable() {
31#if defined(OS_MACOSX) && !defined(OS_IOS)
32 // FSEvents isn't available on iOS and is broken on OSX 10.6 and earlier.
33 // See http://crbug.com/54822#c31
34 return mac::IsOSLionOrLater();
pauljensen6ea122c2015-04-14 06:27:46 +090035#elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_ANDROID)
vandebo@chromium.orgc185d782014-06-11 16:15:24 +090036 return true;
37#else
38 return false;
39#endif
40}
41
craig.schlenter@chromium.orgb2d581e2011-04-15 01:56:01 +090042FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) {
43}
44
45FilePathWatcher::PlatformDelegate::~PlatformDelegate() {
46 DCHECK(is_cancelled());
47}
48
kmadhusu@chromium.orgc9126e52012-12-05 09:36:39 +090049bool FilePathWatcher::Watch(const FilePath& path,
50 bool recursive,
51 const Callback& callback) {
52 DCHECK(path.IsAbsolute());
darin@chromium.org9498d472013-01-15 09:37:47 +090053 return impl_->Watch(path, recursive, callback);
joaodasilva@chromium.org5e575062012-06-04 23:21:27 +090054}
55
craig.schlenter@chromium.orgb2d581e2011-04-15 01:56:01 +090056} // namespace base