OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/file_watcher.h" | 5 #include "chrome/browser/file_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/object_watcher.h" | 10 #include "base/object_watcher.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class FileWatcherImpl : public FileWatcher::PlatformDelegate, | 16 class FileWatcherImpl : public FileWatcher::PlatformDelegate, |
17 public base::ObjectWatcher::Delegate { | 17 public base::ObjectWatcher::Delegate { |
18 public: | 18 public: |
19 FileWatcherImpl() : delegate_(NULL), handle_(INVALID_HANDLE_VALUE) {} | 19 FileWatcherImpl() : delegate_(NULL), handle_(INVALID_HANDLE_VALUE) {} |
20 | 20 |
21 virtual bool Watch(const FilePath& path, FileWatcher::Delegate* delegate, | 21 virtual bool Watch(const FilePath& path, FileWatcher::Delegate* delegate); |
22 MessageLoop* backend_loop); | |
23 | 22 |
24 // Callback from MessageLoopForIO. | 23 // Callback from MessageLoopForIO. |
25 virtual void OnObjectSignaled(HANDLE object); | 24 virtual void OnObjectSignaled(HANDLE object); |
26 | 25 |
27 private: | 26 private: |
28 virtual ~FileWatcherImpl(); | 27 virtual ~FileWatcherImpl(); |
29 | 28 |
30 // Delegate to notify upon changes. | 29 // Delegate to notify upon changes. |
31 FileWatcher::Delegate* delegate_; | 30 FileWatcher::Delegate* delegate_; |
32 | 31 |
(...skipping 14 matching lines...) Expand all Loading... |
47 }; | 46 }; |
48 | 47 |
49 FileWatcherImpl::~FileWatcherImpl() { | 48 FileWatcherImpl::~FileWatcherImpl() { |
50 if (handle_ != INVALID_HANDLE_VALUE) { | 49 if (handle_ != INVALID_HANDLE_VALUE) { |
51 watcher_.StopWatching(); | 50 watcher_.StopWatching(); |
52 FindCloseChangeNotification(handle_); | 51 FindCloseChangeNotification(handle_); |
53 } | 52 } |
54 } | 53 } |
55 | 54 |
56 bool FileWatcherImpl::Watch(const FilePath& path, | 55 bool FileWatcherImpl::Watch(const FilePath& path, |
57 FileWatcher::Delegate* delegate, | 56 FileWatcher::Delegate* delegate) { |
58 MessageLoop* backend_loop) { | |
59 DCHECK(path_.value().empty()); // Can only watch one path. | 57 DCHECK(path_.value().empty()); // Can only watch one path. |
60 file_util::FileInfo file_info; | 58 file_util::FileInfo file_info; |
61 if (file_util::GetFileInfo(path, &file_info)) | 59 if (file_util::GetFileInfo(path, &file_info)) |
62 last_modified_ = file_info.last_modified; | 60 last_modified_ = file_info.last_modified; |
63 | 61 |
64 // FindFirstChangeNotification watches directories, so use the parent path. | 62 // FindFirstChangeNotification watches directories, so use the parent path. |
65 handle_ = FindFirstChangeNotification( | 63 handle_ = FindFirstChangeNotification( |
66 path.DirName().value().c_str(), | 64 path.DirName().value().c_str(), |
67 false, // Don't watch subtrees | 65 false, // Don't watch subtrees |
68 FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | | 66 FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 BOOL ok = FindNextChangeNotification(object); | 102 BOOL ok = FindNextChangeNotification(object); |
105 DCHECK(ok); | 103 DCHECK(ok); |
106 watcher_.StartWatching(object, this); | 104 watcher_.StartWatching(object, this); |
107 } | 105 } |
108 | 106 |
109 } // namespace | 107 } // namespace |
110 | 108 |
111 FileWatcher::FileWatcher() { | 109 FileWatcher::FileWatcher() { |
112 impl_ = new FileWatcherImpl(); | 110 impl_ = new FileWatcherImpl(); |
113 } | 111 } |
OLD | NEW |