OLD | NEW |
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 #include "base/files/file_path_watcher.h" | 5 #include "base/files/file_path_watcher.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/inotify.h> | 9 #include <sys/inotify.h> |
10 #include <sys/ioctl.h> | 10 #include <sys/ioctl.h> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // watch that fired, |child| indicates what has changed, and is relative to | 93 // watch that fired, |child| indicates what has changed, and is relative to |
94 // the currently watched path for |fired_watch|. The flag |created| is true if | 94 // the currently watched path for |fired_watch|. The flag |created| is true if |
95 // the object appears. | 95 // the object appears. |
96 void OnFilePathChanged(InotifyReader::Watch fired_watch, | 96 void OnFilePathChanged(InotifyReader::Watch fired_watch, |
97 const FilePath::StringType& child, | 97 const FilePath::StringType& child, |
98 bool created); | 98 bool created); |
99 | 99 |
100 // Start watching |path| for changes and notify |delegate| on each change. | 100 // Start watching |path| for changes and notify |delegate| on each change. |
101 // Returns true if watch for |path| has been added successfully. | 101 // Returns true if watch for |path| has been added successfully. |
102 virtual bool Watch(const FilePath& path, | 102 virtual bool Watch(const FilePath& path, |
| 103 bool recursive, |
103 FilePathWatcher::Delegate* delegate) OVERRIDE; | 104 FilePathWatcher::Delegate* delegate) OVERRIDE; |
104 | 105 |
105 // Cancel the watch. This unregisters the instance with InotifyReader. | 106 // Cancel the watch. This unregisters the instance with InotifyReader. |
106 virtual void Cancel() OVERRIDE; | 107 virtual void Cancel() OVERRIDE; |
107 | 108 |
108 // Deletion of the FilePathWatcher will call Cancel() to dispose of this | 109 // Deletion of the FilePathWatcher will call Cancel() to dispose of this |
109 // object in the right thread. This also observes destruction of the required | 110 // object in the right thread. This also observes destruction of the required |
110 // cleanup thread, in case it quits before Cancel() is called. | 111 // cleanup thread, in case it quits before Cancel() is called. |
111 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 112 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
112 | 113 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 (change_on_target_path && !created) || | 355 (change_on_target_path && !created) || |
355 (change_on_target_path && file_util::PathExists(target_))) { | 356 (change_on_target_path && file_util::PathExists(target_))) { |
356 delegate_->OnFilePathChanged(target_); | 357 delegate_->OnFilePathChanged(target_); |
357 return; | 358 return; |
358 } | 359 } |
359 } | 360 } |
360 } | 361 } |
361 } | 362 } |
362 | 363 |
363 bool FilePathWatcherImpl::Watch(const FilePath& path, | 364 bool FilePathWatcherImpl::Watch(const FilePath& path, |
| 365 bool recursive, |
364 FilePathWatcher::Delegate* delegate) { | 366 FilePathWatcher::Delegate* delegate) { |
365 DCHECK(target_.empty()); | 367 DCHECK(target_.empty()); |
366 DCHECK(MessageLoopForIO::current()); | 368 DCHECK(MessageLoopForIO::current()); |
| 369 if (recursive) { |
| 370 // Recursive watch is not supported on this platform. |
| 371 NOTIMPLEMENTED(); |
| 372 return false; |
| 373 } |
367 | 374 |
368 set_message_loop(base::MessageLoopProxy::current()); | 375 set_message_loop(base::MessageLoopProxy::current()); |
369 delegate_ = delegate; | 376 delegate_ = delegate; |
370 target_ = path; | 377 target_ = path; |
371 MessageLoop::current()->AddDestructionObserver(this); | 378 MessageLoop::current()->AddDestructionObserver(this); |
372 | 379 |
373 std::vector<FilePath::StringType> comps; | 380 std::vector<FilePath::StringType> comps; |
374 target_.GetComponents(&comps); | 381 target_.GetComponents(&comps); |
375 DCHECK(!comps.empty()); | 382 DCHECK(!comps.empty()); |
376 std::vector<FilePath::StringType>::const_iterator comp = comps.begin(); | 383 std::vector<FilePath::StringType>::const_iterator comp = comps.begin(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 481 } |
475 | 482 |
476 } // namespace | 483 } // namespace |
477 | 484 |
478 FilePathWatcher::FilePathWatcher() { | 485 FilePathWatcher::FilePathWatcher() { |
479 impl_ = new FilePathWatcherImpl(); | 486 impl_ = new FilePathWatcherImpl(); |
480 } | 487 } |
481 | 488 |
482 } // namespace files | 489 } // namespace files |
483 } // namespace base | 490 } // namespace base |
OLD | NEW |