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 namespace base { 15 ~FilePathWatcher()16FilePathWatcher::~FilePathWatcher() { 17 impl_->Cancel(); 18 } 19 20 // static CancelWatch(const scoped_refptr<PlatformDelegate> & delegate)21void FilePathWatcher::CancelWatch( 22 const scoped_refptr<PlatformDelegate>& delegate) { 23 delegate->CancelOnMessageLoopThread(); 24 } 25 26 // static RecursiveWatchAvailable()27bool FilePathWatcher::RecursiveWatchAvailable() { 28 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) || \ 29 defined(OS_LINUX) || defined(OS_ANDROID) 30 return true; 31 #else 32 // FSEvents isn't available on iOS. 33 return false; 34 #endif 35 } 36 PlatformDelegate()37FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) { 38 } 39 ~PlatformDelegate()40FilePathWatcher::PlatformDelegate::~PlatformDelegate() { 41 DCHECK(is_cancelled()); 42 } 43 Watch(const FilePath & path,bool recursive,const Callback & callback)44bool FilePathWatcher::Watch(const FilePath& path, 45 bool recursive, 46 const Callback& callback) { 47 DCHECK(path.IsAbsolute()); 48 return impl_->Watch(path, recursive, callback); 49 } 50 51 } // namespace base 52