1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/sync/repositories/StoreTracker.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.sync.repositories; 1.9 + 1.10 +import java.util.Iterator; 1.11 + 1.12 +/** 1.13 + * Our hacky version of transactional semantics. The goal is to prevent 1.14 + * the following situation: 1.15 + * 1.16 + * * AAA is not modified locally. 1.17 + * * A modified AAA is downloaded during the storing phase. Its local 1.18 + * timestamp is advanced. 1.19 + * * The direction of syncing changes, and AAA is now uploaded to the server. 1.20 + * 1.21 + * The following situation should still be supported: 1.22 + * 1.23 + * * AAA is not modified locally. 1.24 + * * A modified AAA is downloaded and merged with the local AAA. 1.25 + * * The merged AAA is uploaded to the server. 1.26 + * 1.27 + * As should: 1.28 + * 1.29 + * * AAA is modified locally. 1.30 + * * A modified AAA is downloaded, and discarded or merged. 1.31 + * * The current version of AAA is uploaded to the server. 1.32 + * 1.33 + * We achieve this by tracking GUIDs during the storing phase. If we 1.34 + * apply a record such that the local copy is substantially the same 1.35 + * as the record we just downloaded, we add it to a list of records 1.36 + * to avoid uploading. The definition of "substantially the same" 1.37 + * depends on the particular repository. The only consideration is "do we 1.38 + * want to upload this record in this sync?". 1.39 + * 1.40 + * Note that items are removed from this list when a fetch that 1.41 + * considers them for upload completes successfully. The entire list 1.42 + * is discarded when the session is completed. 1.43 + * 1.44 + * This interface exposes methods to: 1.45 + * 1.46 + * * During a store, recording that a record has been stored, and should 1.47 + * thus not be returned in subsequent fetches; 1.48 + * * During a fetch, checking whether a record should be returned. 1.49 + * 1.50 + * In the future this might also grow self-persistence. 1.51 + * 1.52 + * See also RepositorySession.trackRecord. 1.53 + * 1.54 + * @author rnewman 1.55 + * 1.56 + */ 1.57 +public interface StoreTracker { 1.58 + 1.59 + /** 1.60 + * @param guid 1.61 + * The GUID of the item to track. 1.62 + * @return 1.63 + * Whether the GUID was a newly tracked value. 1.64 + */ 1.65 + public boolean trackRecordForExclusion(String guid); 1.66 + 1.67 + /** 1.68 + * @param guid 1.69 + * The GUID of the item to check. 1.70 + * @return 1.71 + * true if the item is already tracked. 1.72 + */ 1.73 + public boolean isTrackedForExclusion(String guid); 1.74 + 1.75 + /** 1.76 + * 1.77 + * @param guid 1.78 + * @return true if the specified GUID was removed from the tracked set. 1.79 + */ 1.80 + public boolean untrackStoredForExclusion(String guid); 1.81 + 1.82 + public RecordFilter getFilter(); 1.83 + 1.84 + public Iterator<String> recordsTrackedForExclusion(); 1.85 +}