| 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/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 namespace win { | 15 namespace win { |
| 15 | 16 |
| 16 // 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 |
| 17 // become signaled. It is an abstraction around RegisterWaitForSingleObject | 18 // become signaled. It is an abstraction around RegisterWaitForSingleObject |
| 18 // that provides a notification callback, OnObjectSignaled, that runs back on | 19 // that provides a notification callback, OnObjectSignaled, that runs back on |
| 19 // the origin thread (i.e., the thread that called StartWatching). | 20 // the origin thread (i.e., the thread that called StartWatching). |
| 20 // | 21 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 // } | 35 // } |
| 35 // private: | 36 // private: |
| 36 // base::ObjectWatcher watcher_; | 37 // base::ObjectWatcher watcher_; |
| 37 // }; | 38 // }; |
| 38 // | 39 // |
| 39 // 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 |
| 40 // signaled. ObjectWatcher makes this task easy. When MyClass goes out of | 41 // signaled. ObjectWatcher makes this task easy. When MyClass goes out of |
| 41 // 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 |
| 42 // OnObjectSignaled being called on a deleted MyClass pointer. Easy! | 43 // OnObjectSignaled being called on a deleted MyClass pointer. Easy! |
| 43 // | 44 // |
| 44 class ObjectWatcher : public MessageLoop::DestructionObserver { | 45 class BASE_API ObjectWatcher : public MessageLoop::DestructionObserver { |
| 45 public: | 46 public: |
| 46 class Delegate { | 47 class Delegate { |
| 47 public: | 48 public: |
| 48 virtual ~Delegate() {} | 49 virtual ~Delegate() {} |
| 49 // Called from the MessageLoop when a signaled object is detected. To | 50 // Called from the MessageLoop when a signaled object is detected. To |
| 50 // continue watching the object, AddWatch must be called again. | 51 // continue watching the object, AddWatch must be called again. |
| 51 virtual void OnObjectSignaled(HANDLE object) = 0; | 52 virtual void OnObjectSignaled(HANDLE object) = 0; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 ObjectWatcher(); | 55 ObjectWatcher(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 85 struct Watch; | 86 struct Watch; |
| 86 Watch* watch_; | 87 Watch* watch_; |
| 87 | 88 |
| 88 DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); | 89 DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 } // namespace win | 92 } // namespace win |
| 92 } // namespace base | 93 } // namespace base |
| 93 | 94 |
| 94 #endif // BASE_OBJECT_WATCHER_H_ | 95 #endif // BASE_OBJECT_WATCHER_H_ |
| OLD | NEW |