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

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

Issue 2598193002: Allow FilePathWatcher to be used from sequenced tasks. (Closed)
Patch Set: thread -> sequence in comment Created 3 years, 12 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
« no previous file with comments | « base/files/file_path_watcher.h ('k') | base/files/file_path_watcher_kqueue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/sequenced_task_runner_handle.h"
19 19
20 namespace base { 20 namespace base {
21 21
22 namespace { 22 namespace {
23 23
24 // The latency parameter passed to FSEventsStreamCreate(). 24 // The latency parameter passed to FSEventsStreamCreate().
25 const CFAbsoluteTime kEventLatencySeconds = 0.3; 25 const CFAbsoluteTime kEventLatencySeconds = 0.3;
26 26
27 // Resolve any symlinks in the path. 27 // Resolve any symlinks in the path.
28 FilePath ResolvePath(const FilePath& path) { 28 FilePath ResolvePath(const FilePath& path) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 bool recursive, 79 bool recursive,
80 const FilePathWatcher::Callback& callback) { 80 const FilePathWatcher::Callback& callback) {
81 DCHECK(!callback.is_null()); 81 DCHECK(!callback.is_null());
82 DCHECK(callback_.is_null()); 82 DCHECK(callback_.is_null());
83 83
84 // This class could support non-recursive watches, but that is currently 84 // This class could support non-recursive watches, but that is currently
85 // left to FilePathWatcherKQueue. 85 // left to FilePathWatcherKQueue.
86 if (!recursive) 86 if (!recursive)
87 return false; 87 return false;
88 88
89 set_task_runner(ThreadTaskRunnerHandle::Get()); 89 set_task_runner(SequencedTaskRunnerHandle::Get());
90 callback_ = callback; 90 callback_ = callback;
91 91
92 FSEventStreamEventId start_event = FSEventsGetCurrentEventId(); 92 FSEventStreamEventId start_event = FSEventsGetCurrentEventId();
93 // The block runtime would implicitly capture the reference, not the object 93 // The block runtime would implicitly capture the reference, not the object
94 // it's referencing. Copy the path into a local, so that the value is 94 // it's referencing. Copy the path into a local, so that the value is
95 // captured by the block's scope. 95 // captured by the block's scope.
96 const FilePath path_copy(path); 96 const FilePath path_copy(path);
97 97
98 dispatch_async(queue_, ^{ 98 dispatch_async(queue_, ^{
99 StartEventStream(start_event, path_copy); 99 StartEventStream(start_event, path_copy);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void FilePathWatcherFSEvents::StartEventStream(FSEventStreamEventId start_event, 265 void FilePathWatcherFSEvents::StartEventStream(FSEventStreamEventId start_event,
266 const FilePath& path) { 266 const FilePath& path) {
267 DCHECK(resolved_target_.empty()); 267 DCHECK(resolved_target_.empty());
268 268
269 target_ = path; 269 target_ = path;
270 ResolveTargetPath(); 270 ResolveTargetPath();
271 UpdateEventStream(start_event); 271 UpdateEventStream(start_event);
272 } 272 }
273 273
274 } // namespace base 274 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher.h ('k') | base/files/file_path_watcher_kqueue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698