summaryrefslogtreecommitdiffstats
path: root/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/StoreTracker.java
blob: b6a3071a9d57e1ab9a334714c68f570dfe7bc9b8 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.sync.repositories;

import java.util.Iterator;

/**
 * Our hacky version of transactional semantics. The goal is to prevent
 * the following situation:
 *
 * * AAA is not modified locally.
 * * A modified AAA is downloaded during the storing phase. Its local
 *   timestamp is advanced.
 * * The direction of syncing changes, and AAA is now uploaded to the server.
 *
 * The following situation should still be supported:
 *
 * * AAA is not modified locally.
 * * A modified AAA is downloaded and merged with the local AAA.
 * * The merged AAA is uploaded to the server.
 *
 * As should:
 *
 * * AAA is modified locally.
 * * A modified AAA is downloaded, and discarded or merged.
 * * The current version of AAA is uploaded to the server.
 *
 * We achieve this by tracking GUIDs during the storing phase. If we
 * apply a record such that the local copy is substantially the same
 * as the record we just downloaded, we add it to a list of records
 * to avoid uploading. The definition of "substantially the same"
 * depends on the particular repository. The only consideration is "do we
 * want to upload this record in this sync?".
 *
 * Note that items are removed from this list when a fetch that
 * considers them for upload completes successfully. The entire list
 * is discarded when the session is completed.
 *
 * This interface exposes methods to:
 *
 * * During a store, recording that a record has been stored, and should
 *   thus not be returned in subsequent fetches;
 * * During a fetch, checking whether a record should be returned.
 *
 * In the future this might also grow self-persistence.
 *
 * See also RepositorySession.trackRecord.
 *
 * @author rnewman
 *
 */
public interface StoreTracker {

  /**
   * @param guid
   *        The GUID of the item to track.
   * @return
   *        Whether the GUID was a newly tracked value.
   */
  public boolean trackRecordForExclusion(String guid);

  /**
   * @param guid
   *        The GUID of the item to check.
   * @return
   *        true if the item is already tracked.
   */
  public boolean isTrackedForExclusion(String guid);

  /**
  *
  * @param guid
  * @return true if the specified GUID was removed from the tracked set.
  */
  public boolean untrackStoredForExclusion(String guid);

  public RecordFilter getFilter();

  public Iterator<String> recordsTrackedForExclusion();
}