OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/test/integration/status_change_checker.h" | 5 #include "chrome/browser/sync/test/integration/status_change_checker.h" |
6 | 6 |
7 StatusChangeChecker::StatusChangeChecker() {} | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/timer/timer.h" |
| 10 |
| 11 StatusChangeChecker::StatusChangeChecker() |
| 12 : timed_out_(false), |
| 13 wait_started_(false) {} |
8 | 14 |
9 StatusChangeChecker::~StatusChangeChecker() {} | 15 StatusChangeChecker::~StatusChangeChecker() {} |
| 16 |
| 17 bool StatusChangeChecker::TimedOut() const { |
| 18 return timed_out_; |
| 19 } |
| 20 |
| 21 base::TimeDelta StatusChangeChecker::GetTimeoutDuration() { |
| 22 return base::TimeDelta::FromSeconds(45); |
| 23 } |
| 24 |
| 25 void StatusChangeChecker::StartBlockingWait() { |
| 26 DCHECK(!wait_started_) << "This class is intended for one use only."; |
| 27 wait_started_ = true; |
| 28 |
| 29 base::OneShotTimer<StatusChangeChecker> timer; |
| 30 timer.Start(FROM_HERE, |
| 31 GetTimeoutDuration(), |
| 32 base::Bind(&StatusChangeChecker::OnTimeout, |
| 33 base::Unretained(this))); |
| 34 |
| 35 { |
| 36 base::MessageLoop* loop = base::MessageLoop::current(); |
| 37 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 38 loop->Run(); |
| 39 } |
| 40 } |
| 41 |
| 42 void StatusChangeChecker::StopWaiting() { |
| 43 base::MessageLoop::current()->QuitWhenIdle(); |
| 44 } |
| 45 |
| 46 void StatusChangeChecker::CheckExitCondition() { |
| 47 DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); |
| 48 if (IsExitConditionSatisfied()) { |
| 49 DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); |
| 50 StopWaiting(); |
| 51 } |
| 52 } |
| 53 |
| 54 void StatusChangeChecker::OnTimeout() { |
| 55 DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); |
| 56 timed_out_ = true; |
| 57 StopWaiting(); |
| 58 } |
OLD | NEW |