Bug 725525 - Part 1: simplify and remove excess logging in Sync.

This commit is contained in:
Richard Newman 2012-02-15 22:05:52 -08:00
parent 63ed618279
commit 4a77a5d489
21 changed files with 316 additions and 273 deletions

View File

@ -37,8 +37,6 @@
package org.mozilla.gecko.sync;
import android.util.Log;
/**
* A little class to allow us to maintain a count of extant
* things (in our case, callbacks that need to fire), and
@ -53,13 +51,13 @@ public class DelayedWorkTracker {
protected int outstandingCount = 0;
public int incrementOutstanding() {
Log.d(LOG_TAG, "Incrementing outstanding.");
Logger.trace(LOG_TAG, "Incrementing outstanding.");
synchronized(this) {
return ++outstandingCount;
}
}
public int decrementOutstanding() {
Log.d(LOG_TAG, "Decrementing outstanding.");
Logger.trace(LOG_TAG, "Decrementing outstanding.");
Runnable job = null;
int count;
synchronized(this) {
@ -81,10 +79,10 @@ public class DelayedWorkTracker {
}
}
public void delayWorkItem(Runnable item) {
Log.d(LOG_TAG, "delayWorkItem.");
Logger.trace(LOG_TAG, "delayWorkItem.");
boolean runnableNow = false;
synchronized(this) {
Log.d(LOG_TAG, "outstandingCount: " + outstandingCount);
Logger.trace(LOG_TAG, "outstandingCount: " + outstandingCount);
if (outstandingCount == 0) {
runnableNow = true;
} else {
@ -95,7 +93,7 @@ public class DelayedWorkTracker {
}
}
if (runnableNow) {
Log.d(LOG_TAG, "Running item now.");
Logger.trace(LOG_TAG, "Running item now.");
item.run();
}
}

View File

@ -0,0 +1,83 @@
/* 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;
import android.util.Log;
public class Logger {
// For extra debugging.
public static boolean LOG_PERSONAL_INFORMATION = false;
// If true, log to System.out as well as using Android's Log.* calls.
public static boolean LOG_TO_STDOUT = false;
public static void logToStdout(String... s) {
if (LOG_TO_STDOUT) {
for (String string : s) {
System.out.print(string);
}
System.out.println("");
}
}
public static void error(String logTag, String message) {
Logger.error(logTag, message, null);
}
public static void error(String logTag, String message, Throwable error) {
logToStdout(logTag, " :: ERROR: ", message);
if (!Log.isLoggable(logTag, Log.ERROR)) {
return;
}
Log.e(logTag, message, error);
}
public static void warn(String logTag, String message) {
Logger.warn(logTag, message, null);
}
public static void warn(String logTag, String message, Throwable error) {
logToStdout(logTag, " :: WARN: ", message);
if (!Log.isLoggable(logTag, Log.WARN)) {
return;
}
Log.w(logTag, message, error);
}
public static void info(String logTag, String message) {
logToStdout(logTag, " :: INFO: ", message);
if (!Log.isLoggable(logTag, Log.INFO)) {
return;
}
Log.i(logTag, message);
}
public static void debug(String logTag, String message) {
Logger.debug(logTag, message, null);
}
public static void debug(String logTag, String message, Throwable error) {
logToStdout(logTag, " :: DEBUG: ", message);
if (!Log.isLoggable(logTag, Log.DEBUG)) {
return;
}
Log.d(logTag, message, error);
}
public static void trace(String logTag, String message) {
logToStdout(logTag, " :: TRACE: ", message);
if (!Log.isLoggable(logTag, Log.VERBOSE)) {
return;
}
Log.v(logTag, message);
}
public static void pii(String logTag, String message) {
if (LOG_PERSONAL_INFORMATION) {
Logger.debug(logTag, "$$PII$$: " + message);
}
}
}

View File

@ -47,7 +47,7 @@ import android.content.SharedPreferences.Editor;
import android.util.Log;
public class SynchronizerConfiguration {
private static final String LOG_TAG = "SynchronizerConfiguration";
private static final String LOG_TAG = "SynczrConfiguration";
public String syncID;
public RepositorySessionBundle remoteBundle;

View File

@ -42,8 +42,8 @@ import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.security.SecureRandom;
import java.util.HashMap;
import org.mozilla.apache.commons.codec.binary.Base32;
import org.mozilla.apache.commons.codec.binary.Base64;
@ -51,7 +51,6 @@ import org.mozilla.gecko.sync.crypto.Cryptographer;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
public class Utils {
@ -62,46 +61,6 @@ public class Utils {
// See <http://developer.android.com/reference/android/content/Context.html#getSharedPreferences%28java.lang.String,%20int%29>
public static final int SHARED_PREFERENCES_MODE = 0;
// We don't really have a trace logger, so use this to toggle
// some debug logging.
// This is awful. I'm so sorry.
public static boolean ENABLE_TRACE_LOGGING = true;
// If true, log to System.out as well as using Android's Log.* calls.
public static boolean LOG_TO_STDOUT = false;
public static void logToStdout(String... s) {
if (LOG_TO_STDOUT) {
for (String string : s) {
System.out.print(string);
}
System.out.println("");
}
}
public static void error(String logTag, String message) {
logToStdout(logTag, " :: ERROR: ", message);
Log.i(logTag, message);
}
public static void info(String logTag, String message) {
logToStdout(logTag, " :: INFO: ", message);
Log.i(logTag, message);
}
public static void debug(String logTag, String message) {
logToStdout(logTag, " :: DEBUG: ", message);
Log.d(logTag, message);
}
public static void trace(String logTag, String message) {
if (!ENABLE_TRACE_LOGGING) {
return;
}
logToStdout(logTag, " :: TRACE: ", message);
Log.d(logTag, message);
}
public static String generateGuid() {
byte[] encodedBytes = Base64.encodeBase64(generateRandomBytes(9), false);
return new String(encodedBytes).replace("+", "-").replace("/", "_");
@ -142,26 +101,25 @@ public class Utils {
* Output: Hex string
*/
public static String byte2hex(byte[] b) {
// String Buffer can be used instead
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1) {
hs = hs + "0" + stmp;
} else {
hs = hs + stmp;
}
if (n < b.length - 1) {
hs = hs + "";
}
// StringBuffer should be used instead.
String hs = "";
String stmp;
for (int n = 0; n < b.length; n++) {
stmp = java.lang.Integer.toHexString(b[n] & 0XFF);
if (stmp.length() == 1) {
hs = hs + "0" + stmp;
} else {
hs = hs + stmp;
}
return hs;
if (n < b.length - 1) {
hs = hs + "";
}
}
return hs;
}
/*
@ -170,21 +128,21 @@ public class Utils {
* Output: A concatenated version of them
*/
public static byte[] concatAll(byte[] first, byte[]... rest) {
int totalLength = first.length;
for (byte[] array : rest) {
totalLength += array.length;
}
byte[] result = new byte[totalLength];
int offset = first.length;
int totalLength = first.length;
for (byte[] array : rest) {
totalLength += array.length;
}
System.arraycopy(first, 0, result, 0, offset);
for (byte[] array : rest) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
byte[] result = new byte[totalLength];
int offset = first.length;
System.arraycopy(first, 0, result, 0, offset);
for (byte[] array : rest) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
/**
@ -199,16 +157,16 @@ public class Utils {
* Should not occur.
*/
public static byte[] decodeBase64(String base64) throws UnsupportedEncodingException {
return Base64.decodeBase64(base64.getBytes("UTF-8"));
return Base64.decodeBase64(base64.getBytes("UTF-8"));
}
/*
* Decode a friendly base32 string.
*/
public static byte[] decodeFriendlyBase32(String base32) {
Base32 converter = new Base32();
return converter.decode(base32.replace('8', 'l').replace('9', 'o')
.toUpperCase());
Base32 converter = new Base32();
final String translated = base32.replace('8', 'l').replace('9', 'o');
return converter.decode(translated.toUpperCase());
}
/*
@ -216,19 +174,16 @@ public class Utils {
* Input: Hex string
* Output: byte[] version of hex string
*/
public static byte[] hex2Byte(String str)
{
if (str.length() % 2 == 1) {
str = "0" + str;
}
byte[] bytes = new byte[str.length() / 2];
for (int i = 0; i < bytes.length; i++)
{
bytes[i] = (byte) Integer
.parseInt(str.substring(2 * i, 2 * i + 2), 16);
}
return bytes;
public static byte[] hex2Byte(String str) {
if (str.length() % 2 == 1) {
str = "0" + str;
}
byte[] bytes = new byte[str.length() / 2];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) Integer.parseInt(str.substring(2 * i, 2 * i + 2), 16);
}
return bytes;
}
public static String millisecondsToDecimalSecondsString(long ms) {
@ -264,7 +219,7 @@ public class Utils {
public static SharedPreferences getSharedPreferences(Context context, String username, String serverURL) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String prefsPath = getPrefsPath(username, serverURL);
Log.d(LOG_TAG, "Shared preferences: " + prefsPath);
Logger.debug(LOG_TAG, "Shared preferences: " + prefsPath);
return context.getSharedPreferences(prefsPath, SHARED_PREFERENCES_MODE);
}

View File

@ -53,6 +53,7 @@ import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.mozilla.apache.commons.codec.binary.Base64;
import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils;
@ -236,20 +237,26 @@ public class JPakeClient implements JPakeRequestDelegate {
* (Receiver Only) Request channel for J-PAKE from server.
*/
private void getChannel() {
Log.d(LOG_TAG, "Getting channel.");
if (finished)
Logger.debug(LOG_TAG, "Getting channel.");
if (finished) {
Logger.debug(LOG_TAG, "Finished; returning.");
return;
}
JPakeRequest channelRequest = null;
try {
channelRequest = new JPakeRequest(jpakeServer + "new_channel",
makeRequestResourceDelegate());
final String uri = jpakeServer + "new_channel";
Logger.debug(LOG_TAG, "Fetching " + uri);
JPakeRequest channelRequest = new JPakeRequest(uri, makeRequestResourceDelegate());
channelRequest.get();
} catch (URISyntaxException e) {
Log.e(LOG_TAG, "URISyntaxException", e);
abort(Constants.JPAKE_ERROR_CHANNEL);
return;
} catch (Exception e) {
Log.e(LOG_TAG, "Unexpected exception in getChannel().", e);
abort(Constants.JPAKE_ERROR_CHANNEL);
return;
}
channelRequest.get();
}
/*
@ -257,7 +264,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* jOutgoing JSONObject.
*/
private void putStep() {
Log.d(LOG_TAG, "Uploading message.");
Logger.debug(LOG_TAG, "Uploading message.");
runOnThread(new Runnable() {
@Override
public void run() {
@ -275,7 +282,7 @@ public class JPakeClient implements JPakeRequestDelegate {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Log.d(LOG_TAG, "outgoing: " + jOutgoing.toJSONString());
Logger.debug(LOG_TAG, "outgoing: " + jOutgoing.toJSONString());
}
});
}
@ -284,7 +291,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* Step One of J-PAKE protocol.
*/
private void computeStepOne() throws NoSuchAlgorithmException, UnsupportedEncodingException {
Log.d(LOG_TAG, "Computing round 1.");
Logger.debug(LOG_TAG, "Computing round 1.");
JPakeCrypto.round1(jParty, numGen);
@ -307,7 +314,7 @@ public class JPakeClient implements JPakeRequestDelegate {
jOutgoing.put(Constants.JSON_KEY_TYPE, mySignerId + "1");
jOutgoing.put(Constants.JSON_KEY_PAYLOAD, jOne);
jOutgoing.put(Constants.JSON_KEY_VERSION, KEYEXCHANGE_VERSION);
Log.d(LOG_TAG, "Sending: " + jOutgoing.toJSONString());
Logger.debug(LOG_TAG, "Sending: " + jOutgoing.toJSONString());
// Store context to determine next step after PUT request.
stateContext = pairWithPin ? State.SNDR_STEP_ONE : State.RCVR_STEP_ONE;
@ -322,7 +329,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* Two message to be sent.
*/
private void computeStepTwo() throws NonObjectJSONException {
Log.d(LOG_TAG, "Computing round 2.");
Logger.debug(LOG_TAG, "Computing round 2.");
// Check incoming message sender.
if (!jIncoming.get(Constants.JSON_KEY_TYPE).equals(theirSignerId + "1")) {
@ -423,7 +430,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* encrypted message for verification of successful key exchange.
*/
private void computeFinal() throws NonObjectJSONException {
Log.d(LOG_TAG, "Computing final round.");
Logger.debug(LOG_TAG, "Computing final round.");
// Check incoming message type.
if (!jIncoming.get(Constants.JSON_KEY_TYPE).equals(theirSignerId + "2")) {
Log.e(LOG_TAG, "Invalid round 2 message: " + jIncoming.toJSONString());
@ -478,7 +485,7 @@ public class JPakeClient implements JPakeRequestDelegate {
}
if (pairWithPin) { // Wait for other device to send verification of keys.
Log.d(LOG_TAG, "get: verifyPairing");
Logger.debug(LOG_TAG, "get: verifyPairing");
this.state = State.VERIFY_PAIRING;
scheduleGetRequest(jpakePollInterval);
} else { // Prepare and send verification of keys.
@ -507,7 +514,7 @@ public class JPakeClient implements JPakeRequestDelegate {
public ExtendedJSONObject computeKeyVerification(KeyBundle keyBundle)
throws UnsupportedEncodingException, CryptoException
{
Log.d(LOG_TAG, "Encrypting key verification value.");
Logger.debug(LOG_TAG, "Encrypting key verification value.");
// KeyBundle not null
ExtendedJSONObject jPayload = encryptPayload(JPAKE_VERIFY_VALUE, keyBundle);
ExtendedJSONObject result = new ExtendedJSONObject();
@ -581,7 +588,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* @param payload Credentials data to be encrypted.
*/
private void encryptData(KeyBundle keyBundle, String payload) {
Log.d(LOG_TAG, "Encrypting data.");
Logger.debug(LOG_TAG, "Encrypting data.");
ExtendedJSONObject jPayload = null;
try {
jPayload = encryptPayload(payload, keyBundle);
@ -608,7 +615,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* @param keyBundle
*/
private void decryptData(KeyBundle keyBundle) {
Log.d(LOG_TAG, "Verifying their key");
Logger.debug(LOG_TAG, "Verifying their key");
if (!(theirSignerId + "3").equals((String) jIncoming
.get(Constants.JSON_KEY_TYPE))) {
try {
@ -629,7 +636,7 @@ public class JPakeClient implements JPakeRequestDelegate {
abort(Constants.JPAKE_ERROR_WRONGMESSAGE);
return;
}
Log.d(LOG_TAG, "Decrypting data.");
Logger.debug(LOG_TAG, "Decrypting data.");
String cleartext = null;
try {
cleartext = new String(decryptPayload(iPayload, keyBundle), "UTF-8");
@ -659,7 +666,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* @param jCreds Credentials to be stored by controller. May be null if device is sender.
*/
private void complete(JSONObject jCreds) {
Log.d(LOG_TAG, "Exchange complete.");
Logger.debug(LOG_TAG, "Exchange complete.");
finished = true;
ssActivity.onComplete(jCreds);
}
@ -683,7 +690,7 @@ public class JPakeClient implements JPakeRequestDelegate {
int statusCode = response.getStatusCode();
switch (statusCode) {
case 304:
Log.d(LOG_TAG, "Channel hasn't been updated yet. Will try again later");
Logger.debug(LOG_TAG, "Channel hasn't been updated yet. Will try again later");
if (pollTries >= jpakeMaxTries) {
Log.e(LOG_TAG, "Tried for " + pollTries + " times, maxTries " + jpakeMaxTries + ", aborting");
abort(Constants.JPAKE_ERROR_TIMEOUT);
@ -699,7 +706,7 @@ public class JPakeClient implements JPakeRequestDelegate {
abort(Constants.JPAKE_ERROR_NODATA);
break;
case 412: // "Precondition failed"
Log.d(LOG_TAG, "Message already replaced on server by other party.");
Logger.debug(LOG_TAG, "Message already replaced on server by other party.");
onRequestSuccess(res);
break;
default:
@ -754,7 +761,7 @@ public class JPakeClient implements JPakeRequestDelegate {
return;
}
channelUrl = jpakeServer + channel;
Log.d(LOG_TAG, "using channel " + channel);
Logger.debug(LOG_TAG, "using channel " + channel);
ssActivity.displayPin(secret + channel);
@ -811,7 +818,7 @@ public class JPakeClient implements JPakeRequestDelegate {
abort(Constants.JPAKE_ERROR_INVALID);
return;
}
Log.d(LOG_TAG, "incoming message: " + jIncoming.toJSONString());
Logger.debug(LOG_TAG, "incoming message: " + jIncoming.toJSONString());
if (this.state == State.SNDR_STEP_ZERO) {
try {
@ -1040,13 +1047,13 @@ public class JPakeClient implements JPakeRequestDelegate {
* Defaults to user abort
*/
public void abort(String error) {
Log.d(LOG_TAG, "aborting...");
Logger.debug(LOG_TAG, "aborting...");
finished = true;
if (error == null) {
error = Constants.JPAKE_ERROR_USERABORT;
}
Log.d(LOG_TAG, error);
Logger.debug(LOG_TAG, error);
if (Constants.JPAKE_ERROR_CHANNEL.equals(error)
|| Constants.JPAKE_ERROR_NETWORK.equals(error)
@ -1062,7 +1069,7 @@ public class JPakeClient implements JPakeRequestDelegate {
* Make a /report post to to server
*/
private void reportFailure(String error) {
Log.d(LOG_TAG, "reporting error to server");
Logger.debug(LOG_TAG, "reporting error to server");
this.error = error;
runOnThread(new Runnable() {
@Override

View File

@ -41,7 +41,7 @@ package org.mozilla.gecko.sync.repositories;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
@ -77,11 +77,11 @@ public abstract class RepositorySession {
private static final String LOG_TAG = "RepositorySession";
private static void error(String message) {
Utils.error(LOG_TAG, message);
Logger.error(LOG_TAG, message);
}
protected static void trace(String message) {
Utils.trace(LOG_TAG, message);
Logger.trace(LOG_TAG, message);
}
protected SessionStatus status = SessionStatus.UNSTARTED;

View File

@ -82,7 +82,7 @@ public class Server11RepositorySession extends RepositorySession {
}
}
public static final String LOG_TAG = "Server11RepositorySession";
public static final String LOG_TAG = "Server11Session";
private static final int UPLOAD_BYTE_THRESHOLD = 1024 * 1024; // 1MB.
private static final int UPLOAD_ITEM_THRESHOLD = 50;

View File

@ -11,7 +11,7 @@ import org.mozilla.gecko.sync.repositories.domain.Record;
import android.util.Log;
public abstract class StoreTrackingRepositorySession extends RepositorySession {
private static final String LOG_TAG = "StoreTrackingRepositorySession";
private static final String LOG_TAG = "StoreTrackSession";
protected StoreTracker storeTracker;
protected static StoreTracker createStoreTracker() {
@ -59,4 +59,4 @@ public abstract class StoreTrackingRepositorySession extends RepositorySession {
this.storeTracker = null;
super.finish(delegate);
}
}
}

View File

@ -53,7 +53,7 @@ import android.util.Log;
public class AndroidBrowserBookmarksDataAccessor extends AndroidBrowserRepositoryDataAccessor {
private static final String LOG_TAG = "AndroidBrowserBookmarksDataAccessor";
private static final String LOG_TAG = "BookmarksDataAccessor";
/*
* Fragments of SQL to make our lives easier.

View File

@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import org.json.simple.JSONArray;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.repositories.BookmarkNeedsReparentingException;
import org.mozilla.gecko.sync.repositories.NoGuidForIdException;
@ -122,7 +123,7 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
parentName = RepoUtils.getStringFromCursor(name, BrowserContract.Bookmarks.TITLE);
}
else {
Log.e(LOG_TAG, "Couldn't find record with guid '" + parentGUID + "' when looking for parent name.");
Logger.error(LOG_TAG, "Couldn't find record with guid '" + parentGUID + "' when looking for parent name.");
throw new ParentNotFoundException(null);
}
} finally {
@ -157,13 +158,13 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
int childPosition = (int) RepoUtils.getLongFromCursor(children, BrowserContract.Bookmarks.POSITION);
trace(" Child position: " + childPosition);
if (childPosition >= count) {
Log.w(LOG_TAG, "Child position " + childPosition + " greater than expected children " + count);
Logger.warn(LOG_TAG, "Child position " + childPosition + " greater than expected children " + count);
broken.put(childGuid, 0L);
} else {
String existing = kids[childPosition];
if (existing != null) {
Log.w(LOG_TAG, "Child position " + childPosition + " already occupied! (" +
childGuid + ", " + existing + ")");
Logger.warn(LOG_TAG, "Child position " + childPosition + " already occupied! (" +
childGuid + ", " + existing + ")");
broken.put(childGuid, 0L);
} else {
kids[childPosition] = childGuid;
@ -175,7 +176,7 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
try {
Utils.fillArraySpaces(kids, broken);
} catch (Exception e) {
Log.e(LOG_TAG, "Unable to reposition children to yield a valid sequence. Data loss may result.", e);
Logger.error(LOG_TAG, "Unable to reposition children to yield a valid sequence. Data loss may result.", e);
}
// TODO: now use 'broken' to edit the records on disk.
@ -187,8 +188,9 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
}
childArray.add(kid);
}
if (Utils.ENABLE_TRACE_LOGGING) {
Log.d(LOG_TAG, "Output child array: " + childArray.toJSONString());
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
// Don't JSON-encode unless we're logging.
Logger.trace(LOG_TAG, "Output child array: " + childArray.toJSONString());
}
} finally {
children.close();
@ -199,10 +201,10 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
@Override
protected Record recordFromMirrorCursor(Cursor cur) throws NoGuidForIdException, NullCursorException, ParentNotFoundException {
String recordGUID = getGUID(cur);
Log.d(LOG_TAG, "Record from mirror cursor: " + recordGUID);
Logger.trace(LOG_TAG, "Record from mirror cursor: " + recordGUID);
if (forbiddenGUID(recordGUID)) {
Log.d(LOG_TAG, "Ignoring " + recordGUID + " record in recordFromMirrorCursor.");
Logger.debug(LOG_TAG, "Ignoring " + recordGUID + " record in recordFromMirrorCursor.");
return null;
}
@ -210,10 +212,10 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
String androidParentGUID = getGUIDForID(androidParentID);
if (androidParentGUID == null) {
Log.d(LOG_TAG, "No parent GUID for record " + recordGUID + " with parent " + androidParentID);
Logger.debug(LOG_TAG, "No parent GUID for record " + recordGUID + " with parent " + androidParentID);
// If the parent has been stored and somehow has a null GUID, throw an error.
if (idToGuid.containsKey(androidParentID)) {
Log.e(LOG_TAG, "Have the parent android ID for the record but the parent's GUID wasn't found.");
Logger.error(LOG_TAG, "Have the parent android ID for the record but the parent's GUID wasn't found.");
throw new NoGuidForIdException(null);
}
}
@ -227,13 +229,13 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
protected JSONArray getChildArrayForCursor(Cursor cur, String recordGUID) throws NullCursorException {
JSONArray childArray = null;
boolean isFolder = rowIsFolder(cur);
Log.d(LOG_TAG, "Record " + recordGUID + " is a " + (isFolder ? "folder." : "bookmark."));
Logger.debug(LOG_TAG, "Record " + recordGUID + " is a " + (isFolder ? "folder." : "bookmark."));
if (isFolder) {
long androidID = guidToID.get(recordGUID);
childArray = getChildren(androidID);
}
if (childArray != null) {
Log.d(LOG_TAG, "Fetched " + childArray.size() + " children for " + recordGUID);
Logger.debug(LOG_TAG, "Fetched " + childArray.size() + " children for " + recordGUID);
}
return childArray;
}
@ -245,7 +247,7 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
bmk.type.equalsIgnoreCase(AndroidBrowserBookmarksDataAccessor.TYPE_FOLDER)) {
return true;
}
Log.i(LOG_TAG, "Ignoring record with guid: " + record.guid + " and type: " + ((BookmarkRecord)record).type);
Logger.info(LOG_TAG, "Ignoring record with guid: " + record.guid + " and type: " + ((BookmarkRecord)record).type);
return false;
}
@ -255,12 +257,12 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
// and insert them if they don't exist.
Cursor cur;
try {
Log.d(LOG_TAG, "Check and build special GUIDs.");
Logger.debug(LOG_TAG, "Check and build special GUIDs.");
dataAccessor.checkAndBuildSpecialGuids();
cur = dataAccessor.getGuidsIDsForFolders();
Log.d(LOG_TAG, "Got GUIDs for folders.");
Logger.debug(LOG_TAG, "Got GUIDs for folders.");
} catch (android.database.sqlite.SQLiteConstraintException e) {
Log.e(LOG_TAG, "Got sqlite constraint exception working with Fennec bookmark DB.", e);
Logger.error(LOG_TAG, "Got sqlite constraint exception working with Fennec bookmark DB.", e);
delegate.onBeginFailed(e);
return;
} catch (NullCursorException e) {
@ -274,7 +276,7 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
// To deal with parent mapping of bookmarks we have to do some
// hairy stuff. Here's the setup for it.
Log.d(LOG_TAG, "Preparing folder ID mappings.");
Logger.debug(LOG_TAG, "Preparing folder ID mappings.");
idToGuid.put(0L, "places"); // Fake our root.
try {
cur.moveToFirst();
@ -283,13 +285,13 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
long id = RepoUtils.getLongFromCursor(cur, BrowserContract.Bookmarks._ID);
guidToID.put(guid, id);
idToGuid.put(id, guid);
Log.d(LOG_TAG, "GUID " + guid + " maps to " + id);
Logger.debug(LOG_TAG, "GUID " + guid + " maps to " + id);
cur.moveToNext();
}
} finally {
cur.close();
}
Log.d(LOG_TAG, "Done with initial setup of bookmarks session.");
Logger.debug(LOG_TAG, "Done with initial setup of bookmarks session.");
super.begin(delegate);
}
@ -298,8 +300,8 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
// Override finish to do this check; make sure all records
// needing re-parenting have been re-parented.
if (needsReparenting != 0) {
Log.e(LOG_TAG, "Finish called but " + needsReparenting +
" bookmark(s) have been placed in unsorted bookmarks and not been reparented.");
Logger.error(LOG_TAG, "Finish called but " + needsReparenting +
" bookmark(s) have been placed in unsorted bookmarks and not been reparented.");
// TODO: handling of failed reparenting.
// E.g., delegate.onFinishFailed(new BookmarkNeedsReparentingException(null));
@ -337,16 +339,28 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo
missingParentToChildren.put(bmk.parentID, children);
}
if (bmk.isFolder()) {
Log.d(LOG_TAG, "Inserting folder " + bmk.guid + ", " + bmk.title +
" with parent " + bmk.androidParentID +
" (" + bmk.parentID + ", " + bmk.parentName +
", " + bmk.pos + ")");
if (Logger.LOG_PERSONAL_INFORMATION) {
if (bmk.isFolder()) {
Logger.pii(LOG_TAG, "Inserting folder " + bmk.guid + ", " + bmk.title +
" with parent " + bmk.androidParentID +
" (" + bmk.parentID + ", " + bmk.parentName +
", " + bmk.pos + ")");
} else {
Logger.pii(LOG_TAG, "Inserting bookmark " + bmk.guid + ", " + bmk.title + ", " +
bmk.bookmarkURI + " with parent " + bmk.androidParentID +
" (" + bmk.parentID + ", " + bmk.parentName +
", " + bmk.pos + ")");
}
} else {
Log.d(LOG_TAG, "Inserting bookmark " + bmk.guid + ", " + bmk.title + ", " +
bmk.bookmarkURI + " with parent " + bmk.androidParentID +
" (" + bmk.parentID + ", " + bmk.parentName +
", " + bmk.pos + ")");
if (bmk.isFolder()) {
Logger.debug(LOG_TAG, "Inserting folder " + bmk.guid + ", parent " +
bmk.androidParentID +
" (" + bmk.parentID + ", " + bmk.pos + ")");
} else {
Logger.debug(LOG_TAG, "Inserting bookmark " + bmk.guid + " with parent " +
bmk.androidParentID +
" (" + bmk.parentID + ", " + ", " + bmk.pos + ")");
}
}
return bmk;
}

View File

@ -51,7 +51,7 @@ public abstract class AndroidBrowserRepositoryDataAccessor {
private static final String[] GUID_COLUMNS = new String[] { BrowserContract.SyncColumns.GUID };
protected Context context;
protected String LOG_TAG = "AndroidBrowserRepositoryDataAccessor";
protected static String LOG_TAG = "BrowserDataAccessor";
private final RepoUtils.QueryHelper queryHelper;
public AndroidBrowserRepositoryDataAccessor(Context context) {

View File

@ -41,7 +41,7 @@ package org.mozilla.gecko.sync.repositories.android;
import java.util.ArrayList;
import java.util.HashMap;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.InvalidRequestException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
@ -62,7 +62,6 @@ import org.mozilla.gecko.sync.repositories.domain.Record;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
/**
* You'll notice that all delegate calls *either*:
@ -89,7 +88,7 @@ import android.util.Log;
public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepositorySession {
protected AndroidBrowserRepositoryDataAccessor dbHelper;
public static final String LOG_TAG = "AndroidBrowserRepositorySession";
public static final String LOG_TAG = "BrowserRepoSession";
private HashMap<String, String> recordToGuid;
public AndroidBrowserRepositorySession(Repository repository) {
@ -142,7 +141,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
// is no way of knowing which call would be hit first.
checkDatabase();
} catch (ProfileDatabaseException e) {
Log.e(LOG_TAG, "ProfileDatabaseException from begin. Fennec must be launched once until this error is fixed");
Logger.error(LOG_TAG, "ProfileDatabaseException from begin. Fennec must be launched once until this error is fixed");
deferredDelegate.onBeginFailed(e);
return;
} catch (NullCursorException e) {
@ -159,10 +158,10 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
protected abstract String buildRecordString(Record record);
protected void checkDatabase() throws ProfileDatabaseException, NullCursorException {
Utils.info(LOG_TAG, "BEGIN: checking database.");
Logger.info(LOG_TAG, "BEGIN: checking database.");
try {
dbHelper.fetch(new String[] { "none" }).close();
Utils.info(LOG_TAG, "END: checking database.");
Logger.info(LOG_TAG, "END: checking database.");
} catch (NullPointerException e) {
throw new ProfileDatabaseException(e);
}
@ -215,7 +214,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
cur.moveToNext();
}
} finally {
Log.d(LOG_TAG, "Closing cursor after guidsSince.");
Logger.debug(LOG_TAG, "Closing cursor after guidsSince.");
cur.close();
}
@ -240,7 +239,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
}
protected void fetchFromCursor(Cursor cursor, RecordFilter filter, long end) {
Log.d(LOG_TAG, "Fetch from cursor:");
Logger.debug(LOG_TAG, "Fetch from cursor:");
try {
try {
if (!cursor.moveToFirst()) {
@ -248,28 +247,28 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
return;
}
while (!cursor.isAfterLast()) {
Log.d(LOG_TAG, "... one more record.");
Record r = recordFromMirrorCursor(cursor);
if (r != null) {
if (filter == null || !filter.excludeRecord(r)) {
Logger.trace(LOG_TAG, "Processing record " + r.guid);
delegate.onFetchedRecord(transformRecord(r));
} else {
Log.d(LOG_TAG, "Filter says to skip record.");
Logger.debug(LOG_TAG, "Skipping filtered record " + r.guid);
}
}
cursor.moveToNext();
}
delegate.onFetchCompleted(end);
} catch (NoGuidForIdException e) {
Log.w(LOG_TAG, "No GUID for ID.", e);
Logger.warn(LOG_TAG, "No GUID for ID.", e);
delegate.onFetchFailed(e, null);
} catch (Exception e) {
Log.w(LOG_TAG, "Exception in fetchFromCursor.", e);
Logger.warn(LOG_TAG, "Exception in fetchFromCursor.", e);
delegate.onFetchFailed(e, null);
return;
}
} finally {
Log.d(LOG_TAG, "Closing cursor after fetch.");
Logger.trace(LOG_TAG, "Closing cursor after fetch.");
cursor.close();
}
}
@ -298,7 +297,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
}
if (guids == null || guids.length < 1) {
Log.e(LOG_TAG, "No guids sent to fetch");
Logger.error(LOG_TAG, "No guids sent to fetch");
delegate.onFetchFailed(new InvalidRequestException(null), null);
return;
}
@ -319,7 +318,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
throw new IllegalStateException("Store tracker not yet initialized!");
}
Log.i(LOG_TAG, "Running fetchSince(" + timestamp + ").");
Logger.info(LOG_TAG, "Running fetchSince(" + timestamp + ").");
FetchSinceRunnable command = new FetchSinceRunnable(timestamp, now(), this.storeTracker.getFilter(), delegate);
delegateQueue.execute(command);
}
@ -367,7 +366,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
throw new NoStoreDelegateException();
}
if (record == null) {
Log.e(LOG_TAG, "Record sent to store was null");
Logger.error(LOG_TAG, "Record sent to store was null");
throw new IllegalArgumentException("Null record passed to AndroidBrowserRepositorySession.store().");
}
@ -388,7 +387,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
// See Bug 708149. This might be resolved by Fennec changing its database
// schema, or by Sync storing non-applied records in its own private database.
if (!checkRecordType(record)) {
Log.d(LOG_TAG, "Ignoring record " + record.guid + " due to unknown record type.");
Logger.debug(LOG_TAG, "Ignoring record " + record.guid + " due to unknown record type.");
// Don't throw: we don't want to abort the entire sync when we get a livemark!
// delegate.onRecordStoreFailed(new InvalidBookmarkTypeException(null));
@ -445,7 +444,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
trace("Remote is older, local is not deleted. Ignoring.");
if (!locallyModified) {
Log.w(LOG_TAG, "Inconsistency: old remote record is deleted, but local record not modified!");
Logger.warn(LOG_TAG, "Inconsistency: old remote record is deleted, but local record not modified!");
// Ensure that this is tracked for upload.
}
return;
@ -475,35 +474,35 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
Record toStore = reconcileRecords(record, existingRecord, lastRemoteRetrieval, lastLocalRetrieval);
if (toStore == null) {
Log.d(LOG_TAG, "Reconciling returned null. Not inserting a record.");
Logger.debug(LOG_TAG, "Reconciling returned null. Not inserting a record.");
return;
}
// TODO: pass in timestamps?
Log.d(LOG_TAG, "Replacing " + existingRecord.guid + " with record " + toStore.guid);
Logger.debug(LOG_TAG, "Replacing " + existingRecord.guid + " with record " + toStore.guid);
Record replaced = replace(toStore, existingRecord);
// Note that we don't track records here; deciding that is the job
// of reconcileRecords.
Log.d(LOG_TAG, "Calling delegate callback with guid " + replaced.guid +
"(" + replaced.androidID + ")");
Logger.debug(LOG_TAG, "Calling delegate callback with guid " + replaced.guid +
"(" + replaced.androidID + ")");
delegate.onRecordStoreSucceeded(replaced);
return;
} catch (MultipleRecordsForGuidException e) {
Log.e(LOG_TAG, "Multiple records returned for given guid: " + record.guid);
Logger.error(LOG_TAG, "Multiple records returned for given guid: " + record.guid);
delegate.onRecordStoreFailed(e);
return;
} catch (NoGuidForIdException e) {
Log.e(LOG_TAG, "Store failed for " + record.guid, e);
Logger.error(LOG_TAG, "Store failed for " + record.guid, e);
delegate.onRecordStoreFailed(e);
return;
} catch (NullCursorException e) {
Log.e(LOG_TAG, "Store failed for " + record.guid, e);
Logger.error(LOG_TAG, "Store failed for " + record.guid, e);
delegate.onRecordStoreFailed(e);
return;
} catch (Exception e) {
Log.e(LOG_TAG, "Store failed for " + record.guid, e);
Logger.error(LOG_TAG, "Store failed for " + record.guid, e);
delegate.onRecordStoreFailed(e);
return;
}
@ -523,11 +522,11 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
Record toStore = prepareRecord(record);
Uri recordURI = dbHelper.insert(toStore);
long id = RepoUtils.getAndroidIdFromUri(recordURI);
Log.d(LOG_TAG, "Inserted as " + id);
Logger.debug(LOG_TAG, "Inserted as " + id);
toStore.androidID = id;
updateBookkeeping(toStore);
Log.d(LOG_TAG, "insert() returning record " + toStore.guid);
Logger.debug(LOG_TAG, "insert() returning record " + toStore.guid);
return toStore;
}
@ -537,7 +536,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
// newRecord should already have suitable androidID and guid.
dbHelper.update(existingRecord.guid, toStore);
updateBookkeeping(toStore);
Log.d(LOG_TAG, "replace() returning record " + toStore.guid);
Logger.debug(LOG_TAG, "replace() returning record " + toStore.guid);
return toStore;
}
@ -583,15 +582,15 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
protected Record findExistingRecord(Record record) throws MultipleRecordsForGuidException,
NoGuidForIdException, NullCursorException, ParentNotFoundException {
Log.d(LOG_TAG, "Finding existing record for incoming record with GUID " + record.guid);
Logger.debug(LOG_TAG, "Finding existing record for incoming record with GUID " + record.guid);
String recordString = buildRecordString(record);
Log.d(LOG_TAG, "Searching with record string " + recordString);
Logger.debug(LOG_TAG, "Searching with record string " + recordString);
String guid = getRecordToGuidMap().get(recordString);
if (guid != null) {
Log.d(LOG_TAG, "Found one. Returning computed record.");
Logger.debug(LOG_TAG, "Found one. Returning computed record.");
return recordForGUID(guid);
}
Log.d(LOG_TAG, "findExistingRecord failed to find one for " + record.guid);
Logger.debug(LOG_TAG, "findExistingRecord failed to find one for " + record.guid);
return null;
}
@ -603,7 +602,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
}
private void createRecordToGuidMap() throws NoGuidForIdException, NullCursorException, ParentNotFoundException {
Utils.info(LOG_TAG, "BEGIN: creating record -> GUID map.");
Logger.info(LOG_TAG, "BEGIN: creating record -> GUID map.");
recordToGuid = new HashMap<String, String>();
Cursor cur = dbHelper.fetchAll();
try {
@ -620,7 +619,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos
} finally {
cur.close();
}
Utils.info(LOG_TAG, "END: creating record -> GUID map.");
Logger.info(LOG_TAG, "END: creating record -> GUID map.");
}
public void putRecordToGuidMap(String recordString, String guid) throws NoGuidForIdException, NullCursorException, ParentNotFoundException {

View File

@ -46,6 +46,7 @@ import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.mozilla.gecko.R;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.repositories.NullCursorException;
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
import org.mozilla.gecko.sync.repositories.domain.HistoryRecord;
@ -54,7 +55,6 @@ import org.mozilla.gecko.sync.repositories.domain.PasswordRecord;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
public class RepoUtils {
@ -177,7 +177,7 @@ public class RepoUtils {
public Cursor safeQuery(String label, String[] projection, String selection, String[] selectionArgs, String sortOrder) throws NullCursorException {
Cursor c = this.query(label, projection, selection, selectionArgs, sortOrder);
if (c == null) {
Log.e(tag, "Got null cursor exception in " + tag + ((label == null) ? "" : label));
Logger.error(tag, "Got null cursor exception in " + tag + ((label == null) ? "" : label));
throw new NullCursorException(null);
}
return c;
@ -206,7 +206,7 @@ public class RepoUtils {
try {
return (JSONArray) new JSONParser().parse(getStringFromCursor(cur, colId));
} catch (ParseException e) {
Log.e(LOG_TAG, "JSON parsing error for " + colId, e);
Logger.error(LOG_TAG, "JSON parsing error for " + colId, e);
return null;
}
}
@ -223,7 +223,7 @@ public class RepoUtils {
final String guid = rec.guid;
if (guid == null) {
// Oh dear.
Log.e(LOG_TAG, "No guid in computeParentFields!");
Logger.error(LOG_TAG, "No guid in computeParentFields!");
return null;
}
@ -232,13 +232,13 @@ public class RepoUtils {
// No magic parent. Use whatever the caller suggests.
realParent = suggestedParentID;
} else {
Log.d(LOG_TAG, "Ignoring suggested parent ID " + suggestedParentID +
" for " + guid + "; using " + realParent);
Logger.debug(LOG_TAG, "Ignoring suggested parent ID " + suggestedParentID +
" for " + guid + "; using " + realParent);
}
if (realParent == null) {
// Oh dear.
Log.e(LOG_TAG, "No parent for record " + guid);
Logger.error(LOG_TAG, "No parent for record " + guid);
return null;
}
@ -283,18 +283,24 @@ public class RepoUtils {
private static BookmarkRecord logBookmark(BookmarkRecord rec) {
try {
Log.d(LOG_TAG, "Returning bookmark record " + rec.guid + " (" + rec.androidID +
", " + rec.parentName + ":" + rec.parentID + ")");
Log.d(LOG_TAG, "> Title: " + rec.title);
Log.d(LOG_TAG, "> Type: " + rec.type);
Log.d(LOG_TAG, "> URI: " + rec.bookmarkURI);
Log.d(LOG_TAG, "> Android position: " + rec.androidPosition);
Log.d(LOG_TAG, "> Position: " + rec.pos);
if (rec.isFolder()) {
Log.d(LOG_TAG, "FOLDER: Children are " + (rec.children == null ? "null" : rec.children.toJSONString()));
Logger.debug(LOG_TAG, "Returning bookmark record " + rec.guid + " (" + rec.androidID +
", parent " + rec.parentID + ")");
if (Logger.LOG_PERSONAL_INFORMATION) {
Logger.pii(LOG_TAG, "> Parent name: " + rec.parentName);
Logger.pii(LOG_TAG, "> Title: " + rec.title);
Logger.pii(LOG_TAG, "> Type: " + rec.type);
Logger.pii(LOG_TAG, "> URI: " + rec.bookmarkURI);
Logger.pii(LOG_TAG, "> Android position: " + rec.androidPosition);
Logger.pii(LOG_TAG, "> Position: " + rec.pos);
if (rec.isFolder()) {
Logger.pii(LOG_TAG, "FOLDER: Children are " +
(rec.children == null ?
"null" :
rec.children.toJSONString()));
}
}
} catch (Exception e) {
Log.d(LOG_TAG, "Exception logging bookmark record " + rec, e);
Logger.debug(LOG_TAG, "Exception logging bookmark record " + rec, e);
}
return rec;
}
@ -319,13 +325,15 @@ public class RepoUtils {
private static HistoryRecord logHistory(HistoryRecord rec) {
try {
Log.d(LOG_TAG, "Returning history record " + rec.guid + " (" + rec.androidID + ")");
Log.d(LOG_TAG, "> Title: " + rec.title);
Log.d(LOG_TAG, "> URI: " + rec.histURI);
Log.d(LOG_TAG, "> Visited: " + rec.fennecDateVisited);
Log.d(LOG_TAG, "> Visits: " + rec.fennecVisitCount);
Logger.debug(LOG_TAG, "Returning history record " + rec.guid + " (" + rec.androidID + ")");
Logger.debug(LOG_TAG, "> Visited: " + rec.fennecDateVisited);
Logger.debug(LOG_TAG, "> Visits: " + rec.fennecVisitCount);
if (Logger.LOG_PERSONAL_INFORMATION) {
Logger.pii(LOG_TAG, "> Title: " + rec.title);
Logger.pii(LOG_TAG, "> URI: " + rec.histURI);
}
} catch (Exception e) {
Log.d(LOG_TAG, "Exception logging bookmark record " + rec, e);
Logger.debug(LOG_TAG, "Exception logging bookmark record " + rec, e);
}
return rec;
}
@ -356,7 +364,7 @@ public class RepoUtils {
public static void queryTimeLogger(String methodCallingQuery, long queryStart, long queryEnd) {
long elapsedTime = queryEnd - queryStart;
Log.i(LOG_TAG, "Query timer: " + methodCallingQuery + " took " + elapsedTime + "ms.");
Logger.debug(LOG_TAG, "Query timer: " + methodCallingQuery + " took " + elapsedTime + "ms.");
}
public static boolean stringsEqual(String a, String b) {

View File

@ -41,6 +41,7 @@ package org.mozilla.gecko.sync.repositories.domain;
import org.json.simple.JSONArray;
import org.mozilla.gecko.sync.CryptoRecord;
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.RepoUtils;
@ -224,7 +225,7 @@ public class BookmarkRecord extends Record {
}
private void trace(String s) {
Utils.trace(LOG_TAG, s);
Logger.trace(LOG_TAG, s);
}
@Override

View File

@ -43,6 +43,7 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.mozilla.gecko.sync.CryptoRecord;
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.RepoUtils;
@ -191,10 +192,11 @@ public class HistoryRecord extends Record {
}
private boolean checkVisitsEquals(HistoryRecord other) {
Log.d(LOG_TAG, "Checking visits.");
if (Utils.ENABLE_TRACE_LOGGING) {
Log.d(LOG_TAG, ">> Mine: " + ((this.visits == null) ? "null" : this.visits.toJSONString()));
Log.d(LOG_TAG, ">> Theirs: " + ((other.visits == null) ? "null" : other.visits.toJSONString()));
Logger.debug(LOG_TAG, "Checking visits.");
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
// Don't JSON-encode unless we're logging.
Logger.trace(LOG_TAG, ">> Mine: " + ((this.visits == null) ? "null" : this.visits.toJSONString()));
Logger.trace(LOG_TAG, ">> Theirs: " + ((other.visits == null) ? "null" : other.visits.toJSONString()));
}
// Handle nulls.

View File

@ -57,7 +57,7 @@ import android.os.IBinder;
import android.util.Log;
public class SyncAuthenticatorService extends Service {
private static final String LOG_TAG = "SyncAuthenticatorService";
private static final String LOG_TAG = "SyncAuthService";
private SyncAccountAuthenticator sAccountAuthenticator = null;
@Override

View File

@ -47,7 +47,7 @@ import org.mozilla.gecko.sync.net.SyncStorageResponse;
import android.util.Log;
public class FetchInfoCollectionsStage implements GlobalSyncStage {
private static final String LOG_TAG = "FetchInfoCollectionsStage";
private static final String LOG_TAG = "FetchInfoCollStage";
public class StageInfoCollectionsDelegate implements InfoCollectionsDelegate {

View File

@ -37,7 +37,7 @@
package org.mozilla.gecko.sync.synchronizer;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.repositories.domain.Record;
import android.util.Log;
@ -51,7 +51,7 @@ import android.util.Log;
*
*/
class ConcurrentRecordConsumer extends RecordConsumer {
private static final String LOG_TAG = "ConcurrentRecordConsumer";
private static final String LOG_TAG = "CRecordConsumer";
/**
* When this is true and all records have been processed, the consumer
@ -65,15 +65,15 @@ class ConcurrentRecordConsumer extends RecordConsumer {
}
private static void info(String message) {
Utils.info(LOG_TAG, message);
Logger.info(LOG_TAG, message);
}
private static void debug(String message) {
Utils.debug(LOG_TAG, message);
Logger.debug(LOG_TAG, message);
}
private static void trace(String message) {
Utils.trace(LOG_TAG, message);
Logger.trace(LOG_TAG, message);
}
private Object monitor = new Object();
@ -104,7 +104,7 @@ class ConcurrentRecordConsumer extends RecordConsumer {
private Object countMonitor = new Object();
@Override
public void stored() {
debug("Record stored. Notifying.");
trace("Record stored. Notifying.");
synchronized (countMonitor) {
counter++;
}

View File

@ -40,8 +40,8 @@ package org.mozilla.gecko.sync.synchronizer;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.DeferredRepositorySessionBeginDelegate;
@ -135,30 +135,6 @@ class RecordsChannel implements
return source.isActive() && sink.isActive();
}
private static void info(String message) {
Utils.logToStdout(LOG_TAG, "::INFO: ", message);
Log.i(LOG_TAG, message);
}
private static void trace(String message) {
if (!Utils.ENABLE_TRACE_LOGGING) {
return;
}
Utils.logToStdout(LOG_TAG, "::TRACE: ", message);
Log.d(LOG_TAG, message);
}
private static void error(String message, Exception e) {
Utils.logToStdout(LOG_TAG, "::ERROR: ", message);
Log.e(LOG_TAG, message, e);
}
private static void warn(String message, Exception e) {
Utils.logToStdout(LOG_TAG, "::WARN: ", message);
Log.w(LOG_TAG, message, e);
}
/**
* Attempt to abort an outstanding fetch. Finish both sessions.
*/
@ -194,7 +170,7 @@ class RecordsChannel implements
* Begin both sessions, invoking flow() when done.
*/
public void beginAndFlow() {
info("Beginning source.");
Logger.info(LOG_TAG, "Beginning source.");
source.begin(this);
}
@ -203,7 +179,7 @@ class RecordsChannel implements
try {
sink.store(record);
} catch (NoStoreDelegateException e) {
error("Got NoStoreDelegateException in RecordsChannel.store(). This should not occur. Aborting.", e);
Logger.error(LOG_TAG, "Got NoStoreDelegateException in RecordsChannel.store(). This should not occur. Aborting.", e);
delegate.onFlowStoreFailed(this, e);
this.abort();
}
@ -211,7 +187,7 @@ class RecordsChannel implements
@Override
public void onFetchFailed(Exception ex, Record record) {
warn("onFetchFailed. Calling for immediate stop.", ex);
Logger.warn(LOG_TAG, "onFetchFailed. Calling for immediate stop.", ex);
this.consumer.halt();
}
@ -232,8 +208,8 @@ class RecordsChannel implements
@Override
public void onFetchCompleted(long end) {
info("onFetchCompleted. Stopping consumer once stores are done.");
info("Fetch timestamp is " + end);
Logger.info(LOG_TAG, "onFetchCompleted. Stopping consumer once stores are done.");
Logger.info(LOG_TAG, "Fetch timestamp is " + end);
this.end = end;
this.consumer.queueFilled();
}
@ -253,7 +229,7 @@ class RecordsChannel implements
@Override
public void consumerIsDone(boolean allRecordsQueued) {
trace("Consumer is done. Are we waiting for it? " + waitingForQueueDone);
Logger.trace(LOG_TAG, "Consumer is done. Are we waiting for it? " + waitingForQueueDone);
if (waitingForQueueDone) {
waitingForQueueDone = false;
this.sink.storeDone(); // Now we'll be waiting for onStoreCompleted.
@ -262,7 +238,7 @@ class RecordsChannel implements
@Override
public void onStoreCompleted() {
info("onStoreCompleted. Notifying delegate of onFlowCompleted. End is " + end);
Logger.info(LOG_TAG, "onStoreCompleted. Notifying delegate of onFlowCompleted. End is " + end);
// TODO: synchronize on consumer callback?
delegate.onFlowCompleted(this, end);
}
@ -275,11 +251,11 @@ class RecordsChannel implements
@Override
public void onBeginSucceeded(RepositorySession session) {
if (session == source) {
info("Source session began. Beginning sink session.");
Logger.info(LOG_TAG, "Source session began. Beginning sink session.");
sink.begin(this);
}
if (session == sink) {
info("Sink session began. Beginning flow.");
Logger.info(LOG_TAG, "Sink session began. Beginning flow.");
this.flow();
return;
}

View File

@ -63,7 +63,7 @@ public class Synchronizer {
public class SynchronizerDelegateSessionDelegate implements
SynchronizerSessionDelegate {
private static final String LOG_TAG = "SynchronizerDelegateSessionDelegate";
private static final String LOG_TAG = "SyncDelSDelegate";
private SynchronizerDelegate synchronizerDelegate;
private SynchronizerSession session;

File diff suppressed because one or more lines are too long