Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/waitable_event_watcher.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "base/compiler_specific.h" |
michael@0 | 8 | #include "base/object_watcher.h" |
michael@0 | 9 | #include "base/waitable_event.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace base { |
michael@0 | 12 | |
michael@0 | 13 | WaitableEventWatcher::ObjectWatcherHelper::ObjectWatcherHelper( |
michael@0 | 14 | WaitableEventWatcher* watcher) |
michael@0 | 15 | : watcher_(watcher) { |
michael@0 | 16 | }; |
michael@0 | 17 | |
michael@0 | 18 | void WaitableEventWatcher::ObjectWatcherHelper::OnObjectSignaled(HANDLE h) { |
michael@0 | 19 | watcher_->OnObjectSignaled(); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | WaitableEventWatcher::WaitableEventWatcher() |
michael@0 | 24 | : event_(NULL), |
michael@0 | 25 | ALLOW_THIS_IN_INITIALIZER_LIST(helper_(this)), |
michael@0 | 26 | delegate_(NULL) { |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | WaitableEventWatcher::~WaitableEventWatcher() { |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | bool WaitableEventWatcher::StartWatching(WaitableEvent* event, |
michael@0 | 33 | Delegate* delegate) { |
michael@0 | 34 | delegate_ = delegate; |
michael@0 | 35 | event_ = event; |
michael@0 | 36 | |
michael@0 | 37 | return watcher_.StartWatching(event->handle(), &helper_); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | void WaitableEventWatcher::StopWatching() { |
michael@0 | 41 | delegate_ = NULL; |
michael@0 | 42 | event_ = NULL; |
michael@0 | 43 | watcher_.StopWatching(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | WaitableEvent* WaitableEventWatcher::GetWatchedEvent() { |
michael@0 | 47 | return event_; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | void WaitableEventWatcher::OnObjectSignaled() { |
michael@0 | 51 | WaitableEvent* event = event_; |
michael@0 | 52 | Delegate* delegate = delegate_; |
michael@0 | 53 | event_ = NULL; |
michael@0 | 54 | delegate_ = NULL; |
michael@0 | 55 | DCHECK(event); |
michael@0 | 56 | |
michael@0 | 57 | delegate->OnWaitableEventSignaled(event); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | } // namespace base |