File: updated_progress_marker_checker.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 3,010 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2014 The Chromium Authors
// 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/updated_progress_marker_checker.h"

#include "base/functional/bind.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "components/sync/engine/cycle/sync_cycle_snapshot.h"
#include "components/sync/service/sync_service_impl.h"

UpdatedProgressMarkerChecker::UpdatedProgressMarkerChecker(
    syncer::SyncServiceImpl* service)
    : SingleClientStatusChangeChecker(service) {
  DCHECK(sync_datatype_helper::test()->TestUsesSelfNotifications());

  // HasUnsyncedItemsForTest() posts a task to the sync thread which guarantees
  // that all tasks posted to the sync thread before this constructor have been
  // processed.
  service->HasUnsyncedItemsForTest(
      base::BindOnce(&UpdatedProgressMarkerChecker::GotHasUnsyncedItems,
                     weak_ptr_factory_.GetWeakPtr()));
}

UpdatedProgressMarkerChecker::~UpdatedProgressMarkerChecker() = default;

bool UpdatedProgressMarkerChecker::IsExitConditionSatisfied(std::ostream* os) {
  *os << "Waiting for progress markers... ";

  if (!has_unsynced_items_.has_value()) {
    *os << "Unknown synced values state.";
    return false;
  }

  const syncer::SyncCycleSnapshot& snap =
      service()->GetLastCycleSnapshotForDebugging();
  // Assuming the lack of ongoing remote changes, the progress marker can be
  // considered updated when:
  // 1. Progress markers are non-empty (which discards the default value for
  //    GetLastCycleSnapshot() prior to the first sync cycle).
  // 2. Our last sync cycle committed no changes (because commits are followed
  //    by the test-only 'self-notify' cycle).
  // 3. No pending local changes (which will ultimately generate new progress
  //    markers once submitted to the server).
  if (snap.download_progress_markers().empty()) {
    *os << "Progress markers are empty.";
    return false;
  }

  if (snap.model_neutral_state().num_successful_commits > 0) {
    *os << "Last sync cycle wasn't empty.";
    return false;
  }

  if (has_unsynced_items_.value()) {
    *os << "Has unsynced items.";
    return false;
  }

  return true;
}

void UpdatedProgressMarkerChecker::GotHasUnsyncedItems(
    bool has_unsynced_items) {
  has_unsynced_items_ = has_unsynced_items;
  CheckExitCondition();
}

void UpdatedProgressMarkerChecker::OnSyncCycleCompleted(
    syncer::SyncService* sync) {
  // Ignore sync cycles that were started before our constructor posted
  // HasUnsyncedItemsForTest() to the sync thread.
  if (!has_unsynced_items_.has_value()) {
    return;
  }

  // Override |has_unsynced_items_| with the result of the sync cycle.
  const syncer::SyncCycleSnapshot& snap =
      service()->GetLastCycleSnapshotForDebugging();
  has_unsynced_items_ = snap.has_remaining_local_changes();
  CheckExitCondition();
}