[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / gpu / media / video_accelerator_unittest_helpers.h
blob61e002d73360bf3b4e57f6b9bac5c0cf9cbcd7b8
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.
4 //
5 // This file contains helper classes for video accelerator unittests.
7 #ifndef CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_
8 #define CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_
10 #include <queue>
12 #include "base/synchronization/condition_variable.h"
13 #include "base/synchronization/lock.h"
15 namespace content {
17 // Helper class allowing one thread to wait on a notification from another.
18 // If notifications come in faster than they are Wait()'d for, they are
19 // accumulated (so exactly as many Wait() calls will unblock as Notify() calls
20 // were made, regardless of order).
21 template <typename StateEnum>
22 class ClientStateNotification {
23 public:
24 ClientStateNotification();
25 ~ClientStateNotification();
27 // Used to notify a single waiter of a ClientState.
28 void Notify(StateEnum state);
29 // Used by waiters to wait for the next ClientState Notification.
30 StateEnum Wait();
32 private:
33 base::Lock lock_;
34 base::ConditionVariable cv_;
35 std::queue<StateEnum> pending_states_for_notification_;
38 template <typename StateEnum>
39 ClientStateNotification<StateEnum>::ClientStateNotification() : cv_(&lock_) {}
41 template <typename StateEnum>
42 ClientStateNotification<StateEnum>::~ClientStateNotification() {}
44 template <typename StateEnum>
45 void ClientStateNotification<StateEnum>::Notify(StateEnum state) {
46 base::AutoLock auto_lock(lock_);
47 pending_states_for_notification_.push(state);
48 cv_.Signal();
51 template <typename StateEnum>
52 StateEnum ClientStateNotification<StateEnum>::Wait() {
53 base::AutoLock auto_lock(lock_);
54 while (pending_states_for_notification_.empty())
55 cv_.Wait();
56 StateEnum ret = pending_states_for_notification_.front();
57 pending_states_for_notification_.pop();
58 return ret;
61 } // namespace content
63 #endif // CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_