| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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/quiesce_status_change_checker.h" |
| 6 |
| 7 #include "base/format_macros.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" |
| 11 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
| 12 |
| 13 static bool HasLatestProgressMarkers(ProfileSyncService* service) { |
| 14 const syncer::sessions::SyncSessionSnapshot& snap = |
| 15 service->GetLastSessionSnapshot(); |
| 16 return snap.model_neutral_state().num_successful_commits == 0 && |
| 17 !service->HasUnsyncedItems(); |
| 18 } |
| 19 |
| 20 static bool IsSyncDisabled(ProfileSyncService* service) { |
| 21 return !service->setup_in_progress() && !service->HasSyncSetupCompleted(); |
| 22 } |
| 23 |
| 24 static bool ProgressMarkersMatch(ProfileSyncService* service1, |
| 25 ProfileSyncService *service2) { |
| 26 const syncer::ModelTypeSet common_types = |
| 27 Intersection(service1->GetActiveDataTypes(), |
| 28 service2->GetActiveDataTypes()); |
| 29 |
| 30 const syncer::sessions::SyncSessionSnapshot& snap1 = |
| 31 service1->GetLastSessionSnapshot(); |
| 32 const syncer::sessions::SyncSessionSnapshot& snap2 = |
| 33 service2->GetLastSessionSnapshot(); |
| 34 |
| 35 for (syncer::ModelTypeSet::Iterator type_it = common_types.First(); |
| 36 type_it.Good(); type_it.Inc()) { |
| 37 // Look up the progress markers. Fail if either one is missing. |
| 38 syncer::ProgressMarkerMap::const_iterator pm_it1 = |
| 39 snap1.download_progress_markers().find(type_it.Get()); |
| 40 if (pm_it1 == snap1.download_progress_markers().end()) { |
| 41 return false; |
| 42 } |
| 43 |
| 44 syncer::ProgressMarkerMap::const_iterator pm_it2 = |
| 45 snap2.download_progress_markers().find(type_it.Get()); |
| 46 if (pm_it2 == snap2.download_progress_markers().end()) { |
| 47 return false; |
| 48 } |
| 49 |
| 50 // Fail if any of them don't match. |
| 51 if (pm_it1->second != pm_it2->second) { |
| 52 return false; |
| 53 } |
| 54 } |
| 55 return true; |
| 56 } |
| 57 |
| 58 QuiesceStatusChangeChecker::QuiesceStatusChangeChecker( |
| 59 std::vector<ProfileSyncService*> services) |
| 60 : MultiClientStatusChangeChecker(services) {} |
| 61 |
| 62 QuiesceStatusChangeChecker::~QuiesceStatusChangeChecker() {} |
| 63 |
| 64 bool QuiesceStatusChangeChecker::IsExitConditionSatisfied() { |
| 65 size_t i = 0; |
| 66 for (ServiceList::iterator it = services_.begin(); |
| 67 it != services_.end(); ++it) { |
| 68 // Don't bother checking disabled clients. |
| 69 if (IsSyncDisabled(*it)) { |
| 70 LOG(WARNING) << "Skipping because sync disabled"; |
| 71 continue; |
| 72 } |
| 73 |
| 74 // Ensure this client has committed all it had to commit then performed the |
| 75 // self-notify GU to fetch the most recent available progress markers. |
| 76 if (!HasLatestProgressMarkers(*it)) { |
| 77 return false; |
| 78 } |
| 79 |
| 80 // Find the next non-disabled client. |
| 81 ServiceList::iterator next_it = it; |
| 82 do { |
| 83 next_it++; |
| 84 } while (next_it != services_.end() && IsSyncDisabled(*next_it)); |
| 85 |
| 86 // Check progress markers. Assumes ProgressMarkersMatch is transistive. |
| 87 if (next_it != services_.end() && !ProgressMarkersMatch(*it, *next_it)) { |
| 88 return false; |
| 89 } |
| 90 |
| 91 ++i; |
| 92 } |
| 93 return true; |
| 94 }; |
| 95 |
| 96 std::string QuiesceStatusChangeChecker::GetDebugMessage() const { |
| 97 return base::StringPrintf("Waiting for quiescence of %" PRIuS " clients", |
| 98 services_.size()); |
| 99 } |
| 100 |
| OLD | NEW |