Reset on-screen keyboard on a change to the active user.
[chromium-blink-merge.git] / mojo / system / waiter_list.cc
blob6f2c44411eb10d89fef8229a30fa51e3b3b73665
1 // Copyright 2013 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 "mojo/system/waiter_list.h"
7 #include "base/logging.h"
8 #include "mojo/system/waiter.h"
10 namespace mojo {
11 namespace system {
13 WaiterList::WaiterList() {
16 WaiterList::~WaiterList() {
17 DCHECK(waiters_.empty());
20 void WaiterList::AwakeWaitersForStateChange(MojoWaitFlags satisfied_flags,
21 MojoWaitFlags satisfiable_flags) {
22 for (WaiterInfoList::iterator it = waiters_.begin(); it != waiters_.end();
23 ++it) {
24 if (it->flags & satisfied_flags)
25 it->waiter->Awake(it->wake_result);
26 else if (!(it->flags & satisfiable_flags))
27 it->waiter->Awake(MOJO_RESULT_FAILED_PRECONDITION);
31 void WaiterList::CancelAllWaiters() {
32 for (WaiterInfoList::iterator it = waiters_.begin(); it != waiters_.end();
33 ++it) {
34 it->waiter->Awake(MOJO_RESULT_CANCELLED);
36 waiters_.clear();
39 void WaiterList::AddWaiter(Waiter* waiter,
40 MojoWaitFlags flags,
41 MojoResult wake_result) {
42 waiters_.push_back(WaiterInfo(waiter, flags, wake_result));
45 void WaiterList::RemoveWaiter(Waiter* waiter) {
46 // We allow a thread to wait on the same handle multiple times simultaneously,
47 // so we need to scan the entire list and remove all occurrences of |waiter|.
48 for (WaiterInfoList::iterator it = waiters_.begin(); it != waiters_.end();) {
49 WaiterInfoList::iterator maybe_delete = it;
50 ++it;
51 if (maybe_delete->waiter == waiter)
52 waiters_.erase(maybe_delete);
56 } // namespace system
57 } // namespace mojo