blob: 6f55ba4f89266f5fdac16c86d1ac853615df4de9 [file] [log] [blame]
[email protected]6d2d92a2014-06-11 07:15:241// Copyright 2014 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#include "base/files/file_path_watcher.h"
6#include "base/files/file_path_watcher_kqueue.h"
7
8#if !defined(OS_IOS)
9#include "base/files/file_path_watcher_fsevents.h"
10#endif
11
12namespace base {
13
14namespace {
15
16class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {
17 public:
dcheng56488182014-10-21 10:54:5118 bool Watch(const FilePath& path,
19 bool recursive,
20 const FilePathWatcher::Callback& callback) override {
[email protected]6d2d92a2014-06-11 07:15:2421 // Use kqueue for non-recursive watches and FSEvents for recursive ones.
22 DCHECK(!impl_.get());
23 if (recursive) {
24 if (!FilePathWatcher::RecursiveWatchAvailable())
25 return false;
26#if !defined(OS_IOS)
27 impl_ = new FilePathWatcherFSEvents();
28#endif // OS_IOS
29 } else {
30 impl_ = new FilePathWatcherKQueue();
31 }
32 DCHECK(impl_.get());
33 return impl_->Watch(path, recursive, callback);
34 }
35
dcheng56488182014-10-21 10:54:5136 void Cancel() override {
dchengc041fef2014-09-20 03:31:2237 if (impl_.get())
[email protected]6d2d92a2014-06-11 07:15:2438 impl_->Cancel();
39 set_cancelled();
40 }
41
dcheng56488182014-10-21 10:54:5142 void CancelOnMessageLoopThread() override {
dchengc041fef2014-09-20 03:31:2243 if (impl_.get())
[email protected]6d2d92a2014-06-11 07:15:2444 impl_->Cancel();
45 set_cancelled();
46 }
47
48 protected:
dcheng56488182014-10-21 10:54:5149 ~FilePathWatcherImpl() override {}
[email protected]6d2d92a2014-06-11 07:15:2450
51 scoped_refptr<PlatformDelegate> impl_;
52};
53
54} // namespace
55
56FilePathWatcher::FilePathWatcher() {
57 impl_ = new FilePathWatcherImpl();
58}
59
60} // namespace base