| 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 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" |
| 9 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 10 | 11 |
| 11 StatusChangeChecker::StatusChangeChecker() : timed_out_(false) { | 12 StatusChangeChecker::StatusChangeChecker() : timed_out_(false) { |
| 12 } | 13 } |
| 13 | 14 |
| 14 StatusChangeChecker::~StatusChangeChecker() {} | 15 StatusChangeChecker::~StatusChangeChecker() {} |
| 15 | 16 |
| 16 bool StatusChangeChecker::TimedOut() const { | 17 bool StatusChangeChecker::TimedOut() const { |
| 17 return timed_out_; | 18 return timed_out_; |
| 18 } | 19 } |
| 19 | 20 |
| 20 base::TimeDelta StatusChangeChecker::GetTimeoutDuration() { | 21 base::TimeDelta StatusChangeChecker::GetTimeoutDuration() { |
| 21 return base::TimeDelta::FromSeconds(45); | 22 return base::TimeDelta::FromSeconds(45); |
| 22 } | 23 } |
| 23 | 24 |
| 24 void StatusChangeChecker::StartBlockingWait() { | 25 void StatusChangeChecker::StartBlockingWait() { |
| 25 base::OneShotTimer timer; | 26 base::OneShotTimer timer; |
| 26 timer.Start(FROM_HERE, | 27 timer.Start(FROM_HERE, |
| 27 GetTimeoutDuration(), | 28 GetTimeoutDuration(), |
| 28 base::Bind(&StatusChangeChecker::OnTimeout, | 29 base::Bind(&StatusChangeChecker::OnTimeout, |
| 29 base::Unretained(this))); | 30 base::Unretained(this))); |
| 30 | 31 |
| 31 { | 32 { |
| 32 base::MessageLoop* loop = base::MessageLoop::current(); | 33 base::MessageLoop* loop = base::MessageLoop::current(); |
| 33 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | 34 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 34 loop->Run(); | 35 base::RunLoop().Run(); |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 void StatusChangeChecker::StopWaiting() { | 39 void StatusChangeChecker::StopWaiting() { |
| 39 base::MessageLoop::current()->QuitWhenIdle(); | 40 base::MessageLoop::current()->QuitWhenIdle(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void StatusChangeChecker::CheckExitCondition() { | 43 void StatusChangeChecker::CheckExitCondition() { |
| 43 DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); | 44 DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); |
| 44 if (IsExitConditionSatisfied()) { | 45 if (IsExitConditionSatisfied()) { |
| 45 DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); | 46 DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); |
| 46 StopWaiting(); | 47 StopWaiting(); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 void StatusChangeChecker::OnTimeout() { | 51 void StatusChangeChecker::OnTimeout() { |
| 51 DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); | 52 DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); |
| 52 timed_out_ = true; | 53 timed_out_ = true; |
| 53 StopWaiting(); | 54 StopWaiting(); |
| 54 } | 55 } |
| OLD | NEW |