| OLD | NEW |
| 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 "chrome/browser/file_path_watcher.h" | 5 #include "chrome/browser/file_path_watcher.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // The latency parameter passed to FSEventsStreamCreate(). | 19 // The latency parameter passed to FSEventsStreamCreate(). |
| 20 const CFAbsoluteTime kEventLatencySeconds = 0.3; | 20 const CFAbsoluteTime kEventLatencySeconds = 0.3; |
| 21 | 21 |
| 22 // Mac-specific file watcher implementation based on the FSEvents API. | 22 // Mac-specific file watcher implementation based on the FSEvents API. |
| 23 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { | 23 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 181 | 181 |
| 182 // It can happen that the watcher gets canceled while tasks that call this | 182 // It can happen that the watcher gets canceled while tasks that call this |
| 183 // function are still in flight, so abort if this situation is detected. | 183 // function are still in flight, so abort if this situation is detected. |
| 184 if (canceled_) | 184 if (canceled_) |
| 185 return; | 185 return; |
| 186 | 186 |
| 187 if (fsevent_stream_) | 187 if (fsevent_stream_) |
| 188 DestroyEventStream(); | 188 DestroyEventStream(); |
| 189 | 189 |
| 190 scoped_cftyperef<CFStringRef> cf_path(CFStringCreateWithCString( | 190 base::mac::ScopedCFTypeRef<CFStringRef> cf_path(CFStringCreateWithCString( |
| 191 NULL, target_.value().c_str(), kCFStringEncodingMacHFS)); | 191 NULL, target_.value().c_str(), kCFStringEncodingMacHFS)); |
| 192 scoped_cftyperef<CFStringRef> cf_dir_path(CFStringCreateWithCString( | 192 base::mac::ScopedCFTypeRef<CFStringRef> cf_dir_path(CFStringCreateWithCString( |
| 193 NULL, target_.DirName().value().c_str(), kCFStringEncodingMacHFS)); | 193 NULL, target_.DirName().value().c_str(), kCFStringEncodingMacHFS)); |
| 194 CFStringRef paths_array[] = { cf_path.get(), cf_dir_path.get() }; | 194 CFStringRef paths_array[] = { cf_path.get(), cf_dir_path.get() }; |
| 195 scoped_cftyperef<CFArrayRef> watched_paths(CFArrayCreate( | 195 base::mac::ScopedCFTypeRef<CFArrayRef> watched_paths(CFArrayCreate( |
| 196 NULL, reinterpret_cast<const void**>(paths_array), arraysize(paths_array), | 196 NULL, reinterpret_cast<const void**>(paths_array), arraysize(paths_array), |
| 197 &kCFTypeArrayCallBacks)); | 197 &kCFTypeArrayCallBacks)); |
| 198 | 198 |
| 199 FSEventStreamContext context; | 199 FSEventStreamContext context; |
| 200 context.version = 0; | 200 context.version = 0; |
| 201 context.info = this; | 201 context.info = this; |
| 202 context.retain = NULL; | 202 context.retain = NULL; |
| 203 context.release = NULL; | 203 context.release = NULL; |
| 204 context.copyDescription = NULL; | 204 context.copyDescription = NULL; |
| 205 | 205 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 223 FSEventStreamInvalidate(fsevent_stream_); | 223 FSEventStreamInvalidate(fsevent_stream_); |
| 224 FSEventStreamRelease(fsevent_stream_); | 224 FSEventStreamRelease(fsevent_stream_); |
| 225 fsevent_stream_ = NULL; | 225 fsevent_stream_ = NULL; |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace | 228 } // namespace |
| 229 | 229 |
| 230 FilePathWatcher::FilePathWatcher() { | 230 FilePathWatcher::FilePathWatcher() { |
| 231 impl_ = new FilePathWatcherImpl(); | 231 impl_ = new FilePathWatcherImpl(); |
| 232 } | 232 } |
| OLD | NEW |