craig.schlenter@chromium.org | b2d581e | 2011-04-15 01:56:01 +0900 | [diff] [blame] | 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" |
avi@chromium.org | a043a86 | 2013-07-18 17:12:40 +0900 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
craig.schlenter@chromium.org | b2d581e | 2011-04-15 01:56:01 +0900 | [diff] [blame] | 12 | |
vandebo@chromium.org | c185d78 | 2014-06-11 16:15:24 +0900 | [diff] [blame] | 13 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 14 | #include "base/mac/mac_util.h" |
| 15 | #endif |
| 16 | |
craig.schlenter@chromium.org | b2d581e | 2011-04-15 01:56:01 +0900 | [diff] [blame] | 17 | namespace base { |
craig.schlenter@chromium.org | b2d581e | 2011-04-15 01:56:01 +0900 | [diff] [blame] | 18 | |
| 19 | FilePathWatcher::~FilePathWatcher() { |
| 20 | impl_->Cancel(); |
| 21 | } |
| 22 | |
jhawkins@chromium.org | fce1f41 | 2011-11-24 05:44:00 +0900 | [diff] [blame] | 23 | // static |
| 24 | void FilePathWatcher::CancelWatch( |
| 25 | const scoped_refptr<PlatformDelegate>& delegate) { |
| 26 | delegate->CancelOnMessageLoopThread(); |
| 27 | } |
| 28 | |
vandebo@chromium.org | c185d78 | 2014-06-11 16:15:24 +0900 | [diff] [blame] | 29 | // static |
| 30 | bool 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(); |
pauljensen | 6ea122c | 2015-04-14 06:27:46 +0900 | [diff] [blame] | 35 | #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_ANDROID) |
vandebo@chromium.org | c185d78 | 2014-06-11 16:15:24 +0900 | [diff] [blame] | 36 | return true; |
| 37 | #else |
| 38 | return false; |
| 39 | #endif |
| 40 | } |
| 41 | |
craig.schlenter@chromium.org | b2d581e | 2011-04-15 01:56:01 +0900 | [diff] [blame] | 42 | FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) { |
| 43 | } |
| 44 | |
| 45 | FilePathWatcher::PlatformDelegate::~PlatformDelegate() { |
| 46 | DCHECK(is_cancelled()); |
| 47 | } |
| 48 | |
kmadhusu@chromium.org | c9126e5 | 2012-12-05 09:36:39 +0900 | [diff] [blame] | 49 | bool FilePathWatcher::Watch(const FilePath& path, |
| 50 | bool recursive, |
| 51 | const Callback& callback) { |
| 52 | DCHECK(path.IsAbsolute()); |
darin@chromium.org | 9498d47 | 2013-01-15 09:37:47 +0900 | [diff] [blame] | 53 | return impl_->Watch(path, recursive, callback); |
joaodasilva@chromium.org | 5e57506 | 2012-06-04 23:21:27 +0900 | [diff] [blame] | 54 | } |
| 55 | |
craig.schlenter@chromium.org | b2d581e | 2011-04-15 01:56:01 +0900 | [diff] [blame] | 56 | } // namespace base |