Enables compositing support for webview.
[chromium-blink-merge.git] / base / files / file_path_watcher.cc
blobbc8db37f1b636881348be5a46a830ec314d7d833
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.
5 // Cross platform methods for FilePathWatcher. See the various platform
6 // specific implementation files, too.
8 #include "base/files/file_path_watcher.h"
10 #include "base/logging.h"
11 #include "base/message_loop.h"
13 namespace base {
14 namespace files {
16 namespace {
18 // A delegate implementation for the callback interface.
19 class FilePathWatcherDelegate : public base::files::FilePathWatcher::Delegate {
20 public:
21 explicit FilePathWatcherDelegate(const FilePathWatcher::Callback& callback)
22 : callback_(callback) {}
24 // FilePathWatcher::Delegate implementation.
25 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
26 callback_.Run(path, false);
29 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
30 callback_.Run(path, true);
33 private:
34 virtual ~FilePathWatcherDelegate() {}
36 FilePathWatcher::Callback callback_;
38 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherDelegate);
41 } // namespace
43 FilePathWatcher::~FilePathWatcher() {
44 impl_->Cancel();
47 // static
48 void FilePathWatcher::CancelWatch(
49 const scoped_refptr<PlatformDelegate>& delegate) {
50 delegate->CancelOnMessageLoopThread();
53 bool FilePathWatcher::Watch(const FilePath& path, Delegate* delegate) {
54 DCHECK(path.IsAbsolute());
55 return impl_->Watch(path, false, delegate);
58 FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) {
61 FilePathWatcher::PlatformDelegate::~PlatformDelegate() {
62 DCHECK(is_cancelled());
65 bool FilePathWatcher::Watch(const FilePath& path,
66 bool recursive,
67 const Callback& callback) {
68 DCHECK(path.IsAbsolute());
69 return impl_->Watch(path, recursive, new FilePathWatcherDelegate(callback));
72 } // namespace files
73 } // namespace base