Chromium Code Reviews| Index: base/win/registry.h |
| diff --git a/base/win/registry.h b/base/win/registry.h |
| index af1aee7dce9d56d01cf911444bbf017bd67259eb..800bafc41aaf191dc9f2fe6160207637d4acf9d5 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 { |
| @@ -23,8 +25,12 @@ namespace win { |
| // Note: |
| // ReadValue family of functions guarantee that the return arguments |
| // are not touched in case of failure. |
| -class BASE_EXPORT RegKey { |
| +class BASE_EXPORT RegKey : private ObjectWatcher::Delegate { |
|
cpu_(ooo_6.6-7.5)
2014/10/08 21:36:46
do we allow private inheritance?
rvargas (doing something else)
2014/10/08 23:01:45
nope :(
Changed
|
| 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,16 @@ 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(); |
| - |
| - // Will automatically be called by destructor if not manually called |
| - // beforehand. Returns true if it was watching, false otherwise. |
| - LONG StopWatching(); |
| + // Returns true on success. |
| + // To stop watching, delete this RegKey object. |
| + bool StartWatching(const ChangeCallback& callback); |
| - inline bool IsWatching() const { return watch_event_ != 0; } |
| - HANDLE watch_event() const { return watch_event_; } |
| HKEY Handle() const { return key_; } |
| private: |
| + // Internal implementation of StartWatching. |
| + bool StartWatchingInternal(); |
| + |
| // Calls RegDeleteKeyEx on supported platforms, alternatively falls back to |
| // RegDeleteKey. |
| static LONG RegDeleteKeyExWrapper(HKEY hKey, |
| @@ -147,9 +147,15 @@ class BASE_EXPORT RegKey { |
| static LONG RegDelRecurse(HKEY root_key, |
| const std::wstring& name, |
| REGSAM access); |
| + |
| + // Implementation of ObjectWatcher::Delegate. |
| + virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
| + |
| HKEY key_; // The registry key being iterated. |
| - HANDLE watch_event_; |
| + ScopedHandle watch_event_; |
| REGSAM wow64access_; |
| + ObjectWatcher object_watcher_; |
| + ChangeCallback callback_; |
| DISALLOW_COPY_AND_ASSIGN(RegKey); |
| }; |