| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This module provides a way to monitor a file for changes. | 5 // This module provides a way to monitor a file for changes. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_FILE_WATCHER_H_ | 7 #ifndef CHROME_BROWSER_FILE_WATCHER_H_ |
| 8 #define CHROME_BROWSER_FILE_WATCHER_H_ | 8 #define CHROME_BROWSER_FILE_WATCHER_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "chrome/browser/chrome_thread.h" | 13 #include "chrome/browser/chrome_thread.h" |
| 14 | 14 |
| 15 class FilePath; | 15 class FilePath; |
| 16 | 16 |
| 17 // This class lets you register interest in changes on a file. The delegate | 17 // This class lets you register interest in changes on a file. The delegate |
| 18 // will get called whenever the file is changed, including created or deleted. | 18 // will get called whenever the file is changed, including created or deleted. |
| 19 // WARNING: To be able to get create/delete notifications and to work cross | 19 // WARNING: To be able to get create/delete notifications and to work cross |
| 20 // platform, we actually listen for changes to the directory containing | 20 // platform, we actually listen for changes to the directory containing |
| 21 // the file. | 21 // the file. |
| 22 // WARNING: On OSX and Windows, the OS API doesn't tell us which file in the | 22 // WARNING: On OSX and Windows, the OS API doesn't tell us which file in the |
| 23 // directory changed. We work around this by watching the file time, but this | 23 // directory changed. We work around this by watching the file time, but this |
| 24 // can result in some extra notifications if we get other notifications within | 24 // can result in some extra notifications if we get other notifications within |
| 25 // 2s of the file having changed. | 25 // 2s of the file having changed. |
| 26 class FileWatcher { | 26 class FileWatcher { |
| 27 public: | 27 public: |
| 28 class Delegate { | 28 // Declares the callback client code implements to receive notifications. Note |
| 29 // that implementations of this interface should not keep a reference to the |
| 30 // corresponding FileWatcher object to prevent a reference cycle. |
| 31 class Delegate : public base::RefCountedThreadSafe<Delegate> { |
| 29 public: | 32 public: |
| 30 virtual ~Delegate() {} | 33 virtual ~Delegate() {} |
| 31 virtual void OnFileChanged(const FilePath& path) = 0; | 34 virtual void OnFileChanged(const FilePath& path) = 0; |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 FileWatcher(); | 37 FileWatcher(); |
| 35 ~FileWatcher() {} | 38 ~FileWatcher() {} |
| 36 | 39 |
| 37 // Register interest in any changes on the file |path|. | 40 // Register interest in any changes on the file |path|. |
| 38 // OnFileChanged will be called back for each change to the file. Any | 41 // OnFileChanged will be called back for each change to the file. Any |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 virtual bool Watch(const FilePath& path, Delegate* delegate) = 0; | 57 virtual bool Watch(const FilePath& path, Delegate* delegate) = 0; |
| 55 }; | 58 }; |
| 56 | 59 |
| 57 private: | 60 private: |
| 58 scoped_refptr<PlatformDelegate> impl_; | 61 scoped_refptr<PlatformDelegate> impl_; |
| 59 | 62 |
| 60 DISALLOW_COPY_AND_ASSIGN(FileWatcher); | 63 DISALLOW_COPY_AND_ASSIGN(FileWatcher); |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 #endif // CHROME_BROWSER_FILE_WATCHER_H_ | 66 #endif // CHROME_BROWSER_FILE_WATCHER_H_ |
| OLD | NEW |