Bug 709339 - First mostly functional drop of native Sync. a=mobile

This commit is contained in:
Richard Newman
2012-01-14 09:20:31 -08:00
parent 83e8e5d5ed
commit 5fe8ffe843
89 changed files with 5497 additions and 2295 deletions

View File

@@ -37,14 +37,26 @@
package org.mozilla.gecko.sync;
import java.io.IOException;
import org.json.simple.parser.ParseException;
import org.mozilla.gecko.sync.SyncConfiguration.ConfigurationBranch;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import android.content.SharedPreferences.Editor;
import android.util.Log;
public class SynchronizerConfiguration {
private static final String LOG_TAG = "SynchronizerConfiguration";
public String syncID;
public RepositorySessionBundle remoteBundle;
public RepositorySessionBundle localBundle;
public SynchronizerConfiguration(ConfigurationBranch config) throws NonObjectJSONException, IOException, ParseException {
this.load(config);
}
public SynchronizerConfiguration(String syncID, RepositorySessionBundle remoteBundle, RepositorySessionBundle localBundle) {
this.syncID = syncID;
this.remoteBundle = remoteBundle;
@@ -58,4 +70,40 @@ public class SynchronizerConfiguration {
out[2] = localBundle.toJSONString();
return out;
}
// This should get partly shuffled back into SyncConfiguration, I think.
public void load(ConfigurationBranch config) throws NonObjectJSONException, IOException, ParseException {
if (config == null) {
throw new IllegalArgumentException("config cannot be null.");
}
String remoteJSON = config.getString("remote", null);
String localJSON = config.getString("local", null);
RepositorySessionBundle rB = new RepositorySessionBundle(remoteJSON);
RepositorySessionBundle lB = new RepositorySessionBundle(localJSON);
if (remoteJSON == null) {
rB.setTimestamp(0);
}
if (localJSON == null) {
lB.setTimestamp(0);
}
syncID = config.getString("syncID", null);
remoteBundle = rB;
localBundle = lB;
Log.i(LOG_TAG, "Initialized SynchronizerConfiguration. syncID: " + syncID + ", remoteBundle: " + remoteBundle + ", localBundle: " + localBundle);
}
public void persist(ConfigurationBranch config) {
if (config == null) {
throw new IllegalArgumentException("config cannot be null.");
}
String jsonRemote = remoteBundle.toJSONString();
String jsonLocal = localBundle.toJSONString();
Editor editor = config.edit();
editor.putString("remote", jsonRemote);
editor.putString("local", jsonLocal);
editor.putString("syncID", syncID);
// Synchronous.
editor.commit();
}
}