summaryrefslogtreecommitdiffstats
path: root/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/GlobalSyncStage.java
blob: 6dee71f90b3943ec2ec0a5ec68c4ecc4e648d687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* 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 java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import org.mozilla.gecko.sync.GlobalSession;


public interface GlobalSyncStage {
  public static enum Stage {
    idle,                       // Start state.
    checkPreconditions,         // Preparation of the basics. TODO: clear status
    fetchInfoCollections,       // Take a look at timestamps.
    fetchInfoConfiguration,     // Fetch server upload limits
    fetchMetaGlobal,
    ensureKeysStage,
    /*
    ensureSpecialRecords,
    updateEngineTimestamps,
    */
    syncClientsEngine(SyncClientsEngineStage.STAGE_NAME),
    /*
    processFirstSyncPref,
    processClientCommands,
    updateEnabledEngines,
    */
    syncTabs("tabs"),
    syncPasswords("passwords"),
    syncBookmarks("bookmarks"),
    syncHistory("history"),
    syncFormHistory("forms"),

    uploadMetaGlobal,
    completed;

    // Maintain a mapping from names ("bookmarks") to Stage enumerations (syncBookmarks).
    private static final Map<String, Stage> named = new HashMap<String, Stage>();
    static {
      for (Stage s : EnumSet.allOf(Stage.class)) {
        if (s.getRepositoryName() != null) {
          named.put(s.getRepositoryName(), s);
        }
      }
    }

    public static Stage byName(final String name) {
      if (name == null) {
        return null;
      }
      return named.get(name);
    }

    /**
     * @return an immutable collection of Stages.
     */
    public static Collection<Stage> getNamedStages() {
      return Collections.unmodifiableCollection(named.values());
    }

    // Each Stage tracks its repositoryName.
    private final String repositoryName;
    public String getRepositoryName() {
      return repositoryName;
    }

    private Stage() {
      this.repositoryName = null;
    }

    private Stage(final String name) {
      this.repositoryName = name;
    }
  }

  public void execute(GlobalSession session) throws NoSuchStageException;
  public void resetLocal(GlobalSession session);
  public void wipeLocal(GlobalSession session) throws Exception;

  /**
   * What storage version number this engine supports.
   * <p>
   * Used to generate a fresh meta/global record for upload.
   * @return a version number or <code>null</code> to never include this engine in a fresh meta/global record.
   */
  public Integer getStorageVersion();
}