[Drive] Handle error cases earlier in FakeDriveService
[chromium-blink-merge.git] / base / files / file_path_watcher_mac.cc
blob54ca46d12bbdf9e9c33692555e3bc0e1040102be
1 // 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.
5 #include "base/files/file_path_watcher.h"
6 #include "base/files/file_path_watcher_kqueue.h"
8 #if !defined(OS_IOS)
9 #include "base/files/file_path_watcher_fsevents.h"
10 #endif
12 namespace base {
14 namespace {
16 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {
17 public:
18 virtual bool Watch(const FilePath& path,
19 bool recursive,
20 const FilePathWatcher::Callback& callback) OVERRIDE {
21 // 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();
32 DCHECK(impl_.get());
33 return impl_->Watch(path, recursive, callback);
36 virtual void Cancel() OVERRIDE {
37 if (impl_)
38 impl_->Cancel();
39 set_cancelled();
42 virtual void CancelOnMessageLoopThread() OVERRIDE {
43 if (impl_)
44 impl_->Cancel();
45 set_cancelled();
48 protected:
49 virtual ~FilePathWatcherImpl() {}
51 scoped_refptr<PlatformDelegate> impl_;
54 } // namespace
56 FilePathWatcher::FilePathWatcher() {
57 impl_ = new FilePathWatcherImpl();
60 } // namespace base