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

Side by Side Diff: base/directory_watcher_mac.cc

Issue 115229: Add support for almost-recursive watches in Linux DirectoryWatcher (Closed)
Patch Set: fix NULL file_thread scenario Created 11 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "base/directory_watcher.h" 5 #include "base/directory_watcher.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 10 matching lines...) Expand all
21 DirectoryWatcherImpl() {} 21 DirectoryWatcherImpl() {}
22 ~DirectoryWatcherImpl() { 22 ~DirectoryWatcherImpl() {
23 if (!path_.value().empty()) { 23 if (!path_.value().empty()) {
24 FSEventStreamStop(fsevent_stream_); 24 FSEventStreamStop(fsevent_stream_);
25 FSEventStreamInvalidate(fsevent_stream_); 25 FSEventStreamInvalidate(fsevent_stream_);
26 FSEventStreamRelease(fsevent_stream_); 26 FSEventStreamRelease(fsevent_stream_);
27 } 27 }
28 } 28 }
29 29
30 virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate, 30 virtual bool Watch(const FilePath& path, DirectoryWatcher::Delegate* delegate,
31 bool recursive); 31 MessageLoop* backend_loop, bool recursive);
32 32
33 void OnFSEventsCallback(const FilePath& event_path) { 33 void OnFSEventsCallback(const FilePath& event_path) {
34 DCHECK(!path_.value().empty()); 34 DCHECK(!path_.value().empty());
35 if (!recursive_) { 35 if (!recursive_) {
36 FilePath absolute_event_path = event_path; 36 FilePath absolute_event_path = event_path;
37 if (!file_util::AbsolutePath(&absolute_event_path)) 37 if (!file_util::AbsolutePath(&absolute_event_path))
38 return; 38 return;
39 if (absolute_event_path != path_) 39 if (absolute_event_path != path_)
40 return; 40 return;
41 } 41 }
(...skipping 23 matching lines...) Expand all
65 char** paths = reinterpret_cast<char**>(event_paths); 65 char** paths = reinterpret_cast<char**>(event_paths);
66 DirectoryWatcherImpl* watcher = 66 DirectoryWatcherImpl* watcher =
67 reinterpret_cast<DirectoryWatcherImpl*> (event_watcher); 67 reinterpret_cast<DirectoryWatcherImpl*> (event_watcher);
68 for (size_t i = 0; i < num_events; i++) { 68 for (size_t i = 0; i < num_events; i++) {
69 watcher->OnFSEventsCallback(FilePath(paths[i])); 69 watcher->OnFSEventsCallback(FilePath(paths[i]));
70 } 70 }
71 } 71 }
72 72
73 bool DirectoryWatcherImpl::Watch(const FilePath& path, 73 bool DirectoryWatcherImpl::Watch(const FilePath& path,
74 DirectoryWatcher::Delegate* delegate, 74 DirectoryWatcher::Delegate* delegate,
75 MessageLoop* backend_loop,
75 bool recursive) { 76 bool recursive) {
76 DCHECK(path_.value().empty()); // Can only watch one path. 77 DCHECK(path_.value().empty()); // Can only watch one path.
77 78
78 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); 79 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
79 80
80 if (!file_util::PathExists(path)) 81 if (!file_util::PathExists(path))
81 return false; 82 return false;
82 83
83 path_ = path; 84 path_ = path;
84 if (!file_util::AbsolutePath(&path_)) { 85 if (!file_util::AbsolutePath(&path_)) {
(...skipping 27 matching lines...) Expand all
112 FSEventStreamStart(fsevent_stream_); 113 FSEventStreamStart(fsevent_stream_);
113 114
114 return true; 115 return true;
115 } 116 }
116 117
117 } // namespace 118 } // namespace
118 119
119 DirectoryWatcher::DirectoryWatcher() { 120 DirectoryWatcher::DirectoryWatcher() {
120 impl_ = new DirectoryWatcherImpl(); 121 impl_ = new DirectoryWatcherImpl();
121 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698