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.

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

mercurial