Bug 718238 - Part 0: Cleanup and basic improvements. r=nalexander

This commit is contained in:
Richard Newman 2012-02-23 08:14:05 -08:00
Родитель 58b13f9e35
Коммит f8b57f22c7
8 изменённых файлов: 43 добавлений и 101 удалений

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

@ -176,7 +176,7 @@ public class CryptoRecord extends Record {
if (jsonRecord.containsKey(KEY_MODIFIED)) {
record.lastModified = jsonRecord.getTimestamp(KEY_MODIFIED);
}
if (jsonRecord.containsKey(KEY_SORTINDEX )) {
if (jsonRecord.containsKey(KEY_SORTINDEX)) {
record.sortIndex = jsonRecord.getLong(KEY_SORTINDEX);
}
// TODO: deleted?

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

@ -50,8 +50,6 @@ import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDeleg
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
import org.mozilla.gecko.sync.repositories.domain.Record;
import android.util.Log;
/**
* A RepositorySession is created and used thusly:
*
@ -76,10 +74,6 @@ public abstract class RepositorySession {
private static final String LOG_TAG = "RepositorySession";
private static void error(String message) {
Logger.error(LOG_TAG, message);
}
protected static void trace(String message) {
Logger.trace(LOG_TAG, message);
}
@ -141,7 +135,7 @@ public abstract class RepositorySession {
* Store success calls are not guaranteed.
*/
public void setStoreDelegate(RepositorySessionStoreDelegate delegate) {
Log.d(LOG_TAG, "Setting store delegate to " + delegate);
Logger.debug(LOG_TAG, "Setting store delegate to " + delegate);
this.delegate = delegate;
}
public abstract void store(Record record) throws NoStoreDelegateException;
@ -154,7 +148,7 @@ public abstract class RepositorySession {
}
public void storeDone(final long end) {
Log.d(LOG_TAG, "Scheduling onStoreCompleted for after storing is done.");
Logger.debug(LOG_TAG, "Scheduling onStoreCompleted for after storing is done.");
Runnable command = new Runnable() {
@Override
public void run() {
@ -189,7 +183,7 @@ public abstract class RepositorySession {
if (this.status == SessionStatus.UNSTARTED) {
this.status = SessionStatus.ACTIVE;
} else {
error("Tried to begin() an already active or finished session");
Logger.error(LOG_TAG, "Tried to begin() an already active or finished session");
throw new InvalidSessionTransitionException(null);
}
}
@ -220,11 +214,11 @@ public abstract class RepositorySession {
* @return
*/
protected RepositorySessionBundle getBundle(RepositorySessionBundle optional) {
System.out.println("RepositorySession.getBundle(optional).");
Logger.debug(LOG_TAG, "RepositorySession.getBundle(optional).");
// Why don't we just persist the old bundle?
RepositorySessionBundle bundle = (optional == null) ? new RepositorySessionBundle() : optional;
bundle.put("timestamp", this.lastSyncTimestamp);
System.out.println("Setting bundle timestamp to " + this.lastSyncTimestamp);
Logger.debug(LOG_TAG, "Setting bundle timestamp to " + this.lastSyncTimestamp);
return bundle;
}
@ -244,11 +238,11 @@ public abstract class RepositorySession {
this.status = SessionStatus.DONE;
delegate.deferredFinishDelegate(delegateQueue).onFinishSucceeded(this, this.getBundle(null));
} else {
Log.e(LOG_TAG, "Tried to finish() an unstarted or already finished session");
Logger.error(LOG_TAG, "Tried to finish() an unstarted or already finished session");
Exception e = new InvalidSessionTransitionException(null);
delegate.deferredFinishDelegate(delegateQueue).onFinishFailed(e);
}
Log.i(LOG_TAG, "Shutting down work queues.");
Logger.info(LOG_TAG, "Shutting down work queues.");
// storeWorkQueue.shutdown();
// delegateQueue.shutdown();
}
@ -311,11 +305,11 @@ public abstract class RepositorySession {
final Record localRecord,
final long lastRemoteRetrieval,
final long lastLocalRetrieval) {
Log.d(LOG_TAG, "Reconciling remote " + remoteRecord.guid + " against local " + localRecord.guid);
Logger.debug(LOG_TAG, "Reconciling remote " + remoteRecord.guid + " against local " + localRecord.guid);
if (localRecord.equalPayloads(remoteRecord)) {
if (remoteRecord.lastModified > localRecord.lastModified) {
Log.d(LOG_TAG, "Records are equal. No record application needed.");
Logger.debug(LOG_TAG, "Records are equal. No record application needed.");
return null;
}
@ -329,7 +323,7 @@ public abstract class RepositorySession {
// * The modified times of each record (interpreted through the lens of clock skew);
// * ...
boolean localIsMoreRecent = localRecord.lastModified > remoteRecord.lastModified;
Log.d(LOG_TAG, "Local record is more recent? " + localIsMoreRecent);
Logger.debug(LOG_TAG, "Local record is more recent? " + localIsMoreRecent);
Record donor = localIsMoreRecent ? localRecord : remoteRecord;
// Modify the local record to match the remote record's GUID and values.
@ -358,4 +352,7 @@ public abstract class RepositorySession {
*/
protected synchronized void trackRecord(Record record) {
}
protected synchronized void untrackRecord(Record record) {
}
}

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

@ -4,12 +4,11 @@
package org.mozilla.gecko.sync.repositories;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.domain.Record;
import android.util.Log;
public abstract class StoreTrackingRepositorySession extends RepositorySession {
private static final String LOG_TAG = "StoreTrackSession";
protected StoreTracker storeTracker;
@ -42,12 +41,22 @@ public abstract class StoreTrackingRepositorySession extends RepositorySession {
throw new IllegalStateException("Store tracker not yet initialized!");
}
Log.d(LOG_TAG, "Tracking record " + record.guid +
" (" + record.lastModified + ") to avoid re-upload.");
Logger.debug(LOG_TAG, "Tracking record " + record.guid +
" (" + record.lastModified + ") to avoid re-upload.");
// Future: we care about the timestamp
this.storeTracker.trackRecordForExclusion(record.guid);
}
@Override
protected synchronized void untrackRecord(Record record) {
if (this.storeTracker == null) {
throw new IllegalStateException("Store tracker not yet initialized!");
}
Logger.debug(LOG_TAG, "Un-tracking record " + record.guid + ".");
this.storeTracker.untrackStoredForExclusion(record.guid);
}
@Override
public void abort(RepositorySessionFinishDelegate delegate) {
this.storeTracker = null;

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

@ -1,40 +1,6 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android Sync Client.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jason Voll <jvoll@mozilla.com>
* Richard Newman <rnewman@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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.repositories.android;

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

@ -1,39 +1,6 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android Sync Client.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jason Voll <jvoll@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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.repositories.android;

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

@ -112,6 +112,8 @@ public class BrowserContract {
.buildUpon().appendQueryParameter(PARAM_IS_SYNC, "true")
.appendQueryParameter(PARAM_SHOW_DELETED, "true")
.build();
public static final Uri PARENTS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "parents");
public static final Uri POSITIONS_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "positions");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/bookmark";

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

@ -25,7 +25,7 @@ import android.net.Uri;
public class RepoUtils {
private static final String LOG_TAG = "DBUtils";
private static final String LOG_TAG = "RepoUtils";
/**
* An array of known-special GUIDs.
@ -205,7 +205,7 @@ public class RepoUtils {
return Long.parseLong(path.substring(lastSlash + 1));
}
public static BookmarkRecord computeParentFields(BookmarkRecord rec, String suggestedParentID, String suggestedParentName) {
public static BookmarkRecord computeParentFields(BookmarkRecord rec, String suggestedParentGUID, String suggestedParentName) {
final String guid = rec.guid;
if (guid == null) {
// Oh dear.
@ -216,9 +216,9 @@ public class RepoUtils {
String realParent = SPECIAL_GUID_PARENTS.get(guid);
if (realParent == null) {
// No magic parent. Use whatever the caller suggests.
realParent = suggestedParentID;
realParent = suggestedParentGUID;
} else {
Logger.debug(LOG_TAG, "Ignoring suggested parent ID " + suggestedParentID +
Logger.debug(LOG_TAG, "Ignoring suggested parent ID " + suggestedParentGUID +
" for " + guid + "; using " + realParent);
}
@ -240,7 +240,7 @@ public class RepoUtils {
}
// Create a BookmarkRecord object from a cursor on a row containing a Fennec bookmark.
public static BookmarkRecord bookmarkFromMirrorCursor(Cursor cur, String parentId, String parentName, JSONArray children) {
public static BookmarkRecord bookmarkFromMirrorCursor(Cursor cur, String parentGUID, String parentName, JSONArray children) {
String guid = getStringFromCursor(cur, BrowserContract.SyncColumns.GUID);
String collection = "bookmarks";

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

@ -44,6 +44,7 @@ import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.NonArrayJSONException;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksDataAccessor;
import org.mozilla.gecko.sync.repositories.android.RepoUtils;
import android.util.Log;
@ -196,11 +197,11 @@ public class BookmarkRecord extends Record {
}
public boolean isBookmark() {
return "bookmark".equals(this.type);
return AndroidBrowserBookmarksDataAccessor.TYPE_BOOKMARK.equalsIgnoreCase(this.type);
}
public boolean isFolder() {
return "folder".equals(this.type);
return AndroidBrowserBookmarksDataAccessor.TYPE_FOLDER.equalsIgnoreCase(this.type);
}
@Override