| 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/quiesce_status_change_checker.h" | 5 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/scoped_observer.h" | 8 #include "base/scoped_observer.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 bool ProgressMarkerWatcher::HasLatestProgressMarkers() { | 138 bool ProgressMarkerWatcher::HasLatestProgressMarkers() { |
| 139 return probably_has_latest_progress_markers_; | 139 return probably_has_latest_progress_markers_; |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool ProgressMarkerWatcher::IsSyncDisabled() { | 142 bool ProgressMarkerWatcher::IsSyncDisabled() { |
| 143 return ::IsSyncDisabled(service_); | 143 return ::IsSyncDisabled(service_); |
| 144 } | 144 } |
| 145 | 145 |
| 146 QuiesceStatusChangeChecker::QuiesceStatusChangeChecker( | 146 QuiesceStatusChangeChecker::QuiesceStatusChangeChecker( |
| 147 std::vector<ProfileSyncService*> services) | 147 std::vector<ProfileSyncService*> services) |
| 148 : services_(services), timed_out_(false) { | 148 : services_(services) { |
| 149 DCHECK_LE(1U, services_.size()); | 149 DCHECK_LE(1U, services_.size()); |
| 150 for (size_t i = 0; i < services_.size(); ++i) { | 150 for (size_t i = 0; i < services_.size(); ++i) { |
| 151 observers_.push_back(new ProgressMarkerWatcher(services[i], this)); | 151 observers_.push_back(new ProgressMarkerWatcher(services[i], this)); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 QuiesceStatusChangeChecker::~QuiesceStatusChangeChecker() {} | 155 QuiesceStatusChangeChecker::~QuiesceStatusChangeChecker() {} |
| 156 | 156 |
| 157 base::TimeDelta QuiesceStatusChangeChecker::GetTimeoutDuration() { | |
| 158 return base::TimeDelta::FromSeconds(45); | |
| 159 } | |
| 160 | |
| 161 void QuiesceStatusChangeChecker::Wait() { | 157 void QuiesceStatusChangeChecker::Wait() { |
| 162 DVLOG(1) << "Await: " << GetDebugMessage(); | 158 DVLOG(1) << "Await: " << GetDebugMessage(); |
| 163 | 159 |
| 164 if (IsExitConditionSatisfied()) { | 160 if (IsExitConditionSatisfied()) { |
| 165 DVLOG(1) << "Await -> Exit before waiting: " << GetDebugMessage(); | 161 DVLOG(1) << "Await -> Exit before waiting: " << GetDebugMessage(); |
| 166 return; | 162 return; |
| 167 } | 163 } |
| 168 | 164 |
| 169 base::OneShotTimer<QuiesceStatusChangeChecker> timer; | 165 StartBlockingWait(); |
| 170 timer.Start(FROM_HERE, | |
| 171 GetTimeoutDuration(), | |
| 172 base::Bind(&QuiesceStatusChangeChecker::OnTimeout, | |
| 173 base::Unretained(this))); | |
| 174 | |
| 175 { | |
| 176 base::MessageLoop* loop = base::MessageLoop::current(); | |
| 177 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
| 178 loop->Run(); | |
| 179 } | |
| 180 } | 166 } |
| 181 | 167 |
| 182 bool QuiesceStatusChangeChecker::IsExitConditionSatisfied() { | 168 bool QuiesceStatusChangeChecker::IsExitConditionSatisfied() { |
| 183 // Check that all progress markers are up to date. | 169 // Check that all progress markers are up to date. |
| 184 for (ScopedVector<ProgressMarkerWatcher>::const_iterator it = | 170 for (ScopedVector<ProgressMarkerWatcher>::const_iterator it = |
| 185 observers_.begin(); it != observers_.end(); ++it) { | 171 observers_.begin(); it != observers_.end(); ++it) { |
| 186 if ((*it)->IsSyncDisabled()) { | 172 if ((*it)->IsSyncDisabled()) { |
| 187 continue; // Skip disabled services. | 173 continue; // Skip disabled services. |
| 188 } | 174 } |
| 189 | 175 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return true; | 211 return true; |
| 226 } | 212 } |
| 227 | 213 |
| 228 std::string QuiesceStatusChangeChecker::GetDebugMessage() const { | 214 std::string QuiesceStatusChangeChecker::GetDebugMessage() const { |
| 229 return base::StringPrintf("Waiting for quiescence of %" PRIuS " clients", | 215 return base::StringPrintf("Waiting for quiescence of %" PRIuS " clients", |
| 230 services_.size()); | 216 services_.size()); |
| 231 } | 217 } |
| 232 | 218 |
| 233 void QuiesceStatusChangeChecker::OnServiceStateChanged( | 219 void QuiesceStatusChangeChecker::OnServiceStateChanged( |
| 234 ProfileSyncService* service) { | 220 ProfileSyncService* service) { |
| 235 if (IsExitConditionSatisfied()) { | 221 CheckExitCondition(); |
| 236 DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); | |
| 237 base::MessageLoop::current()->QuitWhenIdle(); | |
| 238 } | |
| 239 } | 222 } |
| 240 | |
| 241 void QuiesceStatusChangeChecker::OnTimeout() { | |
| 242 DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); | |
| 243 timed_out_ = true; | |
| 244 base::MessageLoop::current()->QuitWhenIdle(); | |
| 245 } | |
| 246 | |
| 247 bool QuiesceStatusChangeChecker::TimedOut() const { | |
| 248 return timed_out_; | |
| 249 } | |
| OLD | NEW |