Bug 709339 - First mostly functional drop of native Sync. a=mobile
This commit is contained in:
@@ -38,10 +38,12 @@
|
||||
package org.mozilla.gecko.sync.synchronizer;
|
||||
|
||||
|
||||
import org.mozilla.gecko.sync.ThreadPool;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
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;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -116,14 +118,23 @@ implements RecordsChannelDelegate,
|
||||
* Please don't call this until you've been notified with onInitialized.
|
||||
*/
|
||||
public void synchronize() {
|
||||
// TODO: pull timestamps from somewhere...
|
||||
// First thing: decide whether we should.
|
||||
if (!sessionA.dataAvailable() &&
|
||||
!sessionB.dataAvailable()) {
|
||||
info("Neither session reports data available. Short-circuiting sync.");
|
||||
sessionA.abort();
|
||||
sessionB.abort();
|
||||
this.delegate.onSynchronizeSkipped(this);
|
||||
return;
|
||||
}
|
||||
|
||||
final SynchronizerSession session = this;
|
||||
|
||||
// TODO: failed record handling.
|
||||
final RecordsChannel channelBToA = new RecordsChannel(this.sessionB, this.sessionA, this);
|
||||
RecordsChannelDelegate channelDelegate = new RecordsChannelDelegate() {
|
||||
public void onFlowCompleted(RecordsChannel recordsChannel, long end) {
|
||||
info("First RecordsChannel flow completed. Starting next.");
|
||||
info("First RecordsChannel flow completed. End is " + end + ". Starting next.");
|
||||
pendingATimestamp = end;
|
||||
flowAToBCompleted = true;
|
||||
channelBToA.flow();
|
||||
@@ -155,7 +166,7 @@ implements RecordsChannelDelegate,
|
||||
|
||||
@Override
|
||||
public void onFlowCompleted(RecordsChannel channel, long end) {
|
||||
info("Second RecordsChannel (" + channel + ") flow completed. Notifying onSynchronized.");
|
||||
info("Second RecordsChannel flow completed. End is " + end + ". Finishing.");
|
||||
pendingBTimestamp = end;
|
||||
flowBToACompleted = true;
|
||||
|
||||
@@ -171,7 +182,6 @@ implements RecordsChannelDelegate,
|
||||
@Override
|
||||
public void onFlowStoreFailed(RecordsChannel recordsChannel, Exception ex) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
warn("Second RecordsChannel flow failed.");
|
||||
}
|
||||
|
||||
@@ -256,7 +266,8 @@ implements RecordsChannelDelegate,
|
||||
warn("Got exception cleaning up first after second session creation failed.", ex);
|
||||
return;
|
||||
}
|
||||
// TODO
|
||||
String session = (this.sessionA == null) ? "B" : "A";
|
||||
this.delegate.onSynchronizeFailed(this, ex, "Finish of session " + session + " failed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,6 +283,7 @@ implements RecordsChannelDelegate,
|
||||
this.synchronizer.bundleA = bundle;
|
||||
}
|
||||
if (this.sessionB != null) {
|
||||
info("Finishing session B.");
|
||||
// On to the next.
|
||||
this.sessionB.finish(this);
|
||||
}
|
||||
@@ -280,6 +292,7 @@ implements RecordsChannelDelegate,
|
||||
info("onFinishSucceeded: bumping session B's timestamp to " + pendingBTimestamp);
|
||||
bundle.bumpTimestamp(pendingBTimestamp);
|
||||
this.synchronizer.bundleB = bundle;
|
||||
info("Notifying delegate.onSynchronized.");
|
||||
this.delegate.onSynchronized(this);
|
||||
}
|
||||
} else {
|
||||
@@ -292,34 +305,7 @@ implements RecordsChannelDelegate,
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionFinishDelegate deferredFinishDelegate() {
|
||||
final SynchronizerSession self = this;
|
||||
return new RepositorySessionFinishDelegate() {
|
||||
@Override
|
||||
public void onFinishSucceeded(final RepositorySession session,
|
||||
final RepositorySessionBundle bundle) {
|
||||
ThreadPool.run(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
self.onFinishSucceeded(session, bundle);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishFailed(final Exception ex) {
|
||||
ThreadPool.run(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
self.onFinishFailed(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositorySessionFinishDelegate deferredFinishDelegate() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
public RepositorySessionFinishDelegate deferredFinishDelegate(final ExecutorService executor) {
|
||||
return new DeferredRepositorySessionFinishDelegate(this, executor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user