• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #if defined(OS_MACOSX) && !defined(OS_IOS)
14 #include "base/mac/mac_util.h"
15 #endif
16 
17 namespace base {
18 
~FilePathWatcher()19 FilePathWatcher::~FilePathWatcher() {
20   impl_->Cancel();
21 }
22 
23 // static
CancelWatch(const scoped_refptr<PlatformDelegate> & delegate)24 void FilePathWatcher::CancelWatch(
25     const scoped_refptr<PlatformDelegate>& delegate) {
26   delegate->CancelOnMessageLoopThread();
27 }
28 
29 // static
RecursiveWatchAvailable()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();
35 #elif defined(OS_WIN) || defined(OS_LINUX)
36   return true;
37 #else
38   return false;
39 #endif
40 }
41 
PlatformDelegate()42 FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) {
43 }
44 
~PlatformDelegate()45 FilePathWatcher::PlatformDelegate::~PlatformDelegate() {
46   DCHECK(is_cancelled());
47 }
48 
Watch(const FilePath & path,bool recursive,const Callback & callback)49 bool FilePathWatcher::Watch(const FilePath& path,
50                             bool recursive,
51                             const Callback& callback) {
52   DCHECK(path.IsAbsolute());
53   return impl_->Watch(path, recursive, callback);
54 }
55 
56 }  // namespace base
57