Skip to content

Commit

Permalink
Merge fx-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
philikon committed Mar 2, 2011
2 parents 68b2239 + 7547590 commit 6e13f1b
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 214 deletions.
3 changes: 0 additions & 3 deletions services/crypto/modules/WeaveCrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ WeaveCrypto.prototype = {
// security/nss/lib/softoken/secmodt.h#201
// typedef PRUint32 PK11AttrFlags;
this.nss_t.PK11AttrFlags = ctypes.unsigned_int;
// security/nss/lib/util/secoidt.h#454
// typedef enum
this.nss_t.SECOidTag = ctypes.int;
// security/nss/lib/util/seccomon.h#83
// typedef struct SECItemStr SECItem; --> SECItemStr defined right below it
this.nss_t.SECItem = ctypes.StructType(
Expand Down
4 changes: 2 additions & 2 deletions services/sync/modules/engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ SyncEngine.prototype = {
try {
item.decrypt();
} catch (ex if (Utils.isHMACMismatch(ex) &&
this.handleHMACMismatch())) {
this.handleHMACMismatch(item))) {
// Let's try handling it.
// If the callback returns true, try decrypting again, because
// we've got new keys.
Expand Down Expand Up @@ -1083,7 +1083,7 @@ SyncEngine.prototype = {
this._resetClient();
},

handleHMACMismatch: function handleHMACMismatch() {
handleHMACMismatch: function handleHMACMismatch(item) {
return Weave.Service.handleHMACEvent();
}
};
16 changes: 10 additions & 6 deletions services/sync/modules/engines/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,12 @@ BookmarksStore.prototype = {
}
return this.__childGUIDsStm = stmt;
},
_childGUIDsCols: ["item_id", "guid"],

_getChildGUIDsForId: function _getChildGUIDsForId(itemid) {
let stmt = this._childGUIDsStm;
stmt.params.parent = itemid;
let rows = Utils.queryAsync(stmt, ["item_id", "guid"]);
let rows = Utils.queryAsync(stmt, this._childGUIDsCols);
return rows.map(function (row) {
if (row.guid) {
return row.guid;
Expand Down Expand Up @@ -1144,6 +1145,7 @@ BookmarksStore.prototype = {
"WHERE url = :url " +
"LIMIT 1");
},
_frecencyCols: ["frecency"],

get _addGUIDAnnotationNameStm() {
let stmt = this._getStmt(
Expand All @@ -1165,6 +1167,7 @@ BookmarksStore.prototype = {
stmt.params.anno_name = GUID_ANNO;
return stmt;
},
_checkGUIDItemAnnotationCols: ["item_id", "name_id", "anno_id", "anno_date"],

get _addItemAnnotationStm() {
return this._getStmt(
Expand Down Expand Up @@ -1214,8 +1217,7 @@ BookmarksStore.prototype = {

let stmt = this._checkGUIDItemAnnotationStm;
stmt.params.item_id = id;
let result = Utils.queryAsync(stmt, ["item_id", "name_id", "anno_id",
"anno_date"])[0];
let result = Utils.queryAsync(stmt, this._checkGUIDItemAnnotationCols)[0];
if (!result) {
this._log.warn("Couldn't annotate bookmark id " + id);
return guid;
Expand Down Expand Up @@ -1268,6 +1270,7 @@ BookmarksStore.prototype = {

return this.__guidForIdStm = stmt;
},
_guidForIdCols: ["guid"],

GUIDForId: function GUIDForId(id) {
let special = kSpecialIds.specialGUIDForId(id);
Expand All @@ -1278,7 +1281,7 @@ BookmarksStore.prototype = {
stmt.params.item_id = id;

// Use the existing GUID if it exists
let result = Utils.queryAsync(stmt, ["guid"])[0];
let result = Utils.queryAsync(stmt, this._guidForIdCols)[0];
if (result && result.guid)
return result.guid;

Expand Down Expand Up @@ -1318,6 +1321,7 @@ BookmarksStore.prototype = {

return this.__idForGUIDStm = stmt;
},
_idForGUIDCols: ["item_id"],

// noCreate is provided as an optional argument to prevent the creation of
// non-existent special records, such as "mobile".
Expand All @@ -1329,7 +1333,7 @@ BookmarksStore.prototype = {
// guid might be a String object rather than a string.
stmt.params.guid = guid.toString();

let results = Utils.queryAsync(stmt, ["item_id"]);
let results = Utils.queryAsync(stmt, this._idForGUIDCols);
this._log.trace("Rows matching GUID " + guid + ": " +
results.map(function(x) x.item_id));

Expand Down Expand Up @@ -1372,7 +1376,7 @@ BookmarksStore.prototype = {
// Add in the bookmark's frecency if we have something
if (record.bmkUri != null) {
this._frecencyStm.params.url = record.bmkUri;
let result = Utils.queryAsync(this._frecencyStm, ["frecency"]);
let result = Utils.queryAsync(this._frecencyStm, this._frecencyCols);
if (result.length)
index += result[0].frecency;
}
Expand Down
14 changes: 14 additions & 0 deletions services/sync/modules/engines/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ ClientEngine.prototype = {
_wipeClient: function _wipeClient() {
SyncEngine.prototype._resetClient.call(this);
this._store.wipe();
},

// Override the default behavior to delete bad records from the server.
handleHMACMismatch: function handleHMACMismatch(item) {
this._log.debug("Handling HMAC mismatch for " + item.id);
if (SyncEngine.prototype.handleHMACMismatch.call(this, item))
return true;

// It's a bad client record. Save it to be deleted at the end of the sync.
this._log.debug("Bad client record detected. Scheduling for deletion.");
this._deleteId(item.id);

// Don't try again.
return false;
}
};

Expand Down
6 changes: 3 additions & 3 deletions services/sync/modules/engines/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let FormWrapper = {
getQuery.params.value = value;

// Give the guid if we found one
let item = Utils.queryAsync(getQuery, "guid")[0];
let item = Utils.queryAsync(getQuery, ["guid"])[0];

if (!item) {
// Shouldn't happen, but Bug 597400...
Expand Down Expand Up @@ -120,9 +120,9 @@ let FormWrapper = {

hasGUID: function hasGUID(guid) {
let query = this.createStatement(
"SELECT 1 FROM moz_formhistory WHERE guid = :guid");
"SELECT guid FROM moz_formhistory WHERE guid = :guid LIMIT 1");
query.params.guid = guid;
return Utils.queryAsync(query).length == 1;
return Utils.queryAsync(query, ["guid"]).length == 1;
},

replaceGUID: function replaceGUID(oldGUID, newGUID) {
Expand Down
Loading

0 comments on commit 6e13f1b

Please sign in to comment.