mobile/android/base/sync/SynchronizerConfiguration.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.sync;
michael@0 6
michael@0 7 import java.io.IOException;
michael@0 8
michael@0 9 import org.json.simple.parser.ParseException;
michael@0 10 import org.mozilla.gecko.background.common.log.Logger;
michael@0 11 import org.mozilla.gecko.sync.SyncConfiguration.ConfigurationBranch;
michael@0 12 import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
michael@0 13
michael@0 14 import android.content.SharedPreferences.Editor;
michael@0 15
michael@0 16 public class SynchronizerConfiguration {
michael@0 17 private static final String LOG_TAG = "SynczrConfiguration";
michael@0 18
michael@0 19 public String syncID;
michael@0 20 public RepositorySessionBundle remoteBundle;
michael@0 21 public RepositorySessionBundle localBundle;
michael@0 22
michael@0 23 public SynchronizerConfiguration(ConfigurationBranch config) throws NonObjectJSONException, IOException, ParseException {
michael@0 24 this.load(config);
michael@0 25 }
michael@0 26
michael@0 27 public SynchronizerConfiguration(String syncID, RepositorySessionBundle remoteBundle, RepositorySessionBundle localBundle) {
michael@0 28 this.syncID = syncID;
michael@0 29 this.remoteBundle = remoteBundle;
michael@0 30 this.localBundle = localBundle;
michael@0 31 }
michael@0 32
michael@0 33 // This should get partly shuffled back into SyncConfiguration, I think.
michael@0 34 public void load(ConfigurationBranch config) throws NonObjectJSONException, IOException, ParseException {
michael@0 35 if (config == null) {
michael@0 36 throw new IllegalArgumentException("config cannot be null.");
michael@0 37 }
michael@0 38 String remoteJSON = config.getString("remote", null);
michael@0 39 String localJSON = config.getString("local", null);
michael@0 40 RepositorySessionBundle rB = new RepositorySessionBundle(remoteJSON);
michael@0 41 RepositorySessionBundle lB = new RepositorySessionBundle(localJSON);
michael@0 42 if (remoteJSON == null) {
michael@0 43 rB.setTimestamp(0);
michael@0 44 }
michael@0 45 if (localJSON == null) {
michael@0 46 lB.setTimestamp(0);
michael@0 47 }
michael@0 48 syncID = config.getString("syncID", null);
michael@0 49 remoteBundle = rB;
michael@0 50 localBundle = lB;
michael@0 51 Logger.debug(LOG_TAG, "Loaded SynchronizerConfiguration. syncID: " + syncID + ", remoteBundle: " + remoteBundle + ", localBundle: " + localBundle);
michael@0 52 }
michael@0 53
michael@0 54 public void persist(ConfigurationBranch config) {
michael@0 55 if (config == null) {
michael@0 56 throw new IllegalArgumentException("config cannot be null.");
michael@0 57 }
michael@0 58 String jsonRemote = remoteBundle.toJSONString();
michael@0 59 String jsonLocal = localBundle.toJSONString();
michael@0 60 Editor editor = config.edit();
michael@0 61 editor.putString("remote", jsonRemote);
michael@0 62 editor.putString("local", jsonLocal);
michael@0 63 editor.putString("syncID", syncID);
michael@0 64
michael@0 65 // Synchronous.
michael@0 66 editor.commit();
michael@0 67 Logger.debug(LOG_TAG, "Persisted SynchronizerConfiguration. syncID: " + syncID + ", remoteBundle: " + remoteBundle + ", localBundle: " + localBundle);
michael@0 68 }
michael@0 69 }

mercurial