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
3// found in the LICENSE file.
4
5#include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h"
6
7#include "chrome/browser/sync/profile_sync_service.h"
8#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
9
10UpdatedProgressMarkerChecker::UpdatedProgressMarkerChecker(
11    ProfileSyncService* service) : SingleClientStatusChangeChecker(service) {}
12
13UpdatedProgressMarkerChecker::~UpdatedProgressMarkerChecker() {}
14
15bool UpdatedProgressMarkerChecker::IsExitConditionSatisfied() {
16  // Checks to see if our self-notify sync cycle has completed and
17  // there's nothing to commit.
18  //
19  // If we assume that no one else is committing at this time and that the
20  // current client did not commit anything in its previous sync cycle, then
21  // this client has the latest progress markers.
22  //
23  // The !service()->HasUnsyncedItems() check makes sure that we have nothing to
24  // commit.
25  //
26  // There is a subtle race condition here.  While committing items, the syncer
27  // will unset the IS_UNSYNCED bits in the directory.  However, the evidence of
28  // this current sync cycle won't be available from GetLastSessionSnapshot()
29  // until the sync cycle completes.  If we query this condition between the
30  // commit response processing and the end of the sync cycle, we could return a
31  // false positive.
32  //
33  // In practice, this doesn't happen very often because we only query the
34  // status when the waiting first starts and when we receive notification of a
35  // sync session complete or other significant event from the
36  // ProfileSyncService.  If we're calling this right after the sync session
37  // completes, then the snapshot is much more likely to be up to date.
38  const syncer::sessions::SyncSessionSnapshot& snap =
39      service()->GetLastSessionSnapshot();
40  return snap.model_neutral_state().num_successful_commits == 0 &&
41         !service()->HasUnsyncedItems();
42}
43
44std::string UpdatedProgressMarkerChecker::GetDebugMessage() const {
45  return "Waiting for progress markers";
46}
47