mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
584e717110
--HG-- rename : mobile/android/base/sync/GlobalConstants.java.in => mobile/android/base/background/common/GlobalConstants.java.in rename : mobile/android/base/sync/Logger.java => mobile/android/base/background/common/log/Logger.java rename : mobile/android/base/sync/log/writers/AndroidLevelCachingLogWriter.java => mobile/android/base/background/common/log/writers/AndroidLevelCachingLogWriter.java rename : mobile/android/base/sync/log/writers/AndroidLogWriter.java => mobile/android/base/background/common/log/writers/AndroidLogWriter.java rename : mobile/android/base/sync/log/writers/LevelFilteringLogWriter.java => mobile/android/base/background/common/log/writers/LevelFilteringLogWriter.java rename : mobile/android/base/sync/log/writers/LogWriter.java => mobile/android/base/background/common/log/writers/LogWriter.java rename : mobile/android/base/sync/log/writers/PrintLogWriter.java => mobile/android/base/background/common/log/writers/PrintLogWriter.java rename : mobile/android/base/sync/log/writers/SimpleTagLogWriter.java => mobile/android/base/background/common/log/writers/SimpleTagLogWriter.java rename : mobile/android/base/sync/log/writers/StringLogWriter.java => mobile/android/base/background/common/log/writers/StringLogWriter.java rename : mobile/android/base/sync/log/writers/TagLogWriter.java => mobile/android/base/background/common/log/writers/TagLogWriter.java rename : mobile/android/base/sync/log/writers/ThreadLocalTagLogWriter.java => mobile/android/base/background/common/log/writers/ThreadLocalTagLogWriter.java
70 lines
2.6 KiB
Java
70 lines
2.6 KiB
Java
/* 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;
|
|
|
|
import java.io.IOException;
|
|
|
|
import org.json.simple.parser.ParseException;
|
|
import org.mozilla.gecko.background.common.log.Logger;
|
|
import org.mozilla.gecko.sync.SyncConfiguration.ConfigurationBranch;
|
|
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
|
|
|
|
import android.content.SharedPreferences.Editor;
|
|
|
|
public class SynchronizerConfiguration {
|
|
private static final String LOG_TAG = "SynczrConfiguration";
|
|
|
|
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;
|
|
this.localBundle = localBundle;
|
|
}
|
|
|
|
// 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;
|
|
Logger.debug(LOG_TAG, "Loaded 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();
|
|
Logger.debug(LOG_TAG, "Persisted SynchronizerConfiguration. syncID: " + syncID + ", remoteBundle: " + remoteBundle + ", localBundle: " + localBundle);
|
|
}
|
|
}
|