| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef BASE_WIN_OBJECT_WATCHER_H_ | 5 #ifndef BASE_WIN_OBJECT_WATCHER_H_ |
| 6 #define BASE_WIN_OBJECT_WATCHER_H_ | 6 #define BASE_WIN_OBJECT_WATCHER_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 namespace win { | 18 namespace win { |
| 19 | 19 |
| 20 // A class that provides a means to asynchronously wait for a Windows object to | 20 // A class that provides a means to asynchronously wait for a Windows object to |
| 21 // become signaled. It is an abstraction around RegisterWaitForSingleObject | 21 // become signaled. It is an abstraction around RegisterWaitForSingleObject |
| 22 // that provides a notification callback, OnObjectSignaled, that runs back on | 22 // that provides a notification callback, OnObjectSignaled, that runs back on |
| 23 // the origin sequence (i.e., the sequence that called StartWatching). | 23 // the origin sequence (i.e., the sequence that called StartWatching). |
| 24 // | 24 // |
| 25 // This class acts like a smart pointer such that when it goes out-of-scope, | 25 // This class acts like a smart pointer such that when it goes out-of-scope, |
| 26 // UnregisterWaitEx is automatically called, and any in-flight notification is | 26 // UnregisterWaitEx is automatically called, and any in-flight notification is |
| 27 // suppressed. | 27 // suppressed. |
| 28 // | 28 // |
| 29 // The waiting handle MUST NOT be closed while watching is in progress. If this |
| 30 // handle is closed while the wait is still pending, the behavior is undefined |
| 31 // (see MSDN:RegisterWaitForSingleObject). |
| 32 // |
| 29 // Typical usage: | 33 // Typical usage: |
| 30 // | 34 // |
| 31 // class MyClass : public base::win::ObjectWatcher::Delegate { | 35 // class MyClass : public base::win::ObjectWatcher::Delegate { |
| 32 // public: | 36 // public: |
| 33 // void DoStuffWhenSignaled(HANDLE object) { | 37 // void DoStuffWhenSignaled(HANDLE object) { |
| 34 // watcher_.StartWatchingOnce(object, this); | 38 // watcher_.StartWatchingOnce(object, this); |
| 35 // } | 39 // } |
| 36 // void OnObjectSignaled(HANDLE object) override { | 40 // void OnObjectSignaled(HANDLE object) override { |
| 37 // // OK, time to do stuff! | 41 // // OK, time to do stuff! |
| 38 // } | 42 // } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 122 |
| 119 WeakPtrFactory<ObjectWatcher> weak_factory_; | 123 WeakPtrFactory<ObjectWatcher> weak_factory_; |
| 120 | 124 |
| 121 DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); | 125 DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 } // namespace win | 128 } // namespace win |
| 125 } // namespace base | 129 } // namespace base |
| 126 | 130 |
| 127 #endif // BASE_WIN_OBJECT_WATCHER_H_ | 131 #endif // BASE_WIN_OBJECT_WATCHER_H_ |
| OLD | NEW |