| 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 "chrome/browser/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 | 22 |
| 23 // Callback from MessageLoopForIO. | 23 // Callback from MessageLoopForIO. |
| 24 virtual void OnObjectSignaled(HANDLE object); | 24 virtual void OnObjectSignaled(HANDLE object); |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 virtual ~FileWatcherImpl(); | 27 virtual ~FileWatcherImpl(); |
| 28 | 28 |
| 29 // Delegate to notify upon changes. | 29 // Delegate to notify upon changes. |
| 30 FileWatcher::Delegate* delegate_; | 30 scoped_refptr<FileWatcher::Delegate> delegate_; |
| 31 | 31 |
| 32 // Path we're watching (passed to delegate). | 32 // Path we're watching (passed to delegate). |
| 33 FilePath path_; | 33 FilePath path_; |
| 34 | 34 |
| 35 // Handle for FindFirstChangeNotification. | 35 // Handle for FindFirstChangeNotification. |
| 36 HANDLE handle_; | 36 HANDLE handle_; |
| 37 | 37 |
| 38 // ObjectWatcher to watch handle_ for events. | 38 // ObjectWatcher to watch handle_ for events. |
| 39 base::ObjectWatcher watcher_; | 39 base::ObjectWatcher watcher_; |
| 40 | 40 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 BOOL ok = FindNextChangeNotification(object); | 102 BOOL ok = FindNextChangeNotification(object); |
| 103 DCHECK(ok); | 103 DCHECK(ok); |
| 104 watcher_.StartWatching(object, this); | 104 watcher_.StartWatching(object, this); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 FileWatcher::FileWatcher() { | 109 FileWatcher::FileWatcher() { |
| 110 impl_ = new FileWatcherImpl(); | 110 impl_ = new FileWatcherImpl(); |
| 111 } | 111 } |
| OLD | NEW |