| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/files/file_path_watcher_fsevents.h" | 5 #include "base/files/file_path_watcher_fsevents.h" |
| 6 | 6 |
| 7 #include <dispatch/dispatch.h> | 7 #include <dispatch/dispatch.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/message_loop/message_loop.h" | |
| 18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 // The latency parameter passed to FSEventsStreamCreate(). | 24 // The latency parameter passed to FSEventsStreamCreate(). |
| 26 const CFAbsoluteTime kEventLatencySeconds = 0.3; | 25 const CFAbsoluteTime kEventLatencySeconds = 0.3; |
| 27 | 26 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 : queue_(dispatch_queue_create( | 71 : queue_(dispatch_queue_create( |
| 73 base::StringPrintf( | 72 base::StringPrintf( |
| 74 "org.chromium.base.FilePathWatcher.%p", this).c_str(), | 73 "org.chromium.base.FilePathWatcher.%p", this).c_str(), |
| 75 DISPATCH_QUEUE_SERIAL)), | 74 DISPATCH_QUEUE_SERIAL)), |
| 76 fsevent_stream_(nullptr) { | 75 fsevent_stream_(nullptr) { |
| 77 } | 76 } |
| 78 | 77 |
| 79 bool FilePathWatcherFSEvents::Watch(const FilePath& path, | 78 bool FilePathWatcherFSEvents::Watch(const FilePath& path, |
| 80 bool recursive, | 79 bool recursive, |
| 81 const FilePathWatcher::Callback& callback) { | 80 const FilePathWatcher::Callback& callback) { |
| 82 DCHECK(MessageLoopForIO::current()); | |
| 83 DCHECK(!callback.is_null()); | 81 DCHECK(!callback.is_null()); |
| 84 DCHECK(callback_.is_null()); | 82 DCHECK(callback_.is_null()); |
| 85 | 83 |
| 86 // This class could support non-recursive watches, but that is currently | 84 // This class could support non-recursive watches, but that is currently |
| 87 // left to FilePathWatcherKQueue. | 85 // left to FilePathWatcherKQueue. |
| 88 if (!recursive) | 86 if (!recursive) |
| 89 return false; | 87 return false; |
| 90 | 88 |
| 91 set_task_runner(ThreadTaskRunnerHandle::Get()); | 89 set_task_runner(ThreadTaskRunnerHandle::Get()); |
| 92 callback_ = callback; | 90 callback_ = callback; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 void FilePathWatcherFSEvents::StartEventStream(FSEventStreamEventId start_event, | 265 void FilePathWatcherFSEvents::StartEventStream(FSEventStreamEventId start_event, |
| 268 const FilePath& path) { | 266 const FilePath& path) { |
| 269 DCHECK(resolved_target_.empty()); | 267 DCHECK(resolved_target_.empty()); |
| 270 | 268 |
| 271 target_ = path; | 269 target_ = path; |
| 272 ResolveTargetPath(); | 270 ResolveTargetPath(); |
| 273 UpdateEventStream(start_event); | 271 UpdateEventStream(start_event); |
| 274 } | 272 } |
| 275 | 273 |
| 276 } // namespace base | 274 } // namespace base |
| OLD | NEW |