Index: base/win/registry.h |
diff --git a/base/win/registry.h b/base/win/registry.h |
index af1aee7dce9d56d01cf911444bbf017bd67259eb..1a5152f150384af00045e4ddec7031479c146994 100644 |
--- a/base/win/registry.h |
+++ b/base/win/registry.h |
@@ -12,6 +12,8 @@ |
#include "base/base_export.h" |
#include "base/basictypes.h" |
#include "base/stl_util.h" |
+#include "base/win/object_watcher.h" |
+#include "base/win/scoped_handle.h" |
namespace base { |
namespace win { |
@@ -25,6 +27,10 @@ namespace win { |
// are not touched in case of failure. |
class BASE_EXPORT RegKey { |
public: |
+ // Called from the MessageLoop when the key changes. To continue watching the |
+ // object, StartWatching must be called again. |
+ typedef base::Callback<void()> ChangeCallback; |
+ |
RegKey(); |
explicit RegKey(HKEY key); |
RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
@@ -120,22 +126,18 @@ class BASE_EXPORT RegKey { |
// Starts watching the key to see if any of its values have changed. |
// The key must have been opened with the KEY_NOTIFY access privilege. |
- LONG StartWatching(); |
- |
- // If StartWatching hasn't been called, always returns false. |
- // Otherwise, returns true if anything under the key has changed. |
- // This can't be const because the |watch_event_| may be refreshed. |
- bool HasChanged(); |
+ // Returns true on success. |
+ // To stop watching, delete this RegKey object. |
+ bool StartWatching(const ChangeCallback& callback); |
- // Will automatically be called by destructor if not manually called |
- // beforehand. Returns true if it was watching, false otherwise. |
- LONG StopWatching(); |
- |
- inline bool IsWatching() const { return watch_event_ != 0; } |
- HANDLE watch_event() const { return watch_event_; } |
HKEY Handle() const { return key_; } |
private: |
+ class WatcherDelegate; |
+ |
+ // Internal implementation of StartWatching. |
+ bool StartWatchingInternal(); |
+ |
// Calls RegDeleteKeyEx on supported platforms, alternatively falls back to |
// RegDeleteKey. |
static LONG RegDeleteKeyExWrapper(HKEY hKey, |
@@ -147,9 +149,16 @@ class BASE_EXPORT RegKey { |
static LONG RegDelRecurse(HKEY root_key, |
const std::wstring& name, |
REGSAM access); |
+ |
+ // objectWatcher::Delegate notification. |
+ void OnObjectSignaled(HANDLE object); |
+ |
HKEY key_; // The registry key being iterated. |
- HANDLE watch_event_; |
+ ScopedHandle watch_event_; |
REGSAM wow64access_; |
+ ObjectWatcher object_watcher_; |
+ scoped_ptr<WatcherDelegate> watcher_delegate_; |
+ ChangeCallback callback_; |
DISALLOW_COPY_AND_ASSIGN(RegKey); |
}; |