Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: base/files/file_path_watcher.cc

Issue 10519003: Added a base::Callback interface to FilePathWatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Cross platform methods for FilePathWatcher. See the various platform 5 // Cross platform methods for FilePathWatcher. See the various platform
6 // specific implementation files, too. 6 // specific implementation files, too.
7 7
8 #include "base/files/file_path_watcher.h" 8 #include "base/files/file_path_watcher.h"
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 12
13 namespace base { 13 namespace base {
14 namespace files { 14 namespace files {
15 15
16 namespace {
17
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) {}
23
24 // FilePathWatcher::Delegate implementation.
25 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
26 callback_.Run(path, false);
27 }
28
29 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
30 callback_.Run(path, true);
31 }
32
33 private:
34 virtual ~FilePathWatcherDelegate() {}
35
36 FilePathWatcher::Callback callback_;
37
38 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherDelegate);
39 };
40
41 } // namespace
42
16 FilePathWatcher::~FilePathWatcher() { 43 FilePathWatcher::~FilePathWatcher() {
17 impl_->Cancel(); 44 impl_->Cancel();
18 } 45 }
19 46
20 // static 47 // static
21 void FilePathWatcher::CancelWatch( 48 void FilePathWatcher::CancelWatch(
22 const scoped_refptr<PlatformDelegate>& delegate) { 49 const scoped_refptr<PlatformDelegate>& delegate) {
23 delegate->CancelOnMessageLoopThread(); 50 delegate->CancelOnMessageLoopThread();
24 } 51 }
25 52
26 bool FilePathWatcher::Watch(const FilePath& path, Delegate* delegate) { 53 bool FilePathWatcher::Watch(const FilePath& path, Delegate* delegate) {
27 DCHECK(path.IsAbsolute()); 54 DCHECK(path.IsAbsolute());
28 return impl_->Watch(path, delegate); 55 return impl_->Watch(path, delegate);
29 } 56 }
30 57
31 FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) { 58 FilePathWatcher::PlatformDelegate::PlatformDelegate(): cancelled_(false) {
32 } 59 }
33 60
34 FilePathWatcher::PlatformDelegate::~PlatformDelegate() { 61 FilePathWatcher::PlatformDelegate::~PlatformDelegate() {
35 DCHECK(is_cancelled()); 62 DCHECK(is_cancelled());
36 } 63 }
37 64
65 bool FilePathWatcher::Watch(const FilePath& path, const Callback& callback) {
66 return Watch(path, new FilePathWatcherDelegate(callback));
67 }
68
38 } // namespace files 69 } // namespace files
39 } // namespace base 70 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698