diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java index 519c270c4b0..7df2559180c 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java @@ -197,11 +197,20 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo if (SPECIAL_GUIDS_MAP == null) { HashMap m = new HashMap(); + + // Note that we always use the literal name "mobile" for the Mobile Bookmarks + // folder, regardless of its actual name in the database or the Fennec UI. + // This is to match desktop (working around Bug 747699) and to avoid a similar + // issue locally. See Bug 748898. + m.put("mobile", "mobile"); + + // Other folders use their contextualized names, and we simply rely on + // these not changing, matching desktop, and such to avoid issues. m.put("menu", context.getString(R.string.bookmarks_folder_menu)); m.put("places", context.getString(R.string.bookmarks_folder_places)); m.put("toolbar", context.getString(R.string.bookmarks_folder_toolbar)); m.put("unfiled", context.getString(R.string.bookmarks_folder_unfiled)); - m.put("mobile", context.getString(R.string.bookmarks_folder_mobile)); + SPECIAL_GUIDS_MAP = Collections.unmodifiableMap(m); } @@ -594,6 +603,27 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo return reconciled; } + /** + * Rename mobile folders to "mobile", both in and out. The other half of + * this logic lives in {@link #computeParentFields(BookmarkRecord, String, String)}, where + * the parent name of a record is set from {@link #SPECIAL_GUIDS_MAP} rather than + * from source data. + * + * Apply this approach generally for symmetry. + */ + @Override + protected void fixupRecord(Record record) { + final BookmarkRecord r = (BookmarkRecord) record; + final String parentName = SPECIAL_GUIDS_MAP.get(r.parentID); + if (parentName == null) { + return; + } + if (Logger.logVerbose(LOG_TAG)) { + Logger.trace(LOG_TAG, "Replacing parent name \"" + r.parentName + "\" with \"" + parentName + "\"."); + } + r.parentName = parentName; + } + @Override protected Record prepareRecord(Record record) { if (record.deleted) { diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java b/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java index 8ae0b9c136b..3b6e779a2f7 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java @@ -93,8 +93,24 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos return false; } + /** + * Perform any necessary transformation of a record prior to searching by + * any field other than GUID. + * + * Example: translating remote folder names into local names. + */ + protected void fixupRecord(Record record) { + return; + } + /** * Override in subclass to implement record extension. + * + * Populate any fields of the record that are expensive to calculate, + * prior to reconciling. + * + * Example: computing children arrays. + * * Return null if this record should not be processed. * * @param record @@ -429,6 +445,9 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos // End deletion logic. // Now we're processing a non-deleted incoming record. + // Apply any changes we need in order to correctly find existing records. + fixupRecord(record); + if (existingRecord == null) { trace("Looking up match for record " + record.guid); existingRecord = findExistingRecord(record); @@ -649,6 +668,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos } protected abstract Record prepareRecord(Record record); + protected void updateBookkeeping(Record record) throws NoGuidForIdException, NullCursorException, ParentNotFoundException {