From eb469c632e8c0b8f8a473ea6c39f65e995b207d4 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Tue, 11 Oct 2016 19:29:02 -0700 Subject: [PATCH] Bug 1291821 - Add onBatchComplete to a FetchRecordsDelegate r=rnewman Intended to signal that a group of records have been fetched, and more are to come after a pause. MozReview-Commit-ID: 8ozZTc6aNdA --HG-- extra : rebase_source : e2fdf70d6db6e242e65b788dcb6a09f975b5124b --- .../Crypto5MiddlewareRepositorySession.java | 5 +++++ ...rredRepositorySessionFetchRecordsDelegate.java | 10 ++++++++++ .../RepositorySessionFetchRecordsDelegate.java | 8 +++++++- .../gecko/sync/synchronizer/RecordsChannel.java | 4 ++++ .../gecko/background/db/TestBookmarks.java | 10 ++++++++++ .../gecko/background/sync/TestStoreTracking.java | 15 +++++++++++++++ .../sync/helpers/DefaultFetchDelegate.java | 5 +++++ .../android/sync/test/SynchronizerHelpers.java | 5 +++++ ...cessRepositorySessionFetchRecordsDelegate.java | 5 +++++ .../BatchingDownloaderDelegateTest.java | 5 +++++ .../downloaders/BatchingDownloaderTest.java | 6 ++++++ 11 files changed, 77 insertions(+), 1 deletion(-) diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java index a9290c57d2d8..9235f04e1b87 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java @@ -114,6 +114,11 @@ public class Crypto5MiddlewareRepositorySession extends MiddlewareRepositorySess next.onFetchCompleted(fetchEnd); } + @Override + public void onBatchCompleted() { + next.onBatchCompleted(); + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { // Synchronously perform *our* work, passing through appropriately. diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java index 1178d9b5bf5b..5b10f2700c4f 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java @@ -46,6 +46,16 @@ public class DeferredRepositorySessionFetchRecordsDelegate implements Repository }); } + @Override + public void onBatchCompleted() { + executor.execute(new Runnable() { + @Override + public void run() { + inner.onBatchCompleted(); + } + }); + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService newExecutor) { if (newExecutor == executor) { diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java index 589a093dc2b9..4ed539c3cba6 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java @@ -23,5 +23,11 @@ public interface RepositorySessionFetchRecordsDelegate { */ public void onFetchCompleted(final long fetchEnd); - public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor); + /** + * Called when a number of records have been returned but more are still expected to come, + * possibly after a certain pause. + */ + void onBatchCompleted(); + + RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor); } diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java index 2f52936ccdbb..6e85b801ac49 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java @@ -216,6 +216,10 @@ public class RecordsChannel implements this.consumer.queueFilled(); } + @Override + public void onBatchCompleted() { + } + @Override public void onRecordStoreFailed(Exception ex, String recordGuid) { Logger.trace(LOG_TAG, "Failed to store record with guid " + recordGuid); diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java index 783aea1ff848..64834e6d124d 100644 --- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java @@ -665,6 +665,11 @@ public class TestBookmarks extends AndroidSyncTestCase { public void onFetchCompleted(long end) { finishAndNotify(session); } + + @Override + public void onBatchCompleted() { + + } }; session.fetchSince(0, fetchDelegate); } @@ -695,6 +700,11 @@ public class TestBookmarks extends AndroidSyncTestCase { public void onFetchCompleted(long end) { finishAndNotify(session); } + + @Override + public void onBatchCompleted() { + + } }; try { session.fetch(new String[] { guid }, fetchDelegate); diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java index bac6c7f49ff6..2041c1f258a7 100644 --- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java @@ -104,8 +104,18 @@ public class TestStoreTracking extends AndroidSyncTestCase { performNotify(e); } } + + @Override + public void onBatchCompleted() { + + } }); } + + @Override + public void onBatchCompleted() { + + } }); } catch (InactiveSessionException e) { performNotify(e); @@ -156,6 +166,11 @@ public class TestStoreTracking extends AndroidSyncTestCase { performNotify(e); } } + + @Override + public void onBatchCompleted() { + + } }); } }); diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java index 3d7d23bab280..9547a0fdab5b 100644 --- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java @@ -99,6 +99,11 @@ public class DefaultFetchDelegate extends DefaultDelegate implements RepositoryS Logger.debug(LOG_TAG, "onFetchCompleted. Doing nothing."); } + @Override + public void onBatchCompleted() { + Logger.debug(LOG_TAG, "onBatchCompleted. Doing nothing."); + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(final ExecutorService executor) { return new DeferredRepositorySessionFetchRecordsDelegate(this, executor); diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java index 7bf4dfa8e019..8ba4fe79e821 100644 --- a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java @@ -54,6 +54,11 @@ public class SynchronizerHelpers { delegate.onFetchCompleted(fetchEnd); } + @Override + public void onBatchCompleted() { + + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { return this; diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java index 5f5cf899594d..13c8e8bb5858 100644 --- a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java @@ -37,6 +37,11 @@ public class ExpectSuccessRepositorySessionFetchRecordsDelegate extends performNotify(); } + @Override + public void onBatchCompleted() { + log("Batch completed."); + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { return this; diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java index da2bbac188f6..a948b7c2be09 100644 --- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java @@ -86,6 +86,11 @@ public class BatchingDownloaderDelegateTest { } + @Override + public void onBatchCompleted() { + + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { return null; diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java index fbbd9cae92d5..84311b5e4027 100644 --- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java @@ -52,6 +52,7 @@ public class BatchingDownloaderTest { public boolean isFailure; public boolean isFetched; public boolean isSuccess; + public int batchesCompleted; public Exception ex; public Record record; @@ -73,6 +74,11 @@ public class BatchingDownloaderTest { this.isSuccess = true; } + @Override + public void onBatchCompleted() { + this.batchesCompleted += 1; + } + @Override public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { return null;