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

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

Issue 1100773004: base: Remove most uses of MessageLoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some missing includes. Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This module provides a way to monitor a file or directory for changes. 5 // This module provides a way to monitor a file or directory for changes.
6 6
7 #ifndef BASE_FILES_FILE_PATH_WATCHER_H_ 7 #ifndef BASE_FILES_FILE_PATH_WATCHER_H_
8 #define BASE_FILES_FILE_PATH_WATCHER_H_ 8 #define BASE_FILES_FILE_PATH_WATCHER_H_
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/single_thread_task_runner.h"
16 16
17 namespace base { 17 namespace base {
18 18
19 // This class lets you register interest in changes on a FilePath. 19 // This class lets you register interest in changes on a FilePath.
20 // The callback will get called whenever the file or directory referenced by the 20 // The callback will get called whenever the file or directory referenced by the
21 // FilePath is changed, including created or deleted. Due to limitations in the 21 // FilePath is changed, including created or deleted. Due to limitations in the
22 // underlying OS APIs, FilePathWatcher has slightly different semantics on OS X 22 // underlying OS APIs, FilePathWatcher has slightly different semantics on OS X
23 // than on Windows or Linux. FilePathWatcher on Linux and Windows will detect 23 // than on Windows or Linux. FilePathWatcher on Linux and Windows will detect
24 // modifications to files in a watched directory. FilePathWatcher on Mac will 24 // modifications to files in a watched directory. FilePathWatcher on Mac will
25 // detect the creation and deletion of files in a watched directory, but will 25 // detect the creation and deletion of files in a watched directory, but will
(...skipping 25 matching lines...) Expand all
51 friend class base::RefCountedThreadSafe<PlatformDelegate>; 51 friend class base::RefCountedThreadSafe<PlatformDelegate>;
52 friend class FilePathWatcher; 52 friend class FilePathWatcher;
53 53
54 virtual ~PlatformDelegate(); 54 virtual ~PlatformDelegate();
55 55
56 // Stop watching. This is only called on the thread of the appropriate 56 // Stop watching. This is only called on the thread of the appropriate
57 // message loop. Since it can also be called more than once, it should 57 // message loop. Since it can also be called more than once, it should
58 // check |is_cancelled()| to avoid duplicate work. 58 // check |is_cancelled()| to avoid duplicate work.
59 virtual void CancelOnMessageLoopThread() = 0; 59 virtual void CancelOnMessageLoopThread() = 0;
60 60
61 scoped_refptr<base::MessageLoopProxy> message_loop() const { 61 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
62 return message_loop_; 62 return task_runner_;
63 } 63 }
64 64
65 void set_message_loop(const scoped_refptr<base::MessageLoopProxy>& loop) { 65 void set_task_runner(
66 message_loop_ = loop; 66 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
67 task_runner_ = task_runner.Pass();
67 } 68 }
68 69
69 // Must be called before the PlatformDelegate is deleted. 70 // Must be called before the PlatformDelegate is deleted.
70 void set_cancelled() { 71 void set_cancelled() {
71 cancelled_ = true; 72 cancelled_ = true;
72 } 73 }
73 74
74 bool is_cancelled() const { 75 bool is_cancelled() const {
75 return cancelled_; 76 return cancelled_;
76 } 77 }
77 78
78 private: 79 private:
79 scoped_refptr<base::MessageLoopProxy> message_loop_; 80 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
80 bool cancelled_; 81 bool cancelled_;
81 }; 82 };
82 83
83 FilePathWatcher(); 84 FilePathWatcher();
84 virtual ~FilePathWatcher(); 85 virtual ~FilePathWatcher();
85 86
86 // A callback that always cleans up the PlatformDelegate, either when executed 87 // A callback that always cleans up the PlatformDelegate, either when executed
87 // or when deleted without having been executed at all, as can happen during 88 // or when deleted without having been executed at all, as can happen during
88 // shutdown. 89 // shutdown.
89 static void CancelWatch(const scoped_refptr<PlatformDelegate>& delegate); 90 static void CancelWatch(const scoped_refptr<PlatformDelegate>& delegate);
(...skipping 12 matching lines...) Expand all
102 103
103 private: 104 private:
104 scoped_refptr<PlatformDelegate> impl_; 105 scoped_refptr<PlatformDelegate> impl_;
105 106
106 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher); 107 DISALLOW_COPY_AND_ASSIGN(FilePathWatcher);
107 }; 108 };
108 109
109 } // namespace base 110 } // namespace base
110 111
111 #endif // BASE_FILES_FILE_PATH_WATCHER_H_ 112 #endif // BASE_FILES_FILE_PATH_WATCHER_H_
OLDNEW
« no previous file with comments | « base/deferred_sequenced_task_runner_unittest.cc ('k') | base/files/file_path_watcher_fsevents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698