зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1408585 - Remove RepositorySession createSession delegates r=rnewman
MozReview-Commit-ID: KezYHeSWDiL --HG-- extra : rebase_source : c63f69a7d5b16d152fa809560a70c14ae1da5715
This commit is contained in:
Родитель
45de7880f9
Коммит
2c2f325436
|
@ -907,7 +907,6 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
|
|||
'sync/middleware/BufferingMiddlewareRepositorySession.java',
|
||||
'sync/middleware/Crypto5MiddlewareRepository.java',
|
||||
'sync/middleware/Crypto5MiddlewareRepositorySession.java',
|
||||
'sync/middleware/MiddlewareRepository.java',
|
||||
'sync/middleware/MiddlewareRepositorySession.java',
|
||||
'sync/middleware/storage/BufferStorage.java',
|
||||
'sync/middleware/storage/MemoryBufferStorage.java',
|
||||
|
@ -969,17 +968,13 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
|
|||
'sync/repositories/android/PasswordsRepositorySession.java',
|
||||
'sync/repositories/android/RepoUtils.java',
|
||||
'sync/repositories/android/SessionHelper.java',
|
||||
'sync/repositories/android/ThreadedRepository.java',
|
||||
'sync/repositories/android/VisitsHelper.java',
|
||||
'sync/repositories/BookmarkNeedsReparentingException.java',
|
||||
'sync/repositories/BookmarksRepository.java',
|
||||
'sync/repositories/ConfigurableServer15Repository.java',
|
||||
'sync/repositories/delegates/DeferrableRepositorySessionCreationDelegate.java',
|
||||
'sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java',
|
||||
'sync/repositories/delegates/DeferredRepositorySessionFinishDelegate.java',
|
||||
'sync/repositories/delegates/DeferredRepositorySessionStoreDelegate.java',
|
||||
'sync/repositories/delegates/RepositorySessionCleanDelegate.java',
|
||||
'sync/repositories/delegates/RepositorySessionCreationDelegate.java',
|
||||
'sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java',
|
||||
'sync/repositories/delegates/RepositorySessionFinishDelegate.java',
|
||||
'sync/repositories/delegates/RepositorySessionStoreDelegate.java',
|
||||
|
@ -1003,7 +998,6 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
|
|||
'sync/repositories/downloaders/BatchingDownloaderDelegate.java',
|
||||
'sync/repositories/FetchFailedException.java',
|
||||
'sync/repositories/HashSetStoreTracker.java',
|
||||
'sync/repositories/HistoryRepository.java',
|
||||
'sync/repositories/IdentityRecordFactory.java',
|
||||
'sync/repositories/InactiveSessionException.java',
|
||||
'sync/repositories/InvalidBookmarkTypeException.java',
|
||||
|
@ -1041,6 +1035,7 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
|
|||
'sync/repositories/VersioningDelegateHelper.java',
|
||||
'sync/Server15PreviousPostFailedException.java',
|
||||
'sync/Server15RecordPostFailedException.java',
|
||||
'sync/SessionCreateException.java',
|
||||
'sync/setup/activities/ActivityUtils.java',
|
||||
'sync/setup/activities/WebURLFinder.java',
|
||||
'sync/setup/Constants.java',
|
||||
|
|
|
@ -13,17 +13,15 @@ import org.mozilla.gecko.background.sync.helpers.ExpectFinishDelegate;
|
|||
import org.mozilla.gecko.background.sync.helpers.ExpectInvalidTypeStoreDelegate;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.NullCursorException;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.BookmarksDataAccessor;
|
||||
import org.mozilla.gecko.sync.repositories.android.BookmarksRepository;
|
||||
import org.mozilla.gecko.sync.repositories.android.BookmarksRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.ThreadedRepository;
|
||||
import org.mozilla.gecko.sync.repositories.android.DataAccessor;
|
||||
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
|
||||
import org.mozilla.gecko.sync.repositories.android.RepoUtils;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
|
||||
|
@ -34,7 +32,7 @@ import android.database.Cursor;
|
|||
public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTestCase {
|
||||
|
||||
@Override
|
||||
protected ThreadedRepository getRepository() {
|
||||
protected Repository getRepository() {
|
||||
|
||||
/**
|
||||
* Override this chain in order to avoid our test code having to create two
|
||||
|
@ -42,15 +40,13 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
*/
|
||||
return new BookmarksRepository() {
|
||||
@Override
|
||||
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
BookmarksRepositorySession session;
|
||||
session = new BookmarksRepositorySession(this, context) {
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new BookmarksRepositorySession(this, context) {
|
||||
@Override
|
||||
protected synchronized void trackGUID(String guid) {
|
||||
System.out.println("Ignoring trackGUID call: this is a test!");
|
||||
}
|
||||
};
|
||||
delegate.deferredCreationDelegate().onSessionCreated(session);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -87,7 +83,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
// to store a folder first, store your record in "mobile" or one of the folders
|
||||
// that always exists.
|
||||
|
||||
public void testFetchOneWithChildren() {
|
||||
public void testFetchOneWithChildren() throws Exception {
|
||||
BookmarkRecord folder = BookmarkHelpers.createFolder1();
|
||||
BookmarkRecord bookmark1 = BookmarkHelpers.createBookmark1();
|
||||
BookmarkRecord bookmark2 = BookmarkHelpers.createBookmark2();
|
||||
|
@ -159,7 +155,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
}
|
||||
|
||||
|
||||
public void testStoreFolder() {
|
||||
public void testStoreFolder() throws Exception {
|
||||
basicStoreTest(BookmarkHelpers.createFolder1());
|
||||
}
|
||||
|
||||
|
@ -190,7 +186,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
}
|
||||
*/
|
||||
|
||||
protected void basicStoreFailTest(Record record) {
|
||||
protected void basicStoreFailTest(Record record) throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
performWait(storeRunnable(session, record, new ExpectInvalidTypeStoreDelegate()));
|
||||
dispose(session);
|
||||
|
@ -201,7 +197,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
*/
|
||||
// Insert two records missing parent, then insert their parent.
|
||||
// Make sure they end up with the correct parent on fetch.
|
||||
public void testBasicReparenting() throws InactiveSessionException {
|
||||
public void testBasicReparenting() throws Exception {
|
||||
Record[] expected = new Record[] {
|
||||
BookmarkHelpers.createBookmark1(),
|
||||
BookmarkHelpers.createBookmark2(),
|
||||
|
@ -212,7 +208,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
|
||||
// Insert 3 folders and 4 bookmarks in different orders
|
||||
// and make sure they come out parented correctly
|
||||
public void testMultipleFolderReparenting1() throws InactiveSessionException {
|
||||
public void testMultipleFolderReparenting1() throws Exception {
|
||||
Record[] expected = new Record[] {
|
||||
BookmarkHelpers.createBookmark1(),
|
||||
BookmarkHelpers.createBookmark2(),
|
||||
|
@ -225,7 +221,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
doMultipleFolderReparentingTest(expected);
|
||||
}
|
||||
|
||||
public void testMultipleFolderReparenting2() throws InactiveSessionException {
|
||||
public void testMultipleFolderReparenting2() throws Exception {
|
||||
Record[] expected = new Record[] {
|
||||
BookmarkHelpers.createBookmark1(),
|
||||
BookmarkHelpers.createBookmark2(),
|
||||
|
@ -238,7 +234,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
doMultipleFolderReparentingTest(expected);
|
||||
}
|
||||
|
||||
public void testMultipleFolderReparenting3() throws InactiveSessionException {
|
||||
public void testMultipleFolderReparenting3() throws Exception {
|
||||
Record[] expected = new Record[] {
|
||||
BookmarkHelpers.createBookmark1(),
|
||||
BookmarkHelpers.createBookmark2(),
|
||||
|
@ -251,7 +247,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
doMultipleFolderReparentingTest(expected);
|
||||
}
|
||||
|
||||
private void doMultipleFolderReparentingTest(Record[] expected) throws InactiveSessionException {
|
||||
private void doMultipleFolderReparentingTest(Record[] expected) throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
doStore(session, expected);
|
||||
ExpectFetchDelegate delegate = preparedExpectFetchDelegate(expected);
|
||||
|
@ -277,7 +273,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
* Store a record after with the new guid as the parent
|
||||
* and make sure it works as well.
|
||||
*/
|
||||
public void testStoreIdenticalFoldersWithChildren() {
|
||||
public void testStoreIdenticalFoldersWithChildren() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
Record record0 = BookmarkHelpers.createFolder1();
|
||||
|
||||
|
@ -368,7 +364,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
BookmarkHelpers.createFolder1());
|
||||
}
|
||||
|
||||
public void testBasicPositioning() {
|
||||
public void testBasicPositioning() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
Record[] expected = new Record[] {
|
||||
BookmarkHelpers.createBookmark1(),
|
||||
|
@ -404,7 +400,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testSqlInjectPurgeDeleteAndUpdateByGuid() {
|
||||
public void testSqlInjectPurgeDeleteAndUpdateByGuid() throws Exception {
|
||||
// Some setup.
|
||||
RepositorySession session = createAndBeginSession();
|
||||
DataAccessor db = getDataAccessor();
|
||||
|
@ -485,7 +481,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
return cur;
|
||||
}
|
||||
|
||||
public void testSqlInjectFetch() {
|
||||
public void testSqlInjectFetch() throws Exception {
|
||||
// Some setup.
|
||||
RepositorySession session = createAndBeginSession();
|
||||
DataAccessor db = getDataAccessor();
|
||||
|
@ -533,7 +529,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testSqlInjectDelete() {
|
||||
public void testSqlInjectDelete() throws Exception {
|
||||
// Some setup.
|
||||
RepositorySession session = createAndBeginSession();
|
||||
DataAccessor db = getDataAccessor();
|
||||
|
@ -578,7 +574,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
|
|||
* Verify that data accessor's bulkInsert actually inserts.
|
||||
* @throws NullCursorException
|
||||
*/
|
||||
public void testBulkInsert() throws NullCursorException {
|
||||
public void testBulkInsert() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
DataAccessor db = getDataAccessor();
|
||||
|
||||
|
|
|
@ -11,15 +11,14 @@ import org.mozilla.gecko.background.sync.helpers.HistoryHelpers;
|
|||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
import org.mozilla.gecko.sync.repositories.NullCursorException;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.HistoryDataAccessor;
|
||||
import org.mozilla.gecko.sync.repositories.android.HistoryRepository;
|
||||
import org.mozilla.gecko.sync.repositories.android.HistoryRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.ThreadedRepository;
|
||||
import org.mozilla.gecko.sync.repositories.android.DataAccessor;
|
||||
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
|
||||
import org.mozilla.gecko.sync.repositories.android.RepoUtils;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.HistoryRecord;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
|
||||
|
@ -31,7 +30,7 @@ import android.net.Uri;
|
|||
public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestCase {
|
||||
|
||||
@Override
|
||||
protected ThreadedRepository getRepository() {
|
||||
protected Repository getRepository() {
|
||||
|
||||
/**
|
||||
* Override this chain in order to avoid our test code having to create two
|
||||
|
@ -39,15 +38,13 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
|
|||
*/
|
||||
return new HistoryRepository() {
|
||||
@Override
|
||||
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
HistoryRepositorySession session;
|
||||
session = new HistoryRepositorySession(this, context) {
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new HistoryRepositorySession(this, context) {
|
||||
@Override
|
||||
protected synchronized void trackGUID(String guid) {
|
||||
System.out.println("Ignoring trackGUID call: this is a test!");
|
||||
}
|
||||
};
|
||||
delegate.onSessionCreated(session);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -202,7 +199,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
|
|||
* and doing a fetch.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAddOneVisit() {
|
||||
public void testAddOneVisit() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
|
||||
HistoryRecord record0 = HistoryHelpers.createHistory3();
|
||||
|
@ -229,7 +226,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAddMultipleVisits() {
|
||||
public void testAddMultipleVisits() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
|
||||
HistoryRecord record0 = HistoryHelpers.createHistory4();
|
||||
|
@ -270,7 +267,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
|
|||
closeDataAccessor(dataAccessor);
|
||||
}
|
||||
|
||||
public void testInvalidHistoryItemIsSkipped() throws NullCursorException {
|
||||
public void testInvalidHistoryItemIsSkipped() throws Exception {
|
||||
final HistoryRepositorySession session = (HistoryRepositorySession) createAndBeginSession();
|
||||
final DataAccessor dbHelper = new HistoryDataAccessor(getApplicationContext());
|
||||
|
||||
|
@ -312,7 +309,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testSqlInjectPurgeDelete() {
|
||||
public void testSqlInjectPurgeDelete() throws Exception {
|
||||
// Some setup.
|
||||
RepositorySession session = createAndBeginSession();
|
||||
final DataAccessor db = getDataAccessor();
|
||||
|
@ -397,7 +394,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
|
|||
return cur;
|
||||
}
|
||||
|
||||
public void testDataAccessorBulkInsert() throws NullCursorException {
|
||||
public void testDataAccessorBulkInsert() throws Exception {
|
||||
final HistoryRepositorySession session = (HistoryRepositorySession) createAndBeginSession();
|
||||
final HistoryDataAccessor db = new HistoryDataAccessor(getApplicationContext());
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.mozilla.gecko.R;
|
|||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
|
||||
import org.mozilla.gecko.background.sync.helpers.BookmarkHelpers;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessCreationDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate;
|
||||
|
@ -48,7 +47,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
/**
|
||||
* Trivial test that pinned items will be skipped if present in the DB.
|
||||
*/
|
||||
public void testPinnedItemsAreNotRetrieved() {
|
||||
public void testPinnedItemsAreNotRetrieved() throws SyncException {
|
||||
final BookmarksRepository repo = new BookmarksRepository();
|
||||
|
||||
// Ensure that they exist.
|
||||
|
@ -69,7 +68,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
assertFalse(guids.contains("dapinneditem"));
|
||||
}
|
||||
|
||||
public void testRetrieveFolderHasAccurateChildren() {
|
||||
public void testRetrieveFolderHasAccurateChildren() throws SyncException {
|
||||
BookmarksRepository repo = new BookmarksRepository();
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
@ -179,7 +178,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
assertChildrenAreOrdered(repo, folderGUID, children);
|
||||
}
|
||||
|
||||
public void testMergeFoldersPreservesSaneOrder() {
|
||||
public void testMergeFoldersPreservesSaneOrder() throws SyncException {
|
||||
BookmarksRepository repo = new BookmarksRepository();
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
@ -271,7 +270,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
* stored in the database. Verify that the parent folder is not flagged
|
||||
* for reupload (i.e., that its modified time is *ahem* unmodified).
|
||||
*/
|
||||
public void testNoReorderingMeansNoReupload() {
|
||||
public void testNoReorderingMeansNoReupload() throws SyncException {
|
||||
BookmarksRepository repo = new BookmarksRepository();
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
@ -355,7 +354,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
* marked as deleted. In a database with constraints, this would fail
|
||||
* if we simply deleted the records, so we move them first.
|
||||
*/
|
||||
public void testFolderDeletionOrphansChildren() {
|
||||
public void testFolderDeletionOrphansChildren() throws SyncException {
|
||||
BookmarksRepository repo = new BookmarksRepository();
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -467,7 +466,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
* new GUID), whilst adding children to it. Verifies that replace and insert
|
||||
* co-operate.
|
||||
*/
|
||||
public void testInsertAndReplaceGuid() {
|
||||
public void testInsertAndReplaceGuid() throws SyncException {
|
||||
BookmarksRepository repo = new BookmarksRepository();
|
||||
wipe();
|
||||
|
||||
|
@ -517,7 +516,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
* new title but the same GUID), whilst adding children to it. Verifies that
|
||||
* replace and insert co-operate.
|
||||
*/
|
||||
public void testInsertAndReplaceTitle() {
|
||||
public void testInsertAndReplaceTitle() throws SyncException {
|
||||
BookmarksRepository repo = new BookmarksRepository();
|
||||
wipe();
|
||||
|
||||
|
@ -562,30 +561,6 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
assertEquals(bmk2.title, fetchGUID(repo, bmk2.guid).title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and begin a new session, handing control to the delegate when started.
|
||||
* Returns when the delegate has notified.
|
||||
*/
|
||||
private void inBegunSession(final BookmarksRepository repo) {
|
||||
Runnable go = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
repo.createSession(new SimpleSuccessCreationDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
try {
|
||||
session.begin();
|
||||
performNotify();
|
||||
} catch (SyncException e) {
|
||||
performNotify("Begin failed", e);
|
||||
}
|
||||
}
|
||||
}, getApplicationContext());
|
||||
}
|
||||
};
|
||||
performWait(go);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the provided session, notifying on success.
|
||||
*
|
||||
|
@ -616,127 +591,109 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
*/
|
||||
private void storeRecordsInSession(BookmarksRepository repo,
|
||||
final BookmarkRecord[] records,
|
||||
final Collection<String> tracked) {
|
||||
repo.createSession(new SimpleSuccessCreationDelegate() {
|
||||
final Collection<String> tracked) throws SyncException {
|
||||
final RepositorySession session = repo.createSession(getApplicationContext());
|
||||
session.begin();
|
||||
|
||||
RepositorySessionStoreDelegate storeDelegate = new SimpleSuccessStoreDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
performNotify("Begin failed", e);
|
||||
}
|
||||
|
||||
RepositorySessionStoreDelegate storeDelegate = new SimpleSuccessStoreDelegate() {
|
||||
@Override
|
||||
public void onStoreCompleted() {
|
||||
// Pass back whatever we tracked.
|
||||
if (tracked != null) {
|
||||
Iterator<String> iter = session.getTrackedRecordIDs();
|
||||
while (iter.hasNext()) {
|
||||
tracked.add(iter.next());
|
||||
}
|
||||
}
|
||||
finishAndNotify(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordStoreSucceeded(String guid) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordStoreReconciled(String guid, String oldGuid, Integer newVersion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoreFailed(Exception e) {
|
||||
|
||||
}
|
||||
};
|
||||
session.setStoreDelegate(storeDelegate);
|
||||
for (BookmarkRecord record : records) {
|
||||
try {
|
||||
session.store(record);
|
||||
} catch (NoStoreDelegateException e) {
|
||||
// Never happens.
|
||||
public void onStoreCompleted() {
|
||||
// Pass back whatever we tracked.
|
||||
if (tracked != null) {
|
||||
Iterator<String> iter = session.getTrackedRecordIDs();
|
||||
while (iter.hasNext()) {
|
||||
tracked.add(iter.next());
|
||||
}
|
||||
}
|
||||
session.storeDone();
|
||||
finishAndNotify(session);
|
||||
}
|
||||
}, getApplicationContext());
|
||||
|
||||
@Override
|
||||
public void onRecordStoreSucceeded(String guid) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordStoreReconciled(String guid, String oldGuid, Integer newVersion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoreFailed(Exception e) {
|
||||
|
||||
}
|
||||
};
|
||||
session.setStoreDelegate(storeDelegate);
|
||||
for (BookmarkRecord record : records) {
|
||||
try {
|
||||
session.store(record);
|
||||
} catch (NoStoreDelegateException e) {
|
||||
// Never happens.
|
||||
}
|
||||
}
|
||||
session.storeDone();
|
||||
}
|
||||
|
||||
public ArrayList<String> fetchGUIDs(BookmarksRepository repo) {
|
||||
final ArrayList<String> fetchedGUIDs = new ArrayList<String>();
|
||||
private ArrayList<String> fetchGUIDs(BookmarksRepository repo) throws SyncException {
|
||||
final ArrayList<String> fetchedGUIDs = new ArrayList<>();
|
||||
|
||||
repo.createSession(new SimpleSuccessCreationDelegate() {
|
||||
final RepositorySession session = repo.createSession(getApplicationContext());
|
||||
session.begin();
|
||||
|
||||
RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
performNotify("Begin failed", e);
|
||||
}
|
||||
|
||||
RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
|
||||
@Override
|
||||
public void onFetchedRecord(Record record) {
|
||||
fetchedGUIDs.add(record.guid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchCompleted() {
|
||||
finishAndNotify(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatchCompleted() {
|
||||
|
||||
}
|
||||
};
|
||||
session.fetchModified(fetchDelegate);
|
||||
public void onFetchedRecord(Record record) {
|
||||
fetchedGUIDs.add(record.guid);
|
||||
}
|
||||
}, getApplicationContext());
|
||||
|
||||
@Override
|
||||
public void onFetchCompleted() {
|
||||
finishAndNotify(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatchCompleted() {
|
||||
|
||||
}
|
||||
};
|
||||
session.fetchModified(fetchDelegate);
|
||||
|
||||
return fetchedGUIDs;
|
||||
}
|
||||
|
||||
private BookmarkRecord fetchGUID(BookmarksRepository repo,
|
||||
final String guid) {
|
||||
final String guid) throws SyncException {
|
||||
Logger.info(LOG_TAG, "Fetching for " + guid);
|
||||
final ArrayList<Record> fetchedRecords = new ArrayList<>();
|
||||
|
||||
repo.createSession(new SimpleSuccessCreationDelegate() {
|
||||
final RepositorySession session = repo.createSession(getApplicationContext());
|
||||
session.begin();
|
||||
|
||||
final RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
public void onFetchedRecord(Record record) {
|
||||
fetchedRecords.add(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchCompleted() {
|
||||
finishAndNotify(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatchCompleted() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
performWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
performNotify("Begin failed", e);
|
||||
}
|
||||
|
||||
RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
|
||||
@Override
|
||||
public void onFetchedRecord(Record record) {
|
||||
fetchedRecords.add(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchCompleted() {
|
||||
finishAndNotify(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatchCompleted() {
|
||||
|
||||
}
|
||||
};
|
||||
try {
|
||||
session.fetch(new String[] { guid }, fetchDelegate);
|
||||
session.fetch(new String[]{guid}, fetchDelegate);
|
||||
} catch (InactiveSessionException e) {
|
||||
performNotify("Session is inactive.", e);
|
||||
performNotify(e);
|
||||
}
|
||||
}
|
||||
}, getApplicationContext());
|
||||
});
|
||||
|
||||
assertEquals(1, fetchedRecords.size());
|
||||
Record fetchedRecord = fetchedRecords.get(0);
|
||||
|
@ -746,7 +703,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
}
|
||||
|
||||
public JSONArray fetchChildrenForGUID(BookmarksRepository repo,
|
||||
final String guid) {
|
||||
final String guid) throws SyncException {
|
||||
return fetchGUID(repo, guid).children;
|
||||
}
|
||||
|
||||
|
@ -927,7 +884,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
getDataAccessor().wipe();
|
||||
}
|
||||
|
||||
protected void assertChildrenAreOrdered(BookmarksRepository repo, String guid, Record[] expected) {
|
||||
protected void assertChildrenAreOrdered(BookmarksRepository repo, String guid, Record[] expected) throws SyncException {
|
||||
Logger.debug(getName(), "Fetching children...");
|
||||
JSONArray folderChildren = fetchChildrenForGUID(repo, guid);
|
||||
|
||||
|
@ -939,7 +896,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected void assertChildrenAreUnordered(BookmarksRepository repo, String guid, Record[] expected) {
|
||||
protected void assertChildrenAreUnordered(BookmarksRepository repo, String guid, Record[] expected) throws SyncException {
|
||||
Logger.debug(getName(), "Fetching children...");
|
||||
JSONArray folderChildren = fetchChildrenForGUID(repo, guid);
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@ import org.mozilla.gecko.background.sync.helpers.SessionTestHelper;
|
|||
import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserContract.Clients;
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.repositories.NoContentProviderException;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
|
||||
import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor;
|
||||
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
|
||||
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository.FennecTabsRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
import org.mozilla.gecko.sync.repositories.domain.TabsRecord;
|
||||
|
@ -106,10 +106,9 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
|
|||
*/
|
||||
return new FennecTabsRepository(clientsDataDelegate) {
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
public RepositorySession createSession(Context context) throws SessionCreateException {
|
||||
try {
|
||||
final FennecTabsRepositorySession session = new FennecTabsRepositorySession(this, context) {
|
||||
return new FennecTabsRepositorySession(this, context) {
|
||||
@Override
|
||||
protected synchronized void trackGUID(String guid) {
|
||||
}
|
||||
|
@ -124,9 +123,8 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
|
|||
return TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS;
|
||||
}
|
||||
};
|
||||
delegate.onSessionCreated(session);
|
||||
} catch (Exception e) {
|
||||
delegate.onSessionCreateFailed(e);
|
||||
throw new SessionCreateException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -212,7 +210,7 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testFetchAll() throws NoContentProviderException, RemoteException {
|
||||
public void testFetchAll() throws Exception {
|
||||
final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
|
||||
|
||||
final FennecTabsRepositorySession session = createAndBeginSession();
|
||||
|
@ -221,7 +219,7 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testFetchSince() throws NoContentProviderException, RemoteException {
|
||||
public void testFetchSince() throws Exception {
|
||||
final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
|
||||
|
||||
final FennecTabsRepositorySession session = createAndBeginSession();
|
||||
|
@ -248,7 +246,7 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
|
|||
|
||||
// Verify that storing a tabs record writes a clients record with the correct
|
||||
// device type to the Fennec clients provider.
|
||||
public void testStore() throws NoContentProviderException, RemoteException {
|
||||
public void testStore() throws Exception {
|
||||
// Get a valid tabsRecord to write.
|
||||
final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
|
||||
deleteAllTestTabs(tabsClient);
|
||||
|
|
|
@ -13,13 +13,13 @@ import org.mozilla.gecko.background.sync.helpers.ExpectStoredDelegate;
|
|||
import org.mozilla.gecko.background.sync.helpers.SessionTestHelper;
|
||||
import org.mozilla.gecko.background.testhelpers.WaitHelper;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoContentProviderException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
|
||||
import org.mozilla.gecko.sync.repositories.android.FormHistoryRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.FormHistoryRecord;
|
||||
|
@ -69,17 +69,15 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
*/
|
||||
return new FormHistoryRepositorySession.FormHistoryRepository() {
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
public RepositorySession createSession(Context context) throws SessionCreateException {
|
||||
try {
|
||||
final FormHistoryRepositorySession session = new FormHistoryRepositorySession(this, context) {
|
||||
return new FormHistoryRepositorySession(this, context) {
|
||||
@Override
|
||||
protected synchronized void trackGUID(String guid) {
|
||||
}
|
||||
};
|
||||
delegate.onSessionCreated(session);
|
||||
} catch (Exception e) {
|
||||
delegate.onSessionCreateFailed(e);
|
||||
throw new SessionCreateException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -98,7 +96,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
getRepository());
|
||||
}
|
||||
|
||||
public void testAcquire() throws NoContentProviderException {
|
||||
public void testAcquire() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
assertNotNull(session.getFormsProvider());
|
||||
session.abort();
|
||||
|
@ -186,7 +184,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
after4 = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void testWipe() throws NoContentProviderException, RemoteException {
|
||||
public void testWipe() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertTwoRecords(session);
|
||||
|
@ -248,7 +246,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
public void testFetchAll() throws NoContentProviderException, RemoteException {
|
||||
public void testFetchAll() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertTwoRecords(session);
|
||||
|
@ -258,7 +256,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testFetchByGuid() throws NoContentProviderException, RemoteException {
|
||||
public void testFetchByGuid() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertTwoRecords(session);
|
||||
|
@ -279,7 +277,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testFetchSince() throws NoContentProviderException, RemoteException {
|
||||
public void testFetchSince() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertFourRecords(session);
|
||||
|
@ -313,7 +311,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
public void testStoreRemoteNew() throws NoContentProviderException, RemoteException {
|
||||
public void testStoreRemoteNew() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertTwoRecords(session);
|
||||
|
@ -335,7 +333,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testStoreRemoteNewer() throws NoContentProviderException, RemoteException {
|
||||
public void testStoreRemoteNewer() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertFourRecords(session);
|
||||
|
@ -370,7 +368,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testStoreRemoteOlder() throws NoContentProviderException, RemoteException {
|
||||
public void testStoreRemoteOlder() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
long oldTimestamp = System.currentTimeMillis() - 100;
|
||||
|
@ -401,7 +399,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
|
|||
session.abort();
|
||||
}
|
||||
|
||||
public void testStoreDifferentGuid() throws NoContentProviderException, RemoteException {
|
||||
public void testStoreDifferentGuid() throws Exception {
|
||||
final FormHistoryRepositorySession session = createAndBeginSession();
|
||||
|
||||
insertTwoRecords(session);
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.mozilla.gecko.sync.repositories.RepositorySession;
|
|||
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
|
||||
import org.mozilla.gecko.sync.repositories.android.PasswordsRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.RepoUtils;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.PasswordRecord;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
|
@ -32,7 +31,6 @@ import android.content.ContentProviderClient;
|
|||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.RemoteException;
|
||||
|
||||
public class TestPasswordsRepository extends AndroidSyncTestCase {
|
||||
private final String NEW_PASSWORD1 = "password";
|
||||
|
@ -44,7 +42,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
assertTrue(WaitHelper.getTestWaiter().isIdle());
|
||||
}
|
||||
|
||||
public void testFetchAll() {
|
||||
public void testFetchAll() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
Record[] expected = new Record[] { PasswordHelpers.createPassword1(),
|
||||
PasswordHelpers.createPassword2() };
|
||||
|
@ -56,7 +54,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testFetchSinceOneRecord() {
|
||||
public void testFetchSinceOneRecord() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
|
||||
// Passwords fetchModified checks timePasswordChanged, not insertion time.
|
||||
|
@ -77,7 +75,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testFetchSinceReturnNoRecords() {
|
||||
public void testFetchSinceReturnNoRecords() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
|
||||
performWait(storeRunnable(session, PasswordHelpers.createPassword2()));
|
||||
|
@ -88,7 +86,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testFetchOneRecordByGuid() {
|
||||
public void testFetchOneRecordByGuid() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
Record record = PasswordHelpers.createPassword1();
|
||||
performWait(storeRunnable(session, record));
|
||||
|
@ -100,7 +98,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testFetchMultipleRecordsByGuids() {
|
||||
public void testFetchMultipleRecordsByGuids() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
PasswordRecord record1 = PasswordHelpers.createPassword1();
|
||||
PasswordRecord record2 = PasswordHelpers.createPassword2();
|
||||
|
@ -116,7 +114,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testFetchNoRecordByGuid() {
|
||||
public void testFetchNoRecordByGuid() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
Record record = PasswordHelpers.createPassword1();
|
||||
|
||||
|
@ -127,13 +125,13 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testStore() {
|
||||
public void testStore() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
performWait(storeRunnable(session, PasswordHelpers.createPassword1()));
|
||||
dispose(session);
|
||||
}
|
||||
|
||||
public void testRemoteNewerTimeStamp() {
|
||||
public void testRemoteNewerTimeStamp() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
|
||||
// Store updated local record.
|
||||
|
@ -183,7 +181,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testLocalNewerTimeStamp() {
|
||||
public void testLocalNewerTimeStamp() throws Exception {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
// Remote record updated before local record.
|
||||
PasswordRecord remote = PasswordHelpers.createPassword1();
|
||||
|
@ -242,7 +240,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
* Store two records that are identical except for guid. Expect to find the
|
||||
* remote one after reconciling.
|
||||
*/
|
||||
public void testStoreIdenticalExceptGuid() {
|
||||
public void testStoreIdenticalExceptGuid() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
PasswordRecord record = PasswordHelpers.createPassword1();
|
||||
record.guid = "before1";
|
||||
|
@ -276,7 +274,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
* to the same site and there are multiple records for that site. Expect to
|
||||
* find the remote one after reconciling.
|
||||
*/
|
||||
public void testStoreIdenticalExceptGuidOnSameSite() {
|
||||
public void testStoreIdenticalExceptGuidOnSameSite() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
PasswordRecord record1 = PasswordHelpers.createPassword1();
|
||||
record1.encryptedUsername = "original";
|
||||
|
@ -304,7 +302,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
dispose(session);
|
||||
}
|
||||
|
||||
public void testRawFetch() throws RemoteException {
|
||||
public void testRawFetch() throws Exception {
|
||||
RepositorySession session = createAndBeginSession();
|
||||
Record[] expected = new Record[] { PasswordHelpers.createPassword1(),
|
||||
PasswordHelpers.createPassword2() };
|
||||
|
@ -343,15 +341,12 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
|
|||
*/
|
||||
return new PasswordsRepositorySession.PasswordsRepository() {
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
PasswordsRepositorySession session;
|
||||
session = new PasswordsRepositorySession(this, context) {
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new PasswordsRepositorySession(this, context) {
|
||||
@Override
|
||||
protected synchronized void trackGUID(String guid) {
|
||||
}
|
||||
};
|
||||
delegate.onSessionCreated(session);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
|
|||
import org.mozilla.gecko.background.sync.helpers.DefaultCleanDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.DefaultFetchDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.DefaultFinishDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.DefaultSessionCreationDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.DefaultStoreDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate;
|
||||
|
@ -624,8 +623,9 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
|
|||
public void testCreateSessionNullContext() {
|
||||
Logger.debug(LOG_TAG, "In testCreateSessionNullContext.");
|
||||
Repository repo = getRepository();
|
||||
|
||||
try {
|
||||
repo.createSession(new DefaultSessionCreationDelegate(), null);
|
||||
repo.createSession(null);
|
||||
fail("Should throw.");
|
||||
} catch (Exception ex) {
|
||||
assertNotNull(ex);
|
||||
|
@ -675,7 +675,7 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
|
|||
fail("Should have caught InvalidSessionTransitionException.");
|
||||
}
|
||||
|
||||
public void testBeginOnFinishedSession() throws InactiveSessionException {
|
||||
public void testBeginOnFinishedSession() {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
performWait(finishRunnable(session, new ExpectFinishDelegate()));
|
||||
try {
|
||||
|
@ -692,7 +692,7 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
|
|||
fail("Should have caught InvalidSessionTransitionException.");
|
||||
}
|
||||
|
||||
public void testFinishOnFinishedSession() throws InactiveSessionException {
|
||||
public void testFinishOnFinishedSession() {
|
||||
final RepositorySession session = createAndBeginSession();
|
||||
performWait(finishRunnable(session, new ExpectFinishDelegate()));
|
||||
try {
|
||||
|
@ -704,7 +704,7 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
|
|||
fail("Should have caught InactiveSessionException.");
|
||||
}
|
||||
|
||||
public void testFetchOnInactiveSession() throws InactiveSessionException {
|
||||
public void testFetchOnInactiveSession() {
|
||||
final RepositorySession session = createSession();
|
||||
try {
|
||||
session.fetch(new String[] { Utils.generateGuid() }, new DefaultFetchDelegate());
|
||||
|
@ -730,12 +730,6 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
|
|||
fail("Should have caught InactiveSessionException.");
|
||||
}
|
||||
|
||||
private static void verifyInactiveException(Exception ex) {
|
||||
if (!(ex instanceof InactiveSessionException)) {
|
||||
fail("Wrong exception type");
|
||||
}
|
||||
}
|
||||
|
||||
protected void closeDataAccessor(DataAccessor dataAccessor) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,16 @@ import junit.framework.AssertionFailedError;
|
|||
|
||||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessCreationDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate;
|
||||
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate;
|
||||
import org.mozilla.gecko.background.testhelpers.WBORepository;
|
||||
import org.mozilla.gecko.sync.CryptoRecord;
|
||||
import org.mozilla.gecko.sync.ExtendedJSONObject;
|
||||
import org.mozilla.gecko.sync.SyncException;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
import org.mozilla.gecko.sync.synchronizer.Synchronizer;
|
||||
|
@ -134,30 +130,33 @@ public class TestStoreTracking extends AndroidSyncTestCase {
|
|||
}
|
||||
};
|
||||
|
||||
session.setStoreDelegate(storeDelegate);
|
||||
try {
|
||||
Logger.debug(getName(), "Storing...");
|
||||
session.store(record);
|
||||
session.storeDone();
|
||||
} catch (NoStoreDelegateException e) {
|
||||
// Should not happen.
|
||||
}
|
||||
final Runnable doStore = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
session.setStoreDelegate(storeDelegate);
|
||||
try {
|
||||
Logger.debug(getName(), "Storing...");
|
||||
session.store(record);
|
||||
session.storeDone();
|
||||
} catch (NoStoreDelegateException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
performWait(doStore);
|
||||
}
|
||||
|
||||
private void doTestNewSessionRetrieveByTime(final WBORepository repository,
|
||||
final String expectedGUID) {
|
||||
final SimpleSuccessCreationDelegate createDelegate = new SimpleSuccessCreationDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
Logger.debug(getName(), "Session created.");
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
e.printStackTrace();
|
||||
performNotify(e);
|
||||
}
|
||||
final String expectedGUID) throws Exception {
|
||||
final RepositorySession session = repository.createSession(getApplicationContext());
|
||||
Logger.debug(getName(), "Session created.");
|
||||
session.begin();
|
||||
|
||||
// Now we get a result.
|
||||
// Now we get a result.
|
||||
final Runnable doFetch = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
session.fetchModified(new SimpleSuccessFetchDelegate() {
|
||||
@Override
|
||||
public void onFetchedRecord(Record record) {
|
||||
|
@ -171,9 +170,13 @@ public class TestStoreTracking extends AndroidSyncTestCase {
|
|||
@Override
|
||||
public void onFinishSucceeded(RepositorySession session,
|
||||
RepositorySessionBundle bundle) {
|
||||
// Hooray!
|
||||
performNotify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishFailed(Exception ex) {
|
||||
performNotify(ex);
|
||||
}
|
||||
});
|
||||
} catch (InactiveSessionException e) {
|
||||
performNotify(e);
|
||||
|
@ -186,14 +189,8 @@ public class TestStoreTracking extends AndroidSyncTestCase {
|
|||
});
|
||||
}
|
||||
};
|
||||
Runnable create = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
repository.createSession(createDelegate, getApplicationContext());
|
||||
}
|
||||
};
|
||||
|
||||
performWait(create);
|
||||
performWait(doFetch);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,49 +201,20 @@ public class TestStoreTracking extends AndroidSyncTestCase {
|
|||
*
|
||||
* Invokes doTestStoreRetrieveByGUID, doTestNewSessionRetrieveByTime.
|
||||
*/
|
||||
public void testStoreRetrieveByGUID() {
|
||||
public void testStoreRetrieveByGUID() throws Exception {
|
||||
Logger.debug(getName(), "Started.");
|
||||
final WBORepository r = new TrackingWBORepository();
|
||||
final long now = System.currentTimeMillis();
|
||||
final String expectedGUID = "abcdefghijkl";
|
||||
final Record record = new BookmarkRecord(expectedGUID, "bookmarks", now , false);
|
||||
|
||||
final RepositorySessionCreationDelegate createDelegate = new SimpleSuccessCreationDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
Logger.debug(getName(), "Session created: " + session);
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
e.printStackTrace();
|
||||
performNotify(e);
|
||||
}
|
||||
|
||||
doTestStoreRetrieveByGUID(r, session, expectedGUID, record);
|
||||
}
|
||||
};
|
||||
|
||||
final Context applicationContext = getApplicationContext();
|
||||
|
||||
// This has to happen on a new thread so that we
|
||||
// can wait for it!
|
||||
Runnable create = onThreadRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
r.createSession(createDelegate, applicationContext);
|
||||
}
|
||||
});
|
||||
final RepositorySession session = r.createSession(applicationContext);
|
||||
session.begin();
|
||||
doTestStoreRetrieveByGUID(r, session, expectedGUID, record);
|
||||
|
||||
Runnable retrieve = onThreadRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTestNewSessionRetrieveByTime(r, expectedGUID);
|
||||
performNotify();
|
||||
}
|
||||
});
|
||||
|
||||
performWait(create);
|
||||
performWait(retrieve);
|
||||
doTestNewSessionRetrieveByTime(r, expectedGUID);
|
||||
}
|
||||
|
||||
private Runnable onThreadRunnable(final Runnable r) {
|
||||
|
@ -276,9 +244,8 @@ public class TestStoreTracking extends AndroidSyncTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new CountingWBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new CountingWBORepositorySession(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
package org.mozilla.gecko.background.sync.helpers;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
public class DefaultSessionCreationDelegate extends DefaultDelegate implements
|
||||
RepositorySessionCreationDelegate {
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
performNotify("Session creation failed", ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
performNotify("Should not have been created.", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
final RepositorySessionCreationDelegate self = this;
|
||||
return new RepositorySessionCreationDelegate() {
|
||||
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
self.onSessionCreated(session);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(final Exception ex) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
self.onSessionCreateFailed(ex);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -5,71 +5,34 @@ package org.mozilla.gecko.background.sync.helpers;
|
|||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.background.testhelpers.WaitHelper;
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.SyncException;
|
||||
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class SessionTestHelper {
|
||||
|
||||
protected static RepositorySession prepareRepositorySession(
|
||||
private static RepositorySession prepareRepositorySession(
|
||||
final Context context,
|
||||
final boolean begin,
|
||||
final Repository repository) {
|
||||
|
||||
final WaitHelper testWaiter = WaitHelper.getTestWaiter();
|
||||
|
||||
final String logTag = "prepareRepositorySession";
|
||||
class CreationDelegate extends DefaultSessionCreationDelegate {
|
||||
private RepositorySession session;
|
||||
synchronized void setSession(RepositorySession session) {
|
||||
this.session = session;
|
||||
}
|
||||
synchronized RepositorySession getSession() {
|
||||
return this.session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
assertNotNull(session);
|
||||
Logger.info(logTag, "Setting session to " + session);
|
||||
setSession(session);
|
||||
if (begin) {
|
||||
Logger.info(logTag, "Calling session.begin on new session.");
|
||||
// The begin callbacks will notify.
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
testWaiter.performNotify(e);
|
||||
}
|
||||
testWaiter.performNotify();
|
||||
} else {
|
||||
Logger.info(logTag, "Notifying after setting new session.");
|
||||
testWaiter.performNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final CreationDelegate delegate = new CreationDelegate();
|
||||
final RepositorySession session;
|
||||
try {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
repository.createSession(delegate, context);
|
||||
}
|
||||
};
|
||||
testWaiter.performWait(runnable);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.warn(logTag, "Caught IllegalArgumentException.");
|
||||
session = repository.createSession(context);
|
||||
assertNotNull(session);
|
||||
} catch (SessionCreateException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
Logger.info(logTag, "Retrieving new session.");
|
||||
final RepositorySession session = delegate.getSession();
|
||||
assertNotNull(session);
|
||||
if (begin) {
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
package org.mozilla.gecko.background.sync.helpers;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
public abstract class SimpleSuccessCreationDelegate extends DefaultDelegate implements RepositorySessionCreationDelegate {
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
performNotify("Session creation failed", ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -14,8 +14,8 @@ import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
|||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFilter;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
|
@ -212,9 +212,8 @@ public class WBORepository extends Repository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new WBORepositorySession(this);
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, Record> cloneWBOs() {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/* 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;
|
||||
|
||||
public class SessionCreateException extends SyncException {
|
||||
private static final long serialVersionUID = -3852991560658529574L;
|
||||
|
||||
public SessionCreateException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
|
@ -6,10 +6,10 @@ package org.mozilla.gecko.sync.middleware;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.middleware.storage.BufferStorage;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
/**
|
||||
* A buffering-enabled middleware which is intended to wrap local repositories. Configurable with
|
||||
|
@ -17,33 +17,11 @@ import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDe
|
|||
*
|
||||
* @author grisha
|
||||
*/
|
||||
public class BufferingMiddlewareRepository extends MiddlewareRepository {
|
||||
public class BufferingMiddlewareRepository extends Repository {
|
||||
private final long syncDeadline;
|
||||
private final Repository inner;
|
||||
private final BufferStorage bufferStorage;
|
||||
|
||||
private class BufferingMiddlewareRepositorySessionCreationDelegate extends MiddlewareRepository.SessionCreationDelegate {
|
||||
private final BufferingMiddlewareRepository repository;
|
||||
private final RepositorySessionCreationDelegate outerDelegate;
|
||||
|
||||
private BufferingMiddlewareRepositorySessionCreationDelegate(BufferingMiddlewareRepository repository, RepositorySessionCreationDelegate outerDelegate) {
|
||||
this.repository = repository;
|
||||
this.outerDelegate = outerDelegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
this.outerDelegate.onSessionCreateFailed(ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
outerDelegate.onSessionCreated(new BufferingMiddlewareRepositorySession(
|
||||
session, this.repository, syncDeadline, bufferStorage
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public BufferingMiddlewareRepository(long syncDeadline, BufferStorage bufferStore, Repository wrappedRepository) {
|
||||
this.syncDeadline = syncDeadline;
|
||||
this.inner = wrappedRepository;
|
||||
|
@ -51,10 +29,8 @@ public class BufferingMiddlewareRepository extends MiddlewareRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
this.inner.createSession(
|
||||
new BufferingMiddlewareRepositorySessionCreationDelegate(this, delegate),
|
||||
context
|
||||
);
|
||||
public RepositorySession createSession(Context context) throws SessionCreateException {
|
||||
final RepositorySession innerSession = this.inner.createSession(context);
|
||||
return new BufferingMiddlewareRepositorySession(innerSession, this, syncDeadline, bufferStorage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.mozilla.gecko.sync.SyncDeadlineReachedException;
|
|||
import org.mozilla.gecko.sync.middleware.storage.BufferStorage;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate;
|
||||
|
@ -33,7 +34,7 @@ import java.util.Collection;
|
|||
private final long syncDeadlineMillis;
|
||||
|
||||
/* package-local */ BufferingMiddlewareRepositorySession(
|
||||
RepositorySession repositorySession, MiddlewareRepository repository,
|
||||
RepositorySession repositorySession, BufferingMiddlewareRepository repository,
|
||||
long syncDeadlineMillis, BufferStorage bufferStorage) {
|
||||
super(repositorySession, repository);
|
||||
this.syncDeadlineMillis = syncDeadlineMillis;
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
package org.mozilla.gecko.sync.middleware;
|
||||
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.crypto.KeyBundle;
|
||||
import org.mozilla.gecko.sync.repositories.IdentityRecordFactory;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFactory;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
|
@ -21,39 +21,9 @@ import android.content.Context;
|
|||
* @author rnewman
|
||||
*
|
||||
*/
|
||||
public class Crypto5MiddlewareRepository extends MiddlewareRepository {
|
||||
|
||||
public class Crypto5MiddlewareRepository extends Repository {
|
||||
public RecordFactory recordFactory = new IdentityRecordFactory();
|
||||
|
||||
public class Crypto5MiddlewareRepositorySessionCreationDelegate extends MiddlewareRepository.SessionCreationDelegate {
|
||||
private final Crypto5MiddlewareRepository repository;
|
||||
private final RepositorySessionCreationDelegate outerDelegate;
|
||||
|
||||
public Crypto5MiddlewareRepositorySessionCreationDelegate(Crypto5MiddlewareRepository repository, RepositorySessionCreationDelegate outerDelegate) {
|
||||
this.repository = repository;
|
||||
this.outerDelegate = outerDelegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
this.outerDelegate.onSessionCreateFailed(ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
// Do some work, then report success with the wrapping session.
|
||||
Crypto5MiddlewareRepositorySession cryptoSession;
|
||||
try {
|
||||
// Synchronous, baby.
|
||||
cryptoSession = new Crypto5MiddlewareRepositorySession(session, this.repository, recordFactory);
|
||||
} catch (Exception ex) {
|
||||
this.outerDelegate.onSessionCreateFailed(ex);
|
||||
return;
|
||||
}
|
||||
this.outerDelegate.onSessionCreated(cryptoSession);
|
||||
}
|
||||
}
|
||||
|
||||
public KeyBundle keyBundle;
|
||||
private final Repository inner;
|
||||
|
||||
|
@ -62,10 +32,11 @@ public class Crypto5MiddlewareRepository extends MiddlewareRepository {
|
|||
this.inner = inner;
|
||||
this.keyBundle = keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
Crypto5MiddlewareRepositorySessionCreationDelegate delegateWrapper = new Crypto5MiddlewareRepositorySessionCreationDelegate(this, delegate);
|
||||
inner.createSession(delegateWrapper, context);
|
||||
public RepositorySession createSession(Context context) throws SessionCreateException {
|
||||
final RepositorySession innerSession = inner.createSession(context);
|
||||
return new Crypto5MiddlewareRepositorySession(innerSession, this, recordFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/* 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.middleware;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
public abstract class MiddlewareRepository extends Repository {
|
||||
|
||||
public static abstract class SessionCreationDelegate implements
|
||||
RepositorySessionCreationDelegate {
|
||||
|
||||
// We call through to our inner repository, so we don't need our own
|
||||
// deferral scheme.
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import org.mozilla.gecko.sync.SyncException;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
|
@ -18,7 +19,7 @@ public abstract class MiddlewareRepositorySession extends RepositorySession {
|
|||
private static final String LOG_TAG = "MiddlewareSession";
|
||||
protected final RepositorySession inner;
|
||||
|
||||
public MiddlewareRepositorySession(RepositorySession innerSession, MiddlewareRepository repository) {
|
||||
/* package-private */ MiddlewareRepositorySession(RepositorySession innerSession, Repository repository) {
|
||||
super(repository);
|
||||
this.inner = innerSession;
|
||||
}
|
||||
|
@ -37,7 +38,7 @@ public abstract class MiddlewareRepositorySession extends RepositorySession {
|
|||
private final MiddlewareRepositorySession outerSession;
|
||||
private final RepositorySessionFinishDelegate next;
|
||||
|
||||
public MiddlewareRepositorySessionFinishDelegate(MiddlewareRepositorySession outerSession, RepositorySessionFinishDelegate next) {
|
||||
/* package-private */ MiddlewareRepositorySessionFinishDelegate(MiddlewareRepositorySession outerSession, RepositorySessionFinishDelegate next) {
|
||||
this.outerSession = outerSession;
|
||||
this.next = next;
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/* 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;
|
||||
|
||||
/**
|
||||
* Shared interface for repositories that consume and produce
|
||||
* bookmark records.
|
||||
*
|
||||
* @author rnewman
|
||||
*
|
||||
*/
|
||||
public interface BookmarksRepository {
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
/* 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;
|
||||
|
||||
/**
|
||||
* Shared interface for repositories that consume and produce
|
||||
* history records.
|
||||
*
|
||||
* @author rnewman
|
||||
*
|
||||
*/
|
||||
public interface HistoryRepository {
|
||||
|
||||
}
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
package org.mozilla.gecko.sync.repositories;
|
||||
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public abstract class Repository {
|
||||
public abstract void createSession(RepositorySessionCreationDelegate delegate, Context context);
|
||||
public abstract RepositorySession createSession(Context context) throws SessionCreateException;
|
||||
|
||||
public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
|
||||
delegate.onCleaned(this);
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.mozilla.gecko.sync.repositories.domain.Record;
|
|||
*
|
||||
*<ul>
|
||||
* <li>Construct, with a reference to its parent {@link Repository}, by calling
|
||||
* {@link Repository#createSession(org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate, android.content.Context)}.</li>
|
||||
* {@link Repository#createSession(android.content.Context)}.</li>
|
||||
* <li>Populate with saved information by calling {@link #unbundle(RepositorySessionBundle)}.</li>
|
||||
* <li>Begin a sync by calling {@link #begin()}. <code>begin()</code>
|
||||
* is an appropriate place to initialize expensive resources.</li>
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.net.URISyntaxException;
|
|||
import org.mozilla.gecko.sync.InfoCollections;
|
||||
import org.mozilla.gecko.sync.InfoConfiguration;
|
||||
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -73,9 +72,8 @@ public class Server15Repository extends Repository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.onSessionCreated(new Server15RepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new Server15RepositorySession(this);
|
||||
}
|
||||
|
||||
public URI collectionURI() {
|
||||
|
|
|
@ -4,21 +4,33 @@
|
|||
|
||||
package org.mozilla.gecko.sync.repositories.android;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class BookmarksRepository extends ThreadedRepository implements org.mozilla.gecko.sync.repositories.BookmarksRepository {
|
||||
|
||||
public class BookmarksRepository extends Repository {
|
||||
@Override
|
||||
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
BookmarksRepositorySession session = new BookmarksRepositorySession(BookmarksRepository.this, context);
|
||||
final RepositorySessionCreationDelegate deferredCreationDelegate = delegate.deferredCreationDelegate();
|
||||
deferredCreationDelegate.onSessionCreated(session);
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new BookmarksRepositorySession(this, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataAccessor getDataAccessor(Context context) {
|
||||
return new BookmarksDataAccessor(context);
|
||||
public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BookmarksDataAccessor dataAccessor = new BookmarksDataAccessor(context);
|
||||
|
||||
try {
|
||||
dataAccessor.purgeDeleted();
|
||||
} catch (Exception e) {
|
||||
delegate.onCleanFailed(this, e);
|
||||
return;
|
||||
}
|
||||
|
||||
delegate.onCleaned(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
|||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
|
@ -62,8 +61,8 @@ public class BookmarksValidationRepository extends Repository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
delegate.onSessionCreated(new BookmarksValidationRepositorySession(this, context));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new BookmarksValidationRepositorySession(this, context);
|
||||
}
|
||||
|
||||
public class BookmarksValidationRepositorySession extends RepositorySession {
|
||||
|
|
|
@ -10,13 +10,13 @@ import org.mozilla.gecko.background.common.log.Logger;
|
|||
import org.mozilla.gecko.background.db.Tab;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserContract.Clients;
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoContentProviderException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
|
@ -309,13 +309,11 @@ public class FennecTabsRepository extends Repository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
public RepositorySession createSession(Context context) throws SessionCreateException {
|
||||
try {
|
||||
final FennecTabsRepositorySession session = new FennecTabsRepositorySession(this, context);
|
||||
delegate.onSessionCreated(session);
|
||||
return new FennecTabsRepositorySession(this, context);
|
||||
} catch (Exception e) {
|
||||
delegate.onSessionCreateFailed(e);
|
||||
throw new SessionCreateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@ import org.mozilla.gecko.background.common.log.Logger;
|
|||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory;
|
||||
import org.mozilla.gecko.db.BrowserContract.FormHistory;
|
||||
import org.mozilla.gecko.sync.SessionCreateException;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoContentProviderException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.NullCursorException;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFilter;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
|
@ -49,13 +50,11 @@ public class FormHistoryRepositorySession extends
|
|||
public static class FormHistoryRepository extends Repository {
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
public RepositorySession createSession(Context context) throws SessionCreateException {
|
||||
try {
|
||||
final FormHistoryRepositorySession session = new FormHistoryRepositorySession(this, context);
|
||||
delegate.onSessionCreated(session);
|
||||
return new FormHistoryRepositorySession(this, context);
|
||||
} catch (Exception e) {
|
||||
delegate.onSessionCreateFailed(e);
|
||||
throw new SessionCreateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,21 +4,33 @@
|
|||
|
||||
package org.mozilla.gecko.sync.repositories.android;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class HistoryRepository extends ThreadedRepository implements org.mozilla.gecko.sync.repositories.HistoryRepository {
|
||||
|
||||
public class HistoryRepository extends Repository {
|
||||
@Override
|
||||
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
HistoryRepositorySession session = new HistoryRepositorySession(HistoryRepository.this, context);
|
||||
delegate.onSessionCreated(session);
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new HistoryRepositorySession(this, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataAccessor getDataAccessor(Context context) {
|
||||
return new HistoryDataAccessor(context);
|
||||
}
|
||||
public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
final HistoryDataAccessor dataAccessor = new HistoryDataAccessor(context);
|
||||
|
||||
try {
|
||||
dataAccessor.purgeDeleted();
|
||||
} catch (Exception e) {
|
||||
delegate.onCleanFailed(this, e);
|
||||
return;
|
||||
}
|
||||
|
||||
delegate.onCleaned(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
|||
import org.mozilla.gecko.sync.repositories.NullCursorException;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFilter;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.android.RepoUtils.QueryHelper;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
|
@ -36,11 +36,8 @@ public class PasswordsRepositorySession extends
|
|||
|
||||
public static class PasswordsRepository extends Repository {
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
PasswordsRepositorySession session = new PasswordsRepositorySession(PasswordsRepository.this, context);
|
||||
final RepositorySessionCreationDelegate deferredCreationDelegate = delegate.deferredCreationDelegate();
|
||||
deferredCreationDelegate.onSessionCreated(session);
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new PasswordsRepositorySession(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/* 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.android;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public abstract class ThreadedRepository extends Repository {
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
new CreateSessionThread(delegate, context).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
|
||||
// Only clean deleted records if success
|
||||
if (success) {
|
||||
new CleanThread(delegate, context).start();
|
||||
}
|
||||
}
|
||||
|
||||
class CleanThread extends Thread {
|
||||
private final RepositorySessionCleanDelegate delegate;
|
||||
private final Context context;
|
||||
|
||||
public CleanThread(RepositorySessionCleanDelegate delegate, Context context) {
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("context is null");
|
||||
}
|
||||
this.delegate = delegate;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
getDataAccessor(context).purgeDeleted();
|
||||
} catch (Exception e) {
|
||||
delegate.onCleanFailed(ThreadedRepository.this, e);
|
||||
return;
|
||||
}
|
||||
delegate.onCleaned(ThreadedRepository.this);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract DataAccessor getDataAccessor(Context context);
|
||||
protected abstract void sessionCreator(RepositorySessionCreationDelegate delegate, Context context);
|
||||
|
||||
class CreateSessionThread extends Thread {
|
||||
private final RepositorySessionCreationDelegate delegate;
|
||||
private final Context context;
|
||||
|
||||
public CreateSessionThread(RepositorySessionCreationDelegate delegate, Context context) {
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("context is null.");
|
||||
}
|
||||
this.delegate = delegate;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sessionCreator(delegate, context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/* 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.delegates;
|
||||
|
||||
import org.mozilla.gecko.sync.ThreadPool;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
|
||||
public abstract class DeferrableRepositorySessionCreationDelegate implements RepositorySessionCreationDelegate {
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
final RepositorySessionCreationDelegate self = this;
|
||||
return new RepositorySessionCreationDelegate() {
|
||||
|
||||
// TODO: rewrite to use ExecutorService.
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
ThreadPool.run(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
self.onSessionCreated(session);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(final Exception ex) {
|
||||
ThreadPool.run(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
self.onSessionCreateFailed(ex);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/* 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.delegates;
|
||||
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
|
||||
// Used to provide the sessionCallback and storeCallback
|
||||
// mechanism to repository instances.
|
||||
public interface RepositorySessionCreationDelegate {
|
||||
public void onSessionCreateFailed(Exception ex);
|
||||
public void onSessionCreated(RepositorySession session);
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate();
|
||||
}
|
|
@ -27,7 +27,6 @@ import org.mozilla.gecko.sync.net.SyncStorageRequest;
|
|||
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
|
||||
import org.mozilla.gecko.sync.net.SyncStorageResponse;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
|
||||
import org.mozilla.gecko.sync.repositories.NonPersistentRepositoryStateProvider;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFactory;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
|
@ -35,7 +34,6 @@ import org.mozilla.gecko.sync.repositories.RepositorySession;
|
|||
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
|
||||
import org.mozilla.gecko.sync.repositories.RepositoryStateProvider;
|
||||
import org.mozilla.gecko.sync.repositories.Server15Repository;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
import org.mozilla.gecko.sync.synchronizer.ServerLocalSynchronizer;
|
||||
|
@ -313,83 +311,76 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
|
|||
final Runnable doWipe = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
r.createSession(new RepositorySessionCreationDelegate() {
|
||||
final RepositorySession localSession;
|
||||
try {
|
||||
localSession = r.createSession(context);
|
||||
} catch (Exception e) {
|
||||
synchronized (monitor) {
|
||||
monitor.notify(e, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
localSession.begin();
|
||||
} catch (SyncException e) {
|
||||
Logger.error(LOG_TAG, "Couldn't begin session", e);
|
||||
localSession.abort();
|
||||
synchronized (monitor) {
|
||||
monitor.notify(e, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
localSession.wipe(new RepositorySessionWipeDelegate() {
|
||||
@Override
|
||||
public void onSessionCreated(final RepositorySession session) {
|
||||
public void onWipeSucceeded() {
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
Logger.error(LOG_TAG, "Couldn't begin session", e);
|
||||
session.abort();
|
||||
localSession.finish(new RepositorySessionFinishDelegate() {
|
||||
|
||||
@Override
|
||||
public void onFinishSucceeded(RepositorySession session,
|
||||
RepositorySessionBundle bundle) {
|
||||
// Hurrah.
|
||||
synchronized (monitor) {
|
||||
monitor.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishFailed(Exception ex) {
|
||||
// Assume that no finish => no wipe.
|
||||
synchronized (monitor) {
|
||||
monitor.notify(ex, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) {
|
||||
return this;
|
||||
}
|
||||
});
|
||||
} catch (InactiveSessionException e) {
|
||||
// Cannot happen. Call for safety.
|
||||
synchronized (monitor) {
|
||||
monitor.notify(e, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
session.wipe(new RepositorySessionWipeDelegate() {
|
||||
@Override
|
||||
public void onWipeSucceeded() {
|
||||
try {
|
||||
session.finish(new RepositorySessionFinishDelegate() {
|
||||
|
||||
@Override
|
||||
public void onFinishSucceeded(RepositorySession session,
|
||||
RepositorySessionBundle bundle) {
|
||||
// Hurrah.
|
||||
synchronized (monitor) {
|
||||
monitor.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishFailed(Exception ex) {
|
||||
// Assume that no finish => no wipe.
|
||||
synchronized (monitor) {
|
||||
monitor.notify(ex, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) {
|
||||
return this;
|
||||
}
|
||||
});
|
||||
} catch (InactiveSessionException e) {
|
||||
// Cannot happen. Call for safety.
|
||||
synchronized (monitor) {
|
||||
monitor.notify(e, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWipeFailed(Exception ex) {
|
||||
session.abort();
|
||||
synchronized (monitor) {
|
||||
monitor.notify(ex, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionWipeDelegate deferredWipeDelegate(ExecutorService executor) {
|
||||
return this;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
public void onWipeFailed(Exception ex) {
|
||||
localSession.abort();
|
||||
synchronized (monitor) {
|
||||
monitor.notify(ex, false);
|
||||
monitor.notify(ex, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
public RepositorySessionWipeDelegate deferredWipeDelegate(ExecutorService executor) {
|
||||
return this;
|
||||
}
|
||||
}, context);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,16 +8,10 @@ package org.mozilla.gecko.sync.stage;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.sync.MetaGlobalException;
|
||||
import org.mozilla.gecko.sync.NonObjectJSONException;
|
||||
import org.mozilla.gecko.sync.SynchronizerConfiguration;
|
||||
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
|
||||
import org.mozilla.gecko.sync.middleware.MiddlewareRepository;
|
||||
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
|
||||
import org.mozilla.gecko.sync.repositories.ConfigurableServer15Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFactory;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
|
@ -28,7 +22,6 @@ import org.mozilla.gecko.sync.repositories.domain.VersionConstants;
|
|||
import org.mozilla.gecko.sync.telemetry.TelemetryCollector;
|
||||
import org.mozilla.gecko.sync.telemetry.TelemetryStageCollector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
|
@ -40,11 +40,6 @@ public class Synchronizer implements SynchronizerSessionDelegate {
|
|||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialized(SynchronizerSession session) {
|
||||
session.synchronize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSynchronized(SynchronizerSession synchronizerSession) {
|
||||
Logger.debug(LOG_TAG, "Got onSynchronized.");
|
||||
|
@ -83,7 +78,7 @@ public class Synchronizer implements SynchronizerSessionDelegate {
|
|||
public void synchronize(Context context, SynchronizerDelegate delegate) {
|
||||
this.synchronizerDelegate = delegate;
|
||||
this.session = newSynchronizerSession();
|
||||
this.session.init(context, bundleA, bundleB);
|
||||
this.session.initAndSynchronize(context, bundleA, bundleB);
|
||||
}
|
||||
|
||||
public SynchronizerConfiguration save() {
|
||||
|
|
|
@ -9,11 +9,11 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.sync.SyncException;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.DeferrableRepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.DeferredRepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
|
||||
|
@ -46,10 +46,7 @@ import android.content.Context;
|
|||
* I always call exactly one of my delegate's `onSynchronized` or
|
||||
* `onSynchronizeFailed` callback methods if I have not seen an error.
|
||||
*/
|
||||
public class SynchronizerSession
|
||||
extends DeferrableRepositorySessionCreationDelegate
|
||||
implements RecordsChannelDelegate,
|
||||
RepositorySessionFinishDelegate {
|
||||
public class SynchronizerSession implements RecordsChannelDelegate, RepositorySessionFinishDelegate {
|
||||
|
||||
protected static final String LOG_TAG = "SynchronizerSession";
|
||||
protected Synchronizer synchronizer;
|
||||
|
@ -104,12 +101,63 @@ implements RecordsChannelDelegate,
|
|||
this.synchronizer = synchronizer;
|
||||
}
|
||||
|
||||
public void init(Context context, RepositorySessionBundle bundleA, RepositorySessionBundle bundleB) {
|
||||
public void initAndSynchronize(Context context, RepositorySessionBundle bundleA, RepositorySessionBundle bundleB) {
|
||||
this.context = context;
|
||||
this.bundleA = bundleA;
|
||||
this.bundleB = bundleB;
|
||||
// Begin sessionA and sessionB, call onInitialized in callbacks.
|
||||
this.getSynchronizer().repositoryA.createSession(this, context);
|
||||
|
||||
try {
|
||||
this.sessionA = this.getSynchronizer().repositoryA.createSession(context);
|
||||
} catch (SyncException e) {
|
||||
// We no longer need a reference to our context.
|
||||
this.context = null;
|
||||
this.delegate.onSynchronizeFailed(this, e, "Failed to create session");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.sessionA.unbundle(bundleA);
|
||||
} catch (Exception e) {
|
||||
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle first session.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.sessionB = this.getSynchronizer().repositoryB.createSession(context);
|
||||
} catch (final SyncException createException) {
|
||||
// We no longer need a reference to our context.
|
||||
this.context = null;
|
||||
// Finish already created sessionA.
|
||||
try {
|
||||
this.sessionA.finish(new RepositorySessionFinishDelegate() {
|
||||
@Override
|
||||
public void onFinishFailed(Exception ex) {
|
||||
SynchronizerSession.this.delegate.onSynchronizeFailed(SynchronizerSession.this, createException, "Failed to create second session.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) {
|
||||
SynchronizerSession.this.delegate.onSynchronizeFailed(SynchronizerSession.this, createException, "Failed to create second session.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) {
|
||||
return new DeferredRepositorySessionFinishDelegate(this, executor);
|
||||
}
|
||||
});
|
||||
} catch (InactiveSessionException finishException) {
|
||||
SynchronizerSession.this.delegate.onSynchronizeFailed(SynchronizerSession.this, createException, "Failed to create second session.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.sessionB.unbundle(bundleB);
|
||||
} catch (Exception e) {
|
||||
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle second session.");
|
||||
}
|
||||
|
||||
synchronize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,7 +220,7 @@ implements RecordsChannelDelegate,
|
|||
/**
|
||||
* Please don't call this until you've been notified with onInitialized.
|
||||
*/
|
||||
public synchronized void synchronize() {
|
||||
private synchronized void synchronize() {
|
||||
numInboundRecords.set(-1);
|
||||
numInboundRecordsStored.set(-1);
|
||||
numInboundRecordsFailed.set(-1);
|
||||
|
@ -304,82 +352,6 @@ implements RecordsChannelDelegate,
|
|||
Logger.warn(LOG_TAG, "Second RecordsChannel onFlowStoreFailed. Logging remote store error.", ex);
|
||||
}
|
||||
|
||||
/*
|
||||
* RepositorySessionCreationDelegate methods.
|
||||
*/
|
||||
|
||||
/**
|
||||
* I could be called twice: once for sessionA and once for sessionB.
|
||||
*
|
||||
* I try to clean up sessionA if it is not null, since the creation of
|
||||
* sessionB must have failed.
|
||||
*/
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
// Attempt to finish the first session, if the second is the one that failed.
|
||||
if (this.sessionA != null) {
|
||||
try {
|
||||
// We no longer need a reference to our context.
|
||||
this.context = null;
|
||||
this.sessionA.finish(this);
|
||||
} catch (Exception e) {
|
||||
// Never mind; best-effort finish.
|
||||
}
|
||||
}
|
||||
// We no longer need a reference to our context.
|
||||
this.context = null;
|
||||
this.delegate.onSynchronizeFailed(this, ex, "Failed to create session");
|
||||
}
|
||||
|
||||
/**
|
||||
* I should be called twice: first for sessionA and second for sessionB.
|
||||
*
|
||||
* If I am called for sessionB, I call my delegate's `onInitialized` callback
|
||||
* method because my repository sessions are correctly initialized.
|
||||
*/
|
||||
// TODO: some of this "finish and clean up" code can be refactored out.
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
if (session == null ||
|
||||
this.sessionA == session) {
|
||||
// TODO: clean up sessionA.
|
||||
this.delegate.onSynchronizeFailed(this, new UnexpectedSessionException(session), "Failed to create session.");
|
||||
return;
|
||||
}
|
||||
if (this.sessionA == null) {
|
||||
this.sessionA = session;
|
||||
|
||||
// Unbundle.
|
||||
try {
|
||||
this.sessionA.unbundle(this.bundleA);
|
||||
} catch (Exception e) {
|
||||
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle first session.");
|
||||
// TODO: abort
|
||||
return;
|
||||
}
|
||||
this.getSynchronizer().repositoryB.createSession(this, this.context);
|
||||
return;
|
||||
}
|
||||
if (this.sessionB == null) {
|
||||
this.sessionB = session;
|
||||
// We no longer need a reference to our context.
|
||||
this.context = null;
|
||||
|
||||
// Unbundle. We unbundled sessionA when that session was created.
|
||||
try {
|
||||
this.sessionB.unbundle(this.bundleB);
|
||||
} catch (Exception e) {
|
||||
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle second session.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.delegate.onInitialized(this);
|
||||
return;
|
||||
}
|
||||
// TODO: need a way to make sure we don't call any more delegate methods.
|
||||
this.delegate.onSynchronizeFailed(this, new UnexpectedSessionException(session), "Failed to create session.");
|
||||
}
|
||||
|
||||
/*
|
||||
* RepositorySessionFinishDelegate methods.
|
||||
*/
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
package org.mozilla.gecko.sync.synchronizer;
|
||||
|
||||
public interface SynchronizerSessionDelegate {
|
||||
public void onInitialized(SynchronizerSession session);
|
||||
|
||||
public void onSynchronized(SynchronizerSession session);
|
||||
public void onSynchronizeFailed(SynchronizerSession session, Exception lastException, String reason);
|
||||
public void onSynchronizeSkipped(SynchronizerSession synchronizerSession);
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.mozilla.gecko.sync.SyncException;
|
|||
import org.mozilla.gecko.sync.repositories.FetchFailedException;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.StoreFailedException;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
|
@ -57,9 +57,8 @@ public class SynchronizerHelpers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this) {
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new WBORepositorySession(this) {
|
||||
@Override
|
||||
public void fetchModified(final RepositorySessionFetchRecordsDelegate delegate) {
|
||||
super.fetchModified(new RepositorySessionFetchRecordsDelegate() {
|
||||
|
@ -93,7 +92,7 @@ public class SynchronizerHelpers {
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,9 +107,8 @@ public class SynchronizerHelpers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this) {
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new WBORepositorySession(this) {
|
||||
@Override
|
||||
public void store(final Record record) throws NoStoreDelegateException {
|
||||
if (storeDelegate == null) {
|
||||
|
@ -127,7 +125,7 @@ public class SynchronizerHelpers {
|
|||
super.store(record);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,9 +214,8 @@ public class SynchronizerHelpers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new BatchFailStoreWBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new BatchFailStoreWBORepositorySession(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,9 +236,8 @@ public class SynchronizerHelpers {
|
|||
|
||||
public static class BeginErrorWBORepository extends TrackingWBORepository {
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new BeginErrorWBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new BeginErrorWBORepositorySession(this);
|
||||
}
|
||||
|
||||
public class BeginErrorWBORepositorySession extends WBORepositorySession {
|
||||
|
@ -258,9 +254,8 @@ public class SynchronizerHelpers {
|
|||
|
||||
public static class FinishErrorWBORepository extends TrackingWBORepository {
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new FinishErrorWBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new FinishErrorWBORepositorySession(this);
|
||||
}
|
||||
|
||||
public class FinishErrorWBORepositorySession extends WBORepositorySession {
|
||||
|
@ -283,9 +278,8 @@ public class SynchronizerHelpers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new DataAvailableWBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new DataAvailableWBORepositorySession(this);
|
||||
}
|
||||
|
||||
public class DataAvailableWBORepositorySession extends WBORepositorySession {
|
||||
|
@ -308,9 +302,8 @@ public class SynchronizerHelpers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new ShouldSkipWBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new ShouldSkipWBORepositorySession(this);
|
||||
}
|
||||
|
||||
public class ShouldSkipWBORepositorySession extends WBORepositorySession {
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mozilla.android.sync.test.SynchronizerHelpers.FailFetchWBORepository;
|
||||
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionCreationDelegate;
|
||||
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.background.testhelpers.TestRunner;
|
||||
import org.mozilla.gecko.background.testhelpers.WBORepository;
|
||||
|
@ -109,24 +108,8 @@ public class TestRecordsChannel {
|
|||
}
|
||||
|
||||
private void createSessions() {
|
||||
WaitHelper.getTestWaiter().performWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sourceRepository.createSession(new ExpectSuccessRepositorySessionCreationDelegate(WaitHelper.getTestWaiter()) {
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
sourceSession = session;
|
||||
sinkRepository.createSession(new ExpectSuccessRepositorySessionCreationDelegate(WaitHelper.getTestWaiter()) {
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
sinkSession = session;
|
||||
WaitHelper.getTestWaiter().performNotify();
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
});
|
||||
sourceSession = sourceRepository.createSession(null);
|
||||
sinkSession = sinkRepository.createSession(null);
|
||||
}
|
||||
|
||||
public void doFlow() throws Exception {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package org.mozilla.android.sync.test;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -87,18 +88,6 @@ public class TestSynchronizer {
|
|||
synchronizer.repositoryA = repoA;
|
||||
synchronizer.repositoryB = repoB;
|
||||
final SynchronizerSession syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() {
|
||||
|
||||
@Override
|
||||
public void onInitialized(SynchronizerSession session) {
|
||||
assertFalse(repoA.wbos.containsKey(guidB));
|
||||
assertFalse(repoA.wbos.containsKey(guidC));
|
||||
assertFalse(repoB.wbos.containsKey(guidA));
|
||||
assertTrue(repoA.wbos.containsKey(guidA));
|
||||
assertTrue(repoB.wbos.containsKey(guidB));
|
||||
assertTrue(repoB.wbos.containsKey(guidC));
|
||||
session.synchronize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSynchronized(SynchronizerSession session) {
|
||||
try {
|
||||
|
@ -125,7 +114,13 @@ public class TestSynchronizer {
|
|||
WaitHelper.getTestWaiter().performWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
syncSession.init(context, new RepositorySessionBundle(0), new RepositorySessionBundle(0));
|
||||
assertFalse(repoA.wbos.containsKey(guidB));
|
||||
assertFalse(repoA.wbos.containsKey(guidC));
|
||||
assertFalse(repoB.wbos.containsKey(guidA));
|
||||
assertTrue(repoA.wbos.containsKey(guidA));
|
||||
assertTrue(repoB.wbos.containsKey(guidB));
|
||||
assertTrue(repoB.wbos.containsKey(guidC));
|
||||
syncSession.initAndSynchronize(context, new RepositorySessionBundle(0), new RepositorySessionBundle(0));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -84,11 +84,6 @@ public class TestSynchronizerSession {
|
|||
synchronizer.repositoryA = repoA;
|
||||
synchronizer.repositoryB = repoB;
|
||||
syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() {
|
||||
@Override
|
||||
public void onInitialized(SynchronizerSession session) {
|
||||
session.synchronize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSynchronized(SynchronizerSession session) {
|
||||
WaitHelper.getTestWaiter().performNotify();
|
||||
|
@ -128,7 +123,7 @@ public class TestSynchronizerSession {
|
|||
@Override
|
||||
public void run() {
|
||||
final Context context = null;
|
||||
syncSession.init(context,
|
||||
syncSession.initAndSynchronize(context,
|
||||
new RepositorySessionBundle(0),
|
||||
new RepositorySessionBundle(0));
|
||||
}
|
||||
|
@ -247,11 +242,6 @@ public class TestSynchronizerSession {
|
|||
synchronizer.repositoryB = repoB;
|
||||
|
||||
syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() {
|
||||
@Override
|
||||
public void onInitialized(SynchronizerSession session) {
|
||||
session.synchronize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSynchronized(SynchronizerSession session) {
|
||||
WaitHelper.getTestWaiter().performNotify(new RuntimeException("Not expecting onSynchronized"));
|
||||
|
@ -272,7 +262,7 @@ public class TestSynchronizerSession {
|
|||
@Override
|
||||
public void run() {
|
||||
final Context context = null;
|
||||
syncSession.init(context,
|
||||
syncSession.initAndSynchronize(context,
|
||||
new RepositorySessionBundle(100),
|
||||
new RepositorySessionBundle(200));
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
package org.mozilla.android.sync.test.helpers;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import org.mozilla.gecko.background.testhelpers.WaitHelper;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
|
||||
public class ExpectSuccessRepositorySessionCreationDelegate extends
|
||||
ExpectSuccessDelegate implements RepositorySessionCreationDelegate {
|
||||
|
||||
public ExpectSuccessRepositorySessionCreationDelegate(WaitHelper waitHelper) {
|
||||
super(waitHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreateFailed(Exception ex) {
|
||||
log("Session creation failed.", ex);
|
||||
performNotify(new AssertionFailedError("onSessionCreateFailed: session creation should not have failed."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
log("Session creation succeeded.");
|
||||
performNotify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionCreationDelegate deferredCreationDelegate() {
|
||||
log("Session creation deferred.");
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,8 +10,8 @@ import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
|||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.RecordFilter;
|
||||
import org.mozilla.gecko.sync.repositories.Repository;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
|
||||
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
|
||||
|
@ -211,9 +211,8 @@ public class WBORepository extends Repository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createSession(RepositorySessionCreationDelegate delegate,
|
||||
Context context) {
|
||||
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this));
|
||||
public RepositorySession createSession(Context context) {
|
||||
return new WBORepositorySession(this);
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, Record> cloneWBOs() {
|
||||
|
|
|
@ -7,7 +7,6 @@ import junit.framework.AssertionFailedError;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionCreationDelegate;
|
||||
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFetchRecordsDelegate;
|
||||
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate;
|
||||
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionStoreDelegate;
|
||||
|
@ -17,22 +16,17 @@ import org.mozilla.gecko.background.testhelpers.TestRunner;
|
|||
import org.mozilla.gecko.background.testhelpers.WBORepository;
|
||||
import org.mozilla.gecko.background.testhelpers.WaitHelper;
|
||||
import org.mozilla.gecko.sync.CryptoRecord;
|
||||
import org.mozilla.gecko.sync.NonObjectJSONException;
|
||||
import org.mozilla.gecko.sync.SyncException;
|
||||
import org.mozilla.gecko.sync.crypto.CryptoException;
|
||||
import org.mozilla.gecko.sync.crypto.KeyBundle;
|
||||
import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository;
|
||||
import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
|
||||
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
|
||||
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
|
||||
import org.mozilla.gecko.sync.repositories.RepositorySession;
|
||||
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
|
||||
import org.mozilla.gecko.sync.repositories.domain.Record;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
@ -77,68 +71,50 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
cmwSession = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run `runnable` in performWait(... onBeginSucceeded { } ).
|
||||
*
|
||||
* The Crypto5MiddlewareRepositorySession is available in self.cmwSession.
|
||||
*
|
||||
* @param runnable
|
||||
*/
|
||||
public void runInOnBeginSucceeded(final Runnable runnable) {
|
||||
final TestCrypto5MiddlewareRepositorySession self = this;
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmwRepo.createSession(new ExpectSuccessRepositorySessionCreationDelegate(getTestWaiter()) {
|
||||
@Override
|
||||
public void onSessionCreated(RepositorySession session) {
|
||||
self.cmwSession = (Crypto5MiddlewareRepositorySession)session;
|
||||
assertSame(RepositorySession.SessionStatus.UNSTARTED, cmwSession.getStatus());
|
||||
|
||||
try {
|
||||
session.begin();
|
||||
} catch (SyncException e) {
|
||||
TestCrypto5MiddlewareRepositorySession.performNotify(e);
|
||||
}
|
||||
runnable.run();
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}));
|
||||
public void beginSessionAndAssertSuccess() throws Exception{
|
||||
cmwSession = (Crypto5MiddlewareRepositorySession) cmwRepo.createSession(null);
|
||||
assertSame(RepositorySession.SessionStatus.UNSTARTED, cmwSession.getStatus());
|
||||
cmwSession.begin();
|
||||
assertSame(RepositorySession.SessionStatus.ACTIVE, cmwSession.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Verify that the status is actually being advanced.
|
||||
*/
|
||||
public void testStatus() {
|
||||
runInOnBeginSucceeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
assertSame(RepositorySession.SessionStatus.ACTIVE, cmwSession.getStatus());
|
||||
public void testStatus() throws Exception {
|
||||
beginSessionAndAssertSuccess();
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter()));
|
||||
} catch (InactiveSessionException e) {
|
||||
performNotify(e);
|
||||
}
|
||||
assertSame(RepositorySession.SessionStatus.DONE, cmwSession.getStatus());
|
||||
}
|
||||
});
|
||||
}));
|
||||
assertSame(RepositorySession.SessionStatus.DONE, cmwSession.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Verify that wipe is actually wiping the underlying repository.
|
||||
*/
|
||||
public void testWipe() {
|
||||
public void testWipe() throws Exception {
|
||||
Record record = new MockRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
|
||||
wboRepo.wbos.put(record.guid, record);
|
||||
assertEquals(1, wboRepo.wbos.size());
|
||||
|
||||
runInOnBeginSucceeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
beginSessionAndAssertSuccess();
|
||||
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmwSession.wipe(new ExpectSuccessRepositoryWipeDelegate(getTestWaiter()));
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
|
@ -155,12 +131,15 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
/**
|
||||
* Verify that store is actually writing encrypted data to the underlying repository.
|
||||
*/
|
||||
public void testStoreEncrypts() throws NonObjectJSONException, CryptoException, IOException {
|
||||
public void testStoreEncrypts() throws Exception {
|
||||
final BookmarkRecord record = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
|
||||
record.title = "unencrypted title";
|
||||
|
||||
runInOnBeginSucceeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
beginSessionAndAssertSuccess();
|
||||
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try {
|
||||
cmwSession.setStoreDelegate(new ExpectSuccessRepositorySessionStoreDelegate(getTestWaiter()));
|
||||
|
@ -174,7 +153,8 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
performNotify(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
assertEquals(1, wboRepo.wbos.size());
|
||||
assertTrue(wboRepo.wbos.containsKey(record.guid));
|
||||
|
||||
|
@ -192,7 +172,7 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
/**
|
||||
* Verify that fetch is actually retrieving encrypted data from the underlying repository and is correctly decrypting it.
|
||||
*/
|
||||
public void testFetchDecrypts() throws UnsupportedEncodingException, CryptoException {
|
||||
public void testFetchDecrypts() throws Exception {
|
||||
final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
|
||||
record1.title = "unencrypted title";
|
||||
final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false);
|
||||
|
@ -209,7 +189,8 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
wboRepo.wbos.put(record2.guid, encryptedRecord2);
|
||||
|
||||
final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter());
|
||||
runInOnBeginSucceeded(new Runnable() {
|
||||
beginSessionAndAssertSuccess();
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
cmwSession.fetch(new String[] { record1.guid }, fetchRecordsDelegate);
|
||||
|
@ -217,7 +198,7 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
performNotify(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
|
@ -238,7 +219,7 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
/**
|
||||
* Verify that fetchAll is actually retrieving encrypted data from the underlying repository and is correctly decrypting it.
|
||||
*/
|
||||
public void testFetchAllDecrypts() throws UnsupportedEncodingException, CryptoException {
|
||||
public void testFetchAllDecrypts() throws Exception {
|
||||
final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
|
||||
record1.title = "unencrypted title";
|
||||
final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false);
|
||||
|
@ -255,11 +236,12 @@ public class TestCrypto5MiddlewareRepositorySession {
|
|||
wboRepo.wbos.put(record2.guid, encryptedRecord2);
|
||||
|
||||
final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchAllRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter());
|
||||
runInOnBeginSucceeded(new Runnable() {
|
||||
beginSessionAndAssertSuccess();
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override public void run() {
|
||||
cmwSession.fetchAll(fetchAllRecordsDelegate);
|
||||
}
|
||||
});
|
||||
}));
|
||||
performWait(onThreadRunnable(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
|
|
Загрузка…
Ссылка в новой задаче