summaryrefslogtreecommitdiffstats
path: root/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/AbstractSessionManagingSyncStage.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/AbstractSessionManagingSyncStage.java')
-rw-r--r--mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/AbstractSessionManagingSyncStage.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/AbstractSessionManagingSyncStage.java b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/AbstractSessionManagingSyncStage.java
new file mode 100644
index 000000000..6592c3baa
--- /dev/null
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/AbstractSessionManagingSyncStage.java
@@ -0,0 +1,43 @@
+/* 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.stage;
+
+import org.mozilla.gecko.sync.GlobalSession;
+
+/**
+ * A global sync stage that manages a <code>GlobalSession</code> instance. This
+ * class is intended to be temporary: it should disappear as work to make
+ * data-driven syncs progresses.
+ * <p>
+ * This class is inherently <b>thread-unsafe</b>: if <code>session</code> is
+ * mutated after being set, all sorts of bad things could occur. At the time of
+ * writing, every <code>GlobalSyncStage</code> created is executed (wiped,
+ * reset) with the same <code>GlobalSession</code> argument.
+ */
+public abstract class AbstractSessionManagingSyncStage implements GlobalSyncStage {
+ protected GlobalSession session;
+
+ protected abstract void execute() throws NoSuchStageException;
+ protected abstract void resetLocal();
+ protected abstract void wipeLocal() throws Exception;
+
+ @Override
+ public void resetLocal(GlobalSession session) {
+ this.session = session;
+ resetLocal();
+ }
+
+ @Override
+ public void wipeLocal(GlobalSession session) throws Exception {
+ this.session = session;
+ wipeLocal();
+ }
+
+ @Override
+ public void execute(GlobalSession session) throws NoSuchStageException {
+ this.session = session;
+ execute();
+ }
+}