| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "components/browser_sync/browser/profile_sync_service.h" | 13 #include "components/browser_sync/browser/profile_sync_service.h" |
| 14 #include "components/sync/sessions/sync_session_snapshot.h" | 14 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Returns true if this service is disabled. | 18 // Returns true if this service is disabled. |
| 19 bool IsSyncDisabled(ProfileSyncService* service) { | 19 bool IsSyncDisabled(ProfileSyncService* service) { |
| 20 return !service->IsSetupInProgress() && !service->IsFirstSetupComplete(); | 20 return !service->IsSetupInProgress() && !service->IsFirstSetupComplete(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // Returns true if these services have matching progress markers. | 23 // Returns true if these services have matching progress markers. |
| 24 bool ProgressMarkersMatch(const ProfileSyncService* service1, | 24 bool ProgressMarkersMatch(const ProfileSyncService* service1, |
| 25 const ProfileSyncService* service2) { | 25 const ProfileSyncService* service2) { |
| 26 const syncer::ModelTypeSet common_types = | 26 const syncer::ModelTypeSet common_types = |
| 27 Intersection(service1->GetActiveDataTypes(), | 27 Intersection(service1->GetActiveDataTypes(), |
| 28 service2->GetActiveDataTypes()); | 28 service2->GetActiveDataTypes()); |
| 29 | 29 |
| 30 const syncer::sessions::SyncSessionSnapshot& snap1 = | 30 const syncer::SyncCycleSnapshot& snap1 = service1->GetLastCycleSnapshot(); |
| 31 service1->GetLastSessionSnapshot(); | 31 const syncer::SyncCycleSnapshot& snap2 = service2->GetLastCycleSnapshot(); |
| 32 const syncer::sessions::SyncSessionSnapshot& snap2 = | |
| 33 service2->GetLastSessionSnapshot(); | |
| 34 | 32 |
| 35 for (syncer::ModelTypeSet::Iterator type_it = common_types.First(); | 33 for (syncer::ModelTypeSet::Iterator type_it = common_types.First(); |
| 36 type_it.Good(); type_it.Inc()) { | 34 type_it.Good(); type_it.Inc()) { |
| 37 // Look up the progress markers. Fail if either one is missing. | 35 // Look up the progress markers. Fail if either one is missing. |
| 38 syncer::ProgressMarkerMap::const_iterator pm_it1 = | 36 syncer::ProgressMarkerMap::const_iterator pm_it1 = |
| 39 snap1.download_progress_markers().find(type_it.Get()); | 37 snap1.download_progress_markers().find(type_it.Get()); |
| 40 if (pm_it1 == snap1.download_progress_markers().end()) { | 38 if (pm_it1 == snap1.download_progress_markers().end()) { |
| 41 return false; | 39 return false; |
| 42 } | 40 } |
| 43 | 41 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // The QuiesceStatusChangeChecker attempts to work around the limitations of | 121 // The QuiesceStatusChangeChecker attempts to work around the limitations of |
| 124 // this progress marker checking method. It tries to update the progress | 122 // this progress marker checking method. It tries to update the progress |
| 125 // marker status only in the OnStateChanged() callback, where the snapshot is | 123 // marker status only in the OnStateChanged() callback, where the snapshot is |
| 126 // freshest. | 124 // freshest. |
| 127 // | 125 // |
| 128 // It also checks the progress marker status when it is first initialized, and | 126 // It also checks the progress marker status when it is first initialized, and |
| 129 // that's where it's most likely that we could return a false positive. We | 127 // that's where it's most likely that we could return a false positive. We |
| 130 // need to check these service at startup, since not every service is | 128 // need to check these service at startup, since not every service is |
| 131 // guaranteed to generate OnStateChanged() events while we're waiting for | 129 // guaranteed to generate OnStateChanged() events while we're waiting for |
| 132 // quiescence. | 130 // quiescence. |
| 133 const syncer::sessions::SyncSessionSnapshot& snap = | 131 const syncer::SyncCycleSnapshot& snap = service_->GetLastCycleSnapshot(); |
| 134 service_->GetLastSessionSnapshot(); | |
| 135 probably_has_latest_progress_markers_ = | 132 probably_has_latest_progress_markers_ = |
| 136 snap.model_neutral_state().num_successful_commits == 0 && | 133 snap.model_neutral_state().num_successful_commits == 0 && |
| 137 !service_->HasUnsyncedItems(); | 134 !service_->HasUnsyncedItems(); |
| 138 } | 135 } |
| 139 | 136 |
| 140 bool ProgressMarkerWatcher::HasLatestProgressMarkers() { | 137 bool ProgressMarkerWatcher::HasLatestProgressMarkers() { |
| 141 return probably_has_latest_progress_markers_; | 138 return probably_has_latest_progress_markers_; |
| 142 } | 139 } |
| 143 | 140 |
| 144 bool ProgressMarkerWatcher::IsSyncDisabled() { | 141 bool ProgressMarkerWatcher::IsSyncDisabled() { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 212 |
| 216 std::string QuiesceStatusChangeChecker::GetDebugMessage() const { | 213 std::string QuiesceStatusChangeChecker::GetDebugMessage() const { |
| 217 return base::StringPrintf("Waiting for quiescence of %" PRIuS " clients", | 214 return base::StringPrintf("Waiting for quiescence of %" PRIuS " clients", |
| 218 services_.size()); | 215 services_.size()); |
| 219 } | 216 } |
| 220 | 217 |
| 221 void QuiesceStatusChangeChecker::OnServiceStateChanged( | 218 void QuiesceStatusChangeChecker::OnServiceStateChanged( |
| 222 ProfileSyncService* service) { | 219 ProfileSyncService* service) { |
| 223 CheckExitCondition(); | 220 CheckExitCondition(); |
| 224 } | 221 } |
| OLD | NEW |