| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 | 10 |
| 11 #include "base/base_api.h" | 11 #include "base/base_export.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 namespace win { | 15 namespace win { |
| 16 | 16 |
| 17 // A class that provides a means to asynchronously wait for a Windows object to | 17 // A class that provides a means to asynchronously wait for a Windows object to |
| 18 // become signaled. It is an abstraction around RegisterWaitForSingleObject | 18 // become signaled. It is an abstraction around RegisterWaitForSingleObject |
| 19 // that provides a notification callback, OnObjectSignaled, that runs back on | 19 // that provides a notification callback, OnObjectSignaled, that runs back on |
| 20 // the origin thread (i.e., the thread that called StartWatching). | 20 // the origin thread (i.e., the thread that called StartWatching). |
| 21 // | 21 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 // } | 35 // } |
| 36 // private: | 36 // private: |
| 37 // base::ObjectWatcher watcher_; | 37 // base::ObjectWatcher watcher_; |
| 38 // }; | 38 // }; |
| 39 // | 39 // |
| 40 // In the above example, MyClass wants to "do stuff" when object becomes | 40 // In the above example, MyClass wants to "do stuff" when object becomes |
| 41 // signaled. ObjectWatcher makes this task easy. When MyClass goes out of | 41 // signaled. ObjectWatcher makes this task easy. When MyClass goes out of |
| 42 // scope, the watcher_ will be destroyed, and there is no need to worry about | 42 // scope, the watcher_ will be destroyed, and there is no need to worry about |
| 43 // OnObjectSignaled being called on a deleted MyClass pointer. Easy! | 43 // OnObjectSignaled being called on a deleted MyClass pointer. Easy! |
| 44 // | 44 // |
| 45 class BASE_API ObjectWatcher : public MessageLoop::DestructionObserver { | 45 class BASE_EXPORT ObjectWatcher : public MessageLoop::DestructionObserver { |
| 46 public: | 46 public: |
| 47 class BASE_API Delegate { | 47 class BASE_EXPORT Delegate { |
| 48 public: | 48 public: |
| 49 virtual ~Delegate() {} | 49 virtual ~Delegate() {} |
| 50 // Called from the MessageLoop when a signaled object is detected. To | 50 // Called from the MessageLoop when a signaled object is detected. To |
| 51 // continue watching the object, StartWatching must be called again. | 51 // continue watching the object, StartWatching must be called again. |
| 52 virtual void OnObjectSignaled(HANDLE object) = 0; | 52 virtual void OnObjectSignaled(HANDLE object) = 0; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 ObjectWatcher(); | 55 ObjectWatcher(); |
| 56 ~ObjectWatcher(); | 56 ~ObjectWatcher(); |
| 57 | 57 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 86 struct Watch; | 86 struct Watch; |
| 87 Watch* watch_; | 87 Watch* watch_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); | 89 DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace win | 92 } // namespace win |
| 93 } // namespace base | 93 } // namespace base |
| 94 | 94 |
| 95 #endif // BASE_OBJECT_WATCHER_H_ | 95 #endif // BASE_OBJECT_WATCHER_H_ |
| OLD | NEW |