Chromium Code Reviews| Index: chrome/browser/sync/test/integration/status_change_checker.cc |
| diff --git a/chrome/browser/sync/test/integration/status_change_checker.cc b/chrome/browser/sync/test/integration/status_change_checker.cc |
| index b92b06a9abd3d7f237c9c24070384bcc3952f400..94c966e59ea3ad08d4973ae488930dfdde58949f 100644 |
| --- a/chrome/browser/sync/test/integration/status_change_checker.cc |
| +++ b/chrome/browser/sync/test/integration/status_change_checker.cc |
| @@ -4,6 +4,55 @@ |
| #include "chrome/browser/sync/test/integration/status_change_checker.h" |
| -StatusChangeChecker::StatusChangeChecker() {} |
| +#include "base/logging.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/timer/timer.h" |
| + |
| +StatusChangeChecker::StatusChangeChecker() |
| + : timed_out_(false), |
| + wait_started_(false) {} |
| StatusChangeChecker::~StatusChangeChecker() {} |
| + |
| +bool StatusChangeChecker::TimedOut() const { |
| + return timed_out_; |
| +} |
| + |
| +base::TimeDelta StatusChangeChecker::GetTimeoutDuration() { |
| + return base::TimeDelta::FromSeconds(45); |
| +} |
| + |
| +void StatusChangeChecker::StartBlockingWait() { |
| + DCHECK(!wait_started_) << "This class is intended for one use only."; |
|
pval...(no longer on Chromium)
2014/05/22 21:07:12
document this one-time use restriction in the clas
rlarocque
2014/05/22 21:29:30
The old class comment was stale. Fixed it and add
|
| + wait_started_ = true; |
| + |
| + base::OneShotTimer<StatusChangeChecker> timer; |
| + timer.Start(FROM_HERE, |
| + GetTimeoutDuration(), |
| + base::Bind(&StatusChangeChecker::OnTimeout, |
| + base::Unretained(this))); |
| + |
| + { |
| + base::MessageLoop* loop = base::MessageLoop::current(); |
| + base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| + loop->Run(); |
| + } |
| +} |
| + |
| +void StatusChangeChecker::Unblock() { |
| + base::MessageLoop::current()->QuitWhenIdle(); |
| +} |
| + |
| +void StatusChangeChecker::CheckExitCondition() { |
| + DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); |
| + if (IsExitConditionSatisfied()) { |
| + DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); |
| + Unblock(); |
| + } |
| +} |
| + |
| +void StatusChangeChecker::OnTimeout() { |
| + DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); |
| + timed_out_ = true; |
| + Unblock(); |
| +} |