Bug 1291821 - Split history stage into recent and full history stages r=rnewman

Recent history stage will only run if full history stage did not complete yet.
Bug 1316110 tracks follow up work to make this more efficient.

MozReview-Commit-ID: 7dtbfEFUMGB

--HG--
extra : rebase_source : 94a3e652d9dcf7996e14b96aee28810baee078ea
This commit is contained in:
Grisha Kruglov 2016-11-16 14:53:07 -08:00
Родитель 5632261a6b
Коммит 1020737f7f
7 изменённых файлов: 104 добавлений и 6 удалений

Просмотреть файл

@ -1041,6 +1041,7 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
'sync/stage/AbstractSessionManagingSyncStage.java',
'sync/stage/AndroidBrowserBookmarksServerSyncStage.java',
'sync/stage/AndroidBrowserHistoryServerSyncStage.java',
'sync/stage/AndroidBrowserRecentHistoryServerSyncStage.java',
'sync/stage/CheckPreconditionsStage.java',
'sync/stage/CompletedStage.java',
'sync/stage/EnsureCrypto5KeysStage.java',

Просмотреть файл

@ -27,6 +27,7 @@ import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse;
import org.mozilla.gecko.sync.stage.AndroidBrowserBookmarksServerSyncStage;
import org.mozilla.gecko.sync.stage.AndroidBrowserHistoryServerSyncStage;
import org.mozilla.gecko.sync.stage.AndroidBrowserRecentHistoryServerSyncStage;
import org.mozilla.gecko.sync.stage.CheckPreconditionsStage;
import org.mozilla.gecko.sync.stage.CompletedStage;
import org.mozilla.gecko.sync.stage.EnsureCrypto5KeysStage;
@ -188,9 +189,14 @@ public class GlobalSession implements HttpResponseObserver {
stages.put(Stage.syncTabs, new FennecTabsServerSyncStage());
stages.put(Stage.syncPasswords, new PasswordsServerSyncStage());
// Will only run if syncFullHistory stage never completed.
// Bug 1316110 tracks follow up work to improve efficiency of this stage.
stages.put(Stage.syncRecentHistory, new AndroidBrowserRecentHistoryServerSyncStage());
stages.put(Stage.syncBookmarks, new AndroidBrowserBookmarksServerSyncStage());
stages.put(Stage.syncHistory, new AndroidBrowserHistoryServerSyncStage());
stages.put(Stage.syncFormHistory, new FormHistoryServerSyncStage());
stages.put(Stage.syncFullHistory, new AndroidBrowserHistoryServerSyncStage());
stages.put(Stage.uploadMetaGlobal, new UploadMetaGlobalStage());
stages.put(Stage.completed, new CompletedStage());

Просмотреть файл

@ -0,0 +1,88 @@
/* 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.MetaGlobalException;
import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SynchronizerConfiguration;
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryRepository;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* History sync stage which is limited to just recent history, and will only run if the full history
* sync stage did not complete yet. Its purpose is to give users with a lot of history in their
* profiles a good experience during a large collection sync.
*
* @author grisha
*/
public class AndroidBrowserRecentHistoryServerSyncStage extends AndroidBrowserHistoryServerSyncStage {
protected static final String LOG_TAG = "RecentHistoryStage";
// TODO: Bug 1316110 tracks follow up work to make this stage more efficient.
private static final int HISTORY_BATCH_LIMIT = 50;
// We need a custom configuration bundle name for this stage, because we want to track last-synced
// timestamp for this stage separately from that of a full history sync stage, yet their collection
// names are the same.
private static final String BUNDLE_NAME = "recentHistory.";
private static final String HISTORY_SORT = "newest";
@Override
public String bundlePrefix() {
return BUNDLE_NAME;
}
@Override
protected Repository getLocalRepository() {
return new BufferingMiddlewareRepository(
session.getSyncDeadline(),
new MemoryBufferStorage(),
new AndroidBrowserHistoryRepository()
);
}
@Override
protected Repository getRemoteRepository() throws URISyntaxException {
return new ConstrainedServer11Repository(
getCollection(),
session.getSyncDeadline(),
session.config.storageURL(),
session.getAuthHeaderProvider(),
session.config.infoCollections,
session.config.infoConfiguration,
HISTORY_BATCH_LIMIT,
HISTORY_SORT,
false /* force single batch only */);
}
/**
* This stage is only enabled if full history session is enabled and did not complete a sync yet.
*/
@Override
public boolean isEnabled() throws MetaGlobalException {
final boolean historyStageEnabled = super.isEnabled();
if (!historyStageEnabled) {
return false;
}
if (session.config == null) {
return false;
}
final SynchronizerConfiguration synchronizerConfiguration;
try {
synchronizerConfiguration = new SynchronizerConfiguration(session.config.getBranch(getCollection() + "."));
} catch (IOException|NonObjectJSONException e) {
return false;
}
return synchronizerConfiguration.localBundle.getTimestamp() == -1;
}
}

Просмотреть файл

@ -33,8 +33,9 @@ public interface GlobalSyncStage {
*/
syncTabs("tabs"),
syncPasswords("passwords"),
syncRecentHistory("recentHistory"),
syncBookmarks("bookmarks"),
syncHistory("history"),
syncFullHistory("history"),
syncFormHistory("forms"),
uploadMetaGlobal,

Просмотреть файл

@ -349,7 +349,7 @@ public class TestGlobalSession {
List<String> namesList = new ArrayList<String>(mg.getEnabledEngineNames());
Collections.sort(namesList);
String[] names = namesList.toArray(new String[namesList.size()]);
String[] expected = new String[] { "bookmarks", "clients", "forms", "history", "passwords", "tabs" };
String[] expected = new String[] { "bookmarks", "clients", "forms", "history", "passwords", "recentHistory", "tabs" };
assertArrayEquals(expected, names);
}

Просмотреть файл

@ -117,7 +117,7 @@ public class TestResetCommands {
};
stagesToRun.put(Stage.syncBookmarks, stageGetsReset);
stagesToRun.put(Stage.syncHistory, stageNotReset);
stagesToRun.put(Stage.syncFullHistory, stageNotReset);
final String resetBookmarks = "{\"args\":[\"bookmarks\"],\"command\":\"resetEngine\"}";
ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(resetBookmarks);

Просмотреть файл

@ -24,7 +24,8 @@ public class TestStageLookup {
expected.add(Stage.syncBookmarks);
expected.add(Stage.syncTabs);
expected.add(Stage.syncFormHistory);
expected.add(Stage.syncHistory);
expected.add(Stage.syncFullHistory);
expected.add(Stage.syncRecentHistory);
expected.add(Stage.syncPasswords);
assertEquals(expected, namedStages);
@ -32,7 +33,8 @@ public class TestStageLookup {
assertEquals(Stage.syncTabs, Stage.byName("tabs"));
assertEquals(Stage.syncBookmarks, Stage.byName("bookmarks"));
assertEquals(Stage.syncFormHistory, Stage.byName("forms"));
assertEquals(Stage.syncHistory, Stage.byName("history"));
assertEquals(Stage.syncFullHistory, Stage.byName("history"));
assertEquals(Stage.syncRecentHistory, Stage.byName("recentHistory"));
assertEquals(Stage.syncPasswords, Stage.byName("passwords"));
assertEquals(null, Stage.byName("foobar"));