| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/multi_client_status_change_checke
r.h" | 5 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/scoped_observer.h" | 8 #include "base/scoped_observer.h" |
| 9 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
| 10 | 10 |
| 11 MultiClientStatusChangeChecker::MultiClientStatusChangeChecker( | 11 MultiClientStatusChangeChecker::MultiClientStatusChangeChecker( |
| 12 std::vector<ProfileSyncService*> services) | 12 std::vector<ProfileSyncService*> services) |
| 13 : services_(services), timed_out_(false) {} | 13 : services_(services) {} |
| 14 | 14 |
| 15 MultiClientStatusChangeChecker::~MultiClientStatusChangeChecker() {} | 15 MultiClientStatusChangeChecker::~MultiClientStatusChangeChecker() {} |
| 16 | 16 |
| 17 base::TimeDelta MultiClientStatusChangeChecker::GetTimeoutDuration() { | |
| 18 return base::TimeDelta::FromSeconds(45); | |
| 19 } | |
| 20 void MultiClientStatusChangeChecker::OnTimeout() { | |
| 21 DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); | |
| 22 timed_out_ = true; | |
| 23 base::MessageLoop::current()->QuitWhenIdle(); | |
| 24 } | |
| 25 | |
| 26 void MultiClientStatusChangeChecker::Wait() { | 17 void MultiClientStatusChangeChecker::Wait() { |
| 27 DVLOG(1) << "Await: " << GetDebugMessage(); | 18 DVLOG(1) << "Await: " << GetDebugMessage(); |
| 28 | 19 |
| 29 if (IsExitConditionSatisfied()) { | 20 if (IsExitConditionSatisfied()) { |
| 30 DVLOG(1) << "Await -> Exit before waiting: " << GetDebugMessage(); | 21 DVLOG(1) << "Await -> Exit before waiting: " << GetDebugMessage(); |
| 31 return; | 22 return; |
| 32 } | 23 } |
| 33 | 24 |
| 34 ScopedObserver<ProfileSyncService, MultiClientStatusChangeChecker> obs(this); | 25 ScopedObserver<ProfileSyncService, MultiClientStatusChangeChecker> obs(this); |
| 35 for (std::vector<ProfileSyncService*>::iterator it = services_.begin(); | 26 for (std::vector<ProfileSyncService*>::iterator it = services_.begin(); |
| 36 it != services_.end(); ++it) { | 27 it != services_.end(); ++it) { |
| 37 obs.Add(*it); | 28 obs.Add(*it); |
| 38 } | 29 } |
| 39 | 30 |
| 40 base::OneShotTimer<MultiClientStatusChangeChecker> timer; | 31 StartBlockingWait(); |
| 41 timer.Start(FROM_HERE, | |
| 42 GetTimeoutDuration(), | |
| 43 base::Bind(&MultiClientStatusChangeChecker::OnTimeout, | |
| 44 base::Unretained(this))); | |
| 45 | |
| 46 { | |
| 47 base::MessageLoop* loop = base::MessageLoop::current(); | |
| 48 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
| 49 loop->Run(); | |
| 50 } | |
| 51 } | 32 } |
| 52 | 33 |
| 53 void MultiClientStatusChangeChecker::OnStateChanged() { | 34 void MultiClientStatusChangeChecker::OnStateChanged() { |
| 54 DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); | 35 CheckExitCondition(); |
| 55 if (IsExitConditionSatisfied()) { | |
| 56 DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); | |
| 57 base::MessageLoop::current()->QuitWhenIdle(); | |
| 58 } | |
| 59 } | 36 } |
| 60 | |
| 61 bool MultiClientStatusChangeChecker::TimedOut() { | |
| 62 return timed_out_; | |
| 63 } | |
| OLD | NEW |