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 <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/event.h> | 8 #include <sys/event.h> |
9 #include <sys/param.h> | 9 #include <sys/param.h> |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/logging.h" | |
15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
16 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
18 | 19 |
19 // On some platforms these are not defined. | 20 // On some platforms these are not defined. |
20 #if !defined(EV_RECEIPT) | 21 #if !defined(EV_RECEIPT) |
21 #define EV_RECEIPT 0 | 22 #define EV_RECEIPT 0 |
22 #endif | 23 #endif |
23 #if !defined(O_EVTONLY) | 24 #if !defined(O_EVTONLY) |
24 #define O_EVTONLY O_RDONLY | 25 #define O_EVTONLY O_RDONLY |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 58 |
58 // MessageLoopForIO::Watcher overrides. | 59 // MessageLoopForIO::Watcher overrides. |
59 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 60 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
60 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 61 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
61 | 62 |
62 // MessageLoop::DestructionObserver overrides. | 63 // MessageLoop::DestructionObserver overrides. |
63 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 64 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
64 | 65 |
65 // FilePathWatcher::PlatformDelegate overrides. | 66 // FilePathWatcher::PlatformDelegate overrides. |
66 virtual bool Watch(const FilePath& path, | 67 virtual bool Watch(const FilePath& path, |
68 bool recursive, | |
67 FilePathWatcher::Delegate* delegate) OVERRIDE; | 69 FilePathWatcher::Delegate* delegate) OVERRIDE; |
68 virtual void Cancel() OVERRIDE; | 70 virtual void Cancel() OVERRIDE; |
69 | 71 |
70 protected: | 72 protected: |
71 virtual ~FilePathWatcherImpl() {} | 73 virtual ~FilePathWatcherImpl() {} |
72 | 74 |
73 private: | 75 private: |
74 class EventData { | 76 class EventData { |
75 public: | 77 public: |
76 EventData(const FilePath& path, const FilePath::StringType& subdir) | 78 EventData(const FilePath& path, const FilePath::StringType& subdir) |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 | 423 |
422 void FilePathWatcherImpl::OnFileCanWriteWithoutBlocking(int fd) { | 424 void FilePathWatcherImpl::OnFileCanWriteWithoutBlocking(int fd) { |
423 NOTREACHED(); | 425 NOTREACHED(); |
424 } | 426 } |
425 | 427 |
426 void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() { | 428 void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() { |
427 CancelOnMessageLoopThread(); | 429 CancelOnMessageLoopThread(); |
428 } | 430 } |
429 | 431 |
430 bool FilePathWatcherImpl::Watch(const FilePath& path, | 432 bool FilePathWatcherImpl::Watch(const FilePath& path, |
433 bool recursive, | |
431 FilePathWatcher::Delegate* delegate) { | 434 FilePathWatcher::Delegate* delegate) { |
432 DCHECK(MessageLoopForIO::current()); | 435 DCHECK(MessageLoopForIO::current()); |
433 DCHECK(target_.value().empty()); // Can only watch one path. | 436 DCHECK(target_.value().empty()); // Can only watch one path. |
434 DCHECK(delegate); | 437 DCHECK(delegate); |
435 DCHECK_EQ(kqueue_, -1); | 438 DCHECK_EQ(kqueue_, -1); |
436 | 439 |
440 if (recursive) { | |
441 NOTIMPLEMENTED(); | |
Mattias Nissler (ping if slow)
2012/11/21 09:28:48
What's the effect of this at run time? I'd rather
Lei Zhang
2012/11/21 20:01:09
I don't think we want to put in CHECKs. Let's say
Mattias Nissler (ping if slow)
2012/11/22 08:51:34
All right, you convinced me that returning false i
| |
442 return false; | |
443 } | |
444 | |
437 delegate_ = delegate; | 445 delegate_ = delegate; |
438 target_ = path; | 446 target_ = path; |
439 | 447 |
440 MessageLoop::current()->AddDestructionObserver(this); | 448 MessageLoop::current()->AddDestructionObserver(this); |
441 io_message_loop_ = base::MessageLoopProxy::current(); | 449 io_message_loop_ = base::MessageLoopProxy::current(); |
442 | 450 |
443 kqueue_ = kqueue(); | 451 kqueue_ = kqueue(); |
444 if (kqueue_ == -1) { | 452 if (kqueue_ == -1) { |
445 DPLOG(ERROR) << "kqueue"; | 453 DPLOG(ERROR) << "kqueue"; |
446 return false; | 454 return false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 } | 503 } |
496 | 504 |
497 } // namespace | 505 } // namespace |
498 | 506 |
499 FilePathWatcher::FilePathWatcher() { | 507 FilePathWatcher::FilePathWatcher() { |
500 impl_ = new FilePathWatcherImpl(); | 508 impl_ = new FilePathWatcherImpl(); |
501 } | 509 } |
502 | 510 |
503 } // namespace files | 511 } // namespace files |
504 } // namespace base | 512 } // namespace base |
OLD | NEW |