OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SYNCHRONIZATION_WAITABLE_EVENT_WATCHER_H_ | 5 #ifndef BASE_SYNCHRONIZATION_WAITABLE_EVENT_WATCHER_H_ |
6 #define BASE_SYNCHRONIZATION_WAITABLE_EVENT_WATCHER_H_ | 6 #define BASE_SYNCHRONIZATION_WAITABLE_EVENT_WATCHER_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 class BASE_EXPORT WaitableEventWatcher | 61 class BASE_EXPORT WaitableEventWatcher |
62 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
63 : public win::ObjectWatcher::Delegate { | 63 : public win::ObjectWatcher::Delegate { |
64 #else | 64 #else |
65 : public MessageLoop::DestructionObserver { | 65 : public MessageLoop::DestructionObserver { |
66 #endif | 66 #endif |
67 public: | 67 public: |
68 typedef Callback<void(WaitableEvent*)> EventCallback; | 68 typedef Callback<void(WaitableEvent*)> EventCallback; |
69 WaitableEventWatcher(); | 69 WaitableEventWatcher(); |
70 virtual ~WaitableEventWatcher(); | 70 ~WaitableEventWatcher() override; |
71 | 71 |
72 // When @event is signaled, the given callback is called on the thread of the | 72 // When @event is signaled, the given callback is called on the thread of the |
73 // current message loop when StartWatching is called. | 73 // current message loop when StartWatching is called. |
74 bool StartWatching(WaitableEvent* event, const EventCallback& callback); | 74 bool StartWatching(WaitableEvent* event, const EventCallback& callback); |
75 | 75 |
76 // Cancel the current watch. Must be called from the same thread which | 76 // Cancel the current watch. Must be called from the same thread which |
77 // started the watch. | 77 // started the watch. |
78 // | 78 // |
79 // Does nothing if no event is being watched, nor if the watch has completed. | 79 // Does nothing if no event is being watched, nor if the watch has completed. |
80 // The callback will *not* be called for the current watch after this | 80 // The callback will *not* be called for the current watch after this |
81 // function returns. Since the callback runs on the same thread as this | 81 // function returns. Since the callback runs on the same thread as this |
82 // function, it cannot be called during this function either. | 82 // function, it cannot be called during this function either. |
83 void StopWatching(); | 83 void StopWatching(); |
84 | 84 |
85 // Return the currently watched event, or NULL if no object is currently being | 85 // Return the currently watched event, or NULL if no object is currently being |
86 // watched. | 86 // watched. |
87 WaitableEvent* GetWatchedEvent(); | 87 WaitableEvent* GetWatchedEvent(); |
88 | 88 |
89 // Return the callback that will be invoked when the event is | 89 // Return the callback that will be invoked when the event is |
90 // signaled. | 90 // signaled. |
91 const EventCallback& callback() const { return callback_; } | 91 const EventCallback& callback() const { return callback_; } |
92 | 92 |
93 private: | 93 private: |
94 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
95 virtual void OnObjectSignaled(HANDLE h) override; | 95 virtual void OnObjectSignaled(HANDLE h) override; |
96 win::ObjectWatcher watcher_; | 96 win::ObjectWatcher watcher_; |
97 #else | 97 #else |
98 // Implementation of MessageLoop::DestructionObserver | 98 // Implementation of MessageLoop::DestructionObserver |
99 virtual void WillDestroyCurrentMessageLoop() override; | 99 void WillDestroyCurrentMessageLoop() override; |
100 | 100 |
101 MessageLoop* message_loop_; | 101 MessageLoop* message_loop_; |
102 scoped_refptr<Flag> cancel_flag_; | 102 scoped_refptr<Flag> cancel_flag_; |
103 AsyncWaiter* waiter_; | 103 AsyncWaiter* waiter_; |
104 base::Closure internal_callback_; | 104 base::Closure internal_callback_; |
105 scoped_refptr<WaitableEvent::WaitableEventKernel> kernel_; | 105 scoped_refptr<WaitableEvent::WaitableEventKernel> kernel_; |
106 #endif | 106 #endif |
107 | 107 |
108 WaitableEvent* event_; | 108 WaitableEvent* event_; |
109 EventCallback callback_; | 109 EventCallback callback_; |
110 }; | 110 }; |
111 | 111 |
112 } // namespace base | 112 } // namespace base |
113 | 113 |
114 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_WATCHER_H_ | 114 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_WATCHER_H_ |
OLD | NEW |