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 "chrome/test/remoting/waiter.h"
7 #include "content/public/test/test_utils.h"
11 TimeoutWaiter::TimeoutWaiter(base::TimeDelta timeout
)
13 DCHECK(timeout
> base::TimeDelta::FromSeconds(0));
16 TimeoutWaiter::~TimeoutWaiter() {}
18 bool TimeoutWaiter::Wait() {
19 DCHECK(!timeout_timer_
.IsRunning());
24 base::Bind(&TimeoutWaiter::CancelWaitCallback
, base::Unretained(this)));
26 message_loop_runner_
= new content::MessageLoopRunner
;
27 message_loop_runner_
->Run();
32 void TimeoutWaiter::CancelWait() {
33 message_loop_runner_
->Quit();
36 void TimeoutWaiter::CancelWaitCallback() {
40 ConditionalTimeoutWaiter::ConditionalTimeoutWaiter(base::TimeDelta timeout
,
41 base::TimeDelta interval
,
42 const Predicate
& callback
)
43 : TimeoutWaiter(timeout
),
47 DCHECK(timeout
> interval
);
50 ConditionalTimeoutWaiter::~ConditionalTimeoutWaiter() {}
52 bool ConditionalTimeoutWaiter::Wait() {
53 DCHECK(!condition_timer_
.IsRunning());
55 condition_timer_
.Start(
58 base::Bind(&ConditionalTimeoutWaiter::CancelWaitCallback
,
59 base::Unretained(this)));
61 // Also call the base class Wait() to start the timeout timer.
62 TimeoutWaiter::Wait();
67 void ConditionalTimeoutWaiter::CancelWait() {
68 condition_timer_
.Stop();
70 // Also call the base class CancelWait() to stop the timeout timer.
71 TimeoutWaiter::CancelWait();
74 void ConditionalTimeoutWaiter::CancelWaitCallback() {
75 if (callback_
.Run()) {
81 } // namespace remoting