single_client_status_change_checker.cc revision effb81e5f8246d0db0270817048dc992db66e9fb
1// Copyright 2014 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#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h" 6 7#include "base/logging.h" 8#include "base/scoped_observer.h" 9#include "chrome/browser/sync/profile_sync_service.h" 10#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 11 12SingleClientStatusChangeChecker::SingleClientStatusChangeChecker( 13 ProfileSyncService* service) : service_(service), timed_out_(false) {} 14 15SingleClientStatusChangeChecker::~SingleClientStatusChangeChecker() {} 16 17base::TimeDelta SingleClientStatusChangeChecker::GetTimeoutDuration() { 18 return base::TimeDelta::FromSeconds(45); 19} 20void SingleClientStatusChangeChecker::OnTimeout() { 21 DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); 22 timed_out_ = true; 23 base::MessageLoop::current()->QuitWhenIdle(); 24} 25 26void SingleClientStatusChangeChecker::Await() { 27 DVLOG(1) << "Await: " << GetDebugMessage(); 28 29 if (IsExitConditionSatisfied()) { 30 DVLOG(1) << "Await -> Exit before waiting: " << GetDebugMessage(); 31 return; 32 } 33 34 ScopedObserver<ProfileSyncService, SingleClientStatusChangeChecker> obs(this); 35 obs.Add(service()); 36 37 base::OneShotTimer<SingleClientStatusChangeChecker> timer; 38 timer.Start(FROM_HERE, 39 GetTimeoutDuration(), 40 base::Bind(&SingleClientStatusChangeChecker::OnTimeout, 41 base::Unretained(this))); 42 43 { 44 base::MessageLoop* loop = base::MessageLoop::current(); 45 base::MessageLoop::ScopedNestableTaskAllower allow(loop); 46 loop->Run(); 47 } 48} 49 50void SingleClientStatusChangeChecker::OnStateChanged() { 51 DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); 52 if (IsExitConditionSatisfied()) { 53 DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); 54 base::MessageLoop::current()->QuitWhenIdle(); 55 } 56} 57 58bool SingleClientStatusChangeChecker::TimedOut() { 59 return timed_out_; 60} 61