MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / base / synchronization / waitable_event_watcher_win.cc
blobdc14e64ced7c3a8bfbeac282e0afe7ca1b55bb02
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
3 // found in the LICENSE file.
5 #include "base/synchronization/waitable_event_watcher.h"
7 #include "base/compiler_specific.h"
8 #include "base/profiler/scoped_profile.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "base/win/object_watcher.h"
12 namespace base {
14 WaitableEventWatcher::WaitableEventWatcher()
15 : event_(NULL) {
18 WaitableEventWatcher::~WaitableEventWatcher() {
21 bool WaitableEventWatcher::StartWatching(
22 WaitableEvent* event,
23 const EventCallback& callback) {
24 callback_ = callback;
25 event_ = event;
26 return watcher_.StartWatching(event->handle(), this);
29 void WaitableEventWatcher::StopWatching() {
30 callback_.Reset();
31 event_ = NULL;
32 watcher_.StopWatching();
35 WaitableEvent* WaitableEventWatcher::GetWatchedEvent() {
36 return event_;
39 void WaitableEventWatcher::OnObjectSignaled(HANDLE h) {
40 // TODO(vadimt): Remove ScopedProfile below once crbug.com/418183 is fixed.
41 tracked_objects::ScopedProfile tracking_profile(
42 FROM_HERE_WITH_EXPLICIT_FUNCTION(
43 "WaitableEventWatche_OnObjectSignaled"));
45 WaitableEvent* event = event_;
46 EventCallback callback = callback_;
47 event_ = NULL;
48 callback_.Reset();
49 DCHECK(event);
51 callback.Run(event);
54 } // namespace base