зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1291821 - Use sync deadline to decide of batching downloader should proceed r=rnewman
MozReview-Commit-ID: IDgIj9lBt61 --HG-- extra : rebase_source : a3d1773abb50748631e28c0aa14797b17b857def
This commit is contained in:
Родитель
2c49e9087a
Коммит
dc5b52e557
|
@ -24,6 +24,7 @@ public class ConstrainedServer11Repository extends Server11Repository {
|
|||
|
||||
public ConstrainedServer11Repository(
|
||||
String collection,
|
||||
long syncDeadline,
|
||||
String storageURL,
|
||||
AuthHeaderProvider authHeaderProvider,
|
||||
InfoCollections infoCollections,
|
||||
|
@ -33,6 +34,7 @@ public class ConstrainedServer11Repository extends Server11Repository {
|
|||
boolean allowMultipleBatches) throws URISyntaxException {
|
||||
super(
|
||||
collection,
|
||||
syncDeadline,
|
||||
storageURL,
|
||||
authHeaderProvider,
|
||||
infoCollections,
|
||||
|
|
|
@ -25,7 +25,7 @@ import android.support.annotation.Nullable;
|
|||
public class Server11Repository extends Repository {
|
||||
public final AuthHeaderProvider authHeaderProvider;
|
||||
|
||||
/* package-local */ final long syncDeadline;
|
||||
private final long syncDeadlineMillis;
|
||||
/* package-local */ final URI collectionURI;
|
||||
|
||||
protected final String collection;
|
||||
|
@ -46,6 +46,7 @@ public class Server11Repository extends Repository {
|
|||
*/
|
||||
public Server11Repository(
|
||||
@NonNull String collection,
|
||||
long syncDeadlineMillis,
|
||||
@NonNull String storageURL,
|
||||
AuthHeaderProvider authHeaderProvider,
|
||||
@NonNull InfoCollections infoCollections,
|
||||
|
@ -60,6 +61,7 @@ public class Server11Repository extends Repository {
|
|||
throw new IllegalArgumentException("infoCollections must not be null");
|
||||
}
|
||||
this.collection = collection;
|
||||
this.syncDeadlineMillis = syncDeadlineMillis;
|
||||
this.collectionURI = new URI(storageURL + (storageURL.endsWith("/") ? collection : "/" + collection));
|
||||
this.authHeaderProvider = authHeaderProvider;
|
||||
this.infoCollections = infoCollections;
|
||||
|
@ -100,4 +102,13 @@ public class Server11Repository extends Repository {
|
|||
public boolean getAllowMultipleBatches() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A point in time by which this repository's session must complete fetch and store operations.
|
||||
* Particularly pertinent for batching downloads performed by the session (should we fetch
|
||||
* another batch?) and buffered repositories (do we have enough time to merge what we've downloaded?).
|
||||
*/
|
||||
public long getSyncDeadline() {
|
||||
return syncDeadlineMillis;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ public class Server11RepositorySession extends RepositorySession {
|
|||
return new BatchingDownloader(
|
||||
serverRepositorySession.serverRepository.authHeaderProvider,
|
||||
Uri.parse(serverRepositorySession.serverRepository.collectionURI().toString()),
|
||||
serverRepositorySession.serverRepository.getSyncDeadline(),
|
||||
serverRepositorySession.serverRepository.getAllowMultipleBatches(),
|
||||
serverRepositorySession);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ public class BatchingDownloader {
|
|||
private final RepositorySession repositorySession;
|
||||
private final DelayedWorkTracker workTracker = new DelayedWorkTracker();
|
||||
private final Uri baseCollectionUri;
|
||||
private final long fetchDeadline;
|
||||
private final boolean allowMultipleBatches;
|
||||
|
||||
/* package-local */ final AuthHeaderProvider authHeaderProvider;
|
||||
|
@ -70,12 +71,14 @@ public class BatchingDownloader {
|
|||
public BatchingDownloader(
|
||||
AuthHeaderProvider authHeaderProvider,
|
||||
Uri baseCollectionUri,
|
||||
long fetchDeadline,
|
||||
boolean allowMultipleBatches,
|
||||
RepositorySession repositorySession) {
|
||||
this.repositorySession = repositorySession;
|
||||
this.authHeaderProvider = authHeaderProvider;
|
||||
this.baseCollectionUri = baseCollectionUri;
|
||||
this.allowMultipleBatches = allowMultipleBatches;
|
||||
this.fetchDeadline = fetchDeadline;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -217,6 +220,12 @@ public class BatchingDownloader {
|
|||
}
|
||||
});
|
||||
|
||||
// Should we proceed, however? Do we have enough time?
|
||||
if (!mayProceedWithBatching(fetchDeadline)) {
|
||||
this.abort(fetchRecordsDelegate, new Exception("Not enough time to complete next batch"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create and execute new batch request.
|
||||
try {
|
||||
final SyncStorageCollectionRequest newRequest = makeSyncStorageCollectionRequest(newer,
|
||||
|
@ -293,6 +302,14 @@ public class BatchingDownloader {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean mayProceedWithBatching(long deadline) {
|
||||
// For simplicity, allow batching to proceed if there's at least a minute left for the sync.
|
||||
// This should be enough to fetch and process records in the batch.
|
||||
final long timeLeft = deadline - SystemClock.elapsedRealtime();
|
||||
return timeLeft > TimeUnit.MINUTES.toMillis(1);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static URI buildCollectionURI(Uri baseCollectionUri, boolean full, long newer, long limit, String sort, String ids, String offset) throws URISyntaxException {
|
||||
Uri.Builder uriBuilder = baseCollectionUri.buildUpon();
|
||||
|
|
|
@ -41,6 +41,7 @@ public class AndroidBrowserBookmarksServerSyncStage extends ServerSyncStage {
|
|||
protected Repository getRemoteRepository() throws URISyntaxException {
|
||||
return new ConstrainedServer11Repository(
|
||||
getCollection(),
|
||||
session.getSyncDeadline(),
|
||||
session.config.storageURL(),
|
||||
session.getAuthHeaderProvider(),
|
||||
session.config.infoCollections,
|
||||
|
|
|
@ -46,6 +46,7 @@ public class AndroidBrowserHistoryServerSyncStage extends ServerSyncStage {
|
|||
protected Repository getRemoteRepository() throws URISyntaxException {
|
||||
return new ConstrainedServer11Repository(
|
||||
getCollection(),
|
||||
session.getSyncDeadline(),
|
||||
session.config.storageURL(),
|
||||
session.getAuthHeaderProvider(),
|
||||
session.config.infoCollections,
|
||||
|
|
|
@ -144,6 +144,7 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
|
|||
protected Repository getRemoteRepository() throws URISyntaxException {
|
||||
String collection = getCollection();
|
||||
return new Server11Repository(collection,
|
||||
session.getSyncDeadline(),
|
||||
session.config.storageURL(),
|
||||
session.getAuthHeaderProvider(),
|
||||
session.config.infoCollections,
|
||||
|
|
Загрузка…
Ссылка в новой задаче