Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2835)

Unified Diff: chrome/browser/sync/test/integration/quiesce_status_change_checker.cc

Issue 165393010: Draft: Moving code out of ProfileSyncServiceHarness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/test/integration/quiesce_status_change_checker.cc
diff --git a/chrome/browser/sync/test/integration/quiesce_status_change_checker.cc b/chrome/browser/sync/test/integration/quiesce_status_change_checker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21f493084d9844f2e215f2e6470cf9980e152a41
--- /dev/null
+++ b/chrome/browser/sync/test/integration/quiesce_status_change_checker.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h"
+
+#include "base/format_macros.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/sync/profile_sync_service.h"
+#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
+
+static bool HasLatestProgressMarkers(ProfileSyncService* service) {
+ const syncer::sessions::SyncSessionSnapshot& snap =
+ service->GetLastSessionSnapshot();
+ return snap.model_neutral_state().num_successful_commits == 0 &&
+ !service->HasUnsyncedItems();
+}
+
+static bool IsSyncDisabled(ProfileSyncService* service) {
+ return !service->setup_in_progress() && !service->HasSyncSetupCompleted();
+}
+
+static bool ProgressMarkersMatch(ProfileSyncService* service1,
+ ProfileSyncService *service2) {
+ const syncer::ModelTypeSet common_types =
+ Intersection(service1->GetActiveDataTypes(),
+ service2->GetActiveDataTypes());
+
+ const syncer::sessions::SyncSessionSnapshot& snap1 =
+ service1->GetLastSessionSnapshot();
+ const syncer::sessions::SyncSessionSnapshot& snap2 =
+ service2->GetLastSessionSnapshot();
+
+ for (syncer::ModelTypeSet::Iterator type_it = common_types.First();
+ type_it.Good(); type_it.Inc()) {
+ // Look up the progress markers. Fail if either one is missing.
+ syncer::ProgressMarkerMap::const_iterator pm_it1 =
+ snap1.download_progress_markers().find(type_it.Get());
+ if (pm_it1 == snap1.download_progress_markers().end()) {
+ return false;
+ }
+
+ syncer::ProgressMarkerMap::const_iterator pm_it2 =
+ snap2.download_progress_markers().find(type_it.Get());
+ if (pm_it2 == snap2.download_progress_markers().end()) {
+ return false;
+ }
+
+ // Fail if any of them don't match.
+ if (pm_it1->second != pm_it2->second) {
+ return false;
+ }
+ }
+ return true;
+}
+
+QuiesceStatusChangeChecker::QuiesceStatusChangeChecker(
+ std::vector<ProfileSyncService*> services)
+ : MultiClientStatusChangeChecker(services) {}
+
+QuiesceStatusChangeChecker::~QuiesceStatusChangeChecker() {}
+
+bool QuiesceStatusChangeChecker::IsExitConditionSatisfied() {
+ size_t i = 0;
+ for (ServiceList::iterator it = services_.begin();
+ it != services_.end(); ++it) {
+ // Don't bother checking disabled clients.
+ if (IsSyncDisabled(*it)) {
+ LOG(WARNING) << "Skipping because sync disabled";
+ continue;
+ }
+
+ // Ensure this client has committed all it had to commit then performed the
+ // self-notify GU to fetch the most recent available progress markers.
+ if (!HasLatestProgressMarkers(*it)) {
+ return false;
+ }
+
+ // Find the next non-disabled client.
+ ServiceList::iterator next_it = it;
+ do {
+ next_it++;
+ } while (next_it != services_.end() && IsSyncDisabled(*next_it));
+
+ // Check progress markers. Assumes ProgressMarkersMatch is transistive.
+ if (next_it != services_.end() && !ProgressMarkersMatch(*it, *next_it)) {
+ return false;
+ }
+
+ ++i;
+ }
+ return true;
+};
+
+std::string QuiesceStatusChangeChecker::GetDebugMessage() const {
+ return base::StringPrintf("Waiting for quiescence of %" PRIuS " clients",
+ services_.size());
+}
+

Powered by Google App Engine
This is Rietveld 408576698