OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/file_path_watcher/file_path_watcher.h" | 5 #include "content/common/file_path_watcher/file_path_watcher.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/win/object_watcher.h" | 13 #include "base/win/object_watcher.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, | 17 class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
18 public base::win::ObjectWatcher::Delegate, | 18 public base::win::ObjectWatcher::Delegate, |
19 public MessageLoop::DestructionObserver { | 19 public MessageLoop::DestructionObserver { |
20 public: | 20 public: |
21 FilePathWatcherImpl() : delegate_(NULL), handle_(INVALID_HANDLE_VALUE) {} | 21 FilePathWatcherImpl() : delegate_(NULL), handle_(INVALID_HANDLE_VALUE) {} |
22 | 22 |
23 // FilePathWatcher::PlatformDelegate overrides. | 23 // FilePathWatcher::PlatformDelegate overrides. |
24 virtual bool Watch(const FilePath& path, | 24 virtual bool Watch(const FilePath& path, |
25 FilePathWatcher::Delegate* delegate, | 25 FilePathWatcher::Delegate* delegate) OVERRIDE; |
26 base::MessageLoopProxy* loop) OVERRIDE; | |
27 virtual void Cancel() OVERRIDE; | 26 virtual void Cancel() OVERRIDE; |
28 | 27 |
29 // Deletion of the FilePathWatcher will call Cancel() to dispose of this | 28 // Deletion of the FilePathWatcher will call Cancel() to dispose of this |
30 // object in the right thread. This also observes destruction of the required | 29 // object in the right thread. This also observes destruction of the required |
31 // cleanup thread, in case it quits before Cancel() is called. | 30 // cleanup thread, in case it quits before Cancel() is called. |
32 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 31 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
33 | 32 |
34 // Callback from MessageLoopForIO. | 33 // Callback from MessageLoopForIO. |
35 virtual void OnObjectSignaled(HANDLE object); | 34 virtual void OnObjectSignaled(HANDLE object); |
36 | 35 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 base::Time last_modified_; | 68 base::Time last_modified_; |
70 | 69 |
71 // The time at which we processed the first notification with the | 70 // The time at which we processed the first notification with the |
72 // |last_modified_| time stamp. | 71 // |last_modified_| time stamp. |
73 base::Time first_notification_; | 72 base::Time first_notification_; |
74 | 73 |
75 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl); | 74 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl); |
76 }; | 75 }; |
77 | 76 |
78 bool FilePathWatcherImpl::Watch(const FilePath& path, | 77 bool FilePathWatcherImpl::Watch(const FilePath& path, |
79 FilePathWatcher::Delegate* delegate, | 78 FilePathWatcher::Delegate* delegate) { |
80 base::MessageLoopProxy*) { | |
81 DCHECK(target_.value().empty()); // Can only watch one path. | 79 DCHECK(target_.value().empty()); // Can only watch one path. |
82 | 80 |
83 set_message_loop(base::MessageLoopProxy::CreateForCurrentThread()); | 81 set_message_loop(base::MessageLoopProxy::CreateForCurrentThread()); |
84 delegate_ = delegate; | 82 delegate_ = delegate; |
85 target_ = path; | 83 target_ = path; |
86 MessageLoop::current()->AddDestructionObserver(this); | 84 MessageLoop::current()->AddDestructionObserver(this); |
87 | 85 |
88 if (!UpdateWatch()) | 86 if (!UpdateWatch()) |
89 return false; | 87 return false; |
90 | 88 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 watcher_.StopWatching(); | 265 watcher_.StopWatching(); |
268 FindCloseChangeNotification(handle_); | 266 FindCloseChangeNotification(handle_); |
269 handle_ = INVALID_HANDLE_VALUE; | 267 handle_ = INVALID_HANDLE_VALUE; |
270 } | 268 } |
271 | 269 |
272 } // namespace | 270 } // namespace |
273 | 271 |
274 FilePathWatcher::FilePathWatcher() { | 272 FilePathWatcher::FilePathWatcher() { |
275 impl_ = new FilePathWatcherImpl(); | 273 impl_ = new FilePathWatcherImpl(); |
276 } | 274 } |
OLD | NEW |