зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1413488 - [Form Autofill] Rename the "data" property of "AutofillRecords" to "_data". r=seanlee
MozReview-Commit-ID: CmvqUW9PrrW --HG-- extra : rebase_source : fe0e5d5570335d0ae0078cfb604a29d70d0a29f1
This commit is contained in:
Родитель
9214b56b5a
Коммит
ecdb3157e8
|
@ -265,7 +265,7 @@ class AutofillRecords {
|
||||||
this._schemaVersion = schemaVersion;
|
this._schemaVersion = schemaVersion;
|
||||||
|
|
||||||
let hasChanges = (result, record) => this._migrateRecord(record) || result;
|
let hasChanges = (result, record) => this._migrateRecord(record) || result;
|
||||||
if (this.data.reduce(hasChanges, false)) {
|
if (this._data.reduce(hasChanges, false)) {
|
||||||
this._store.saveSoon();
|
this._store.saveSoon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ class AutofillRecords {
|
||||||
* @returns {array}
|
* @returns {array}
|
||||||
* The data object.
|
* The data object.
|
||||||
*/
|
*/
|
||||||
get data() {
|
get _data() {
|
||||||
return this._store.data[this._collectionName];
|
return this._store.data[this._collectionName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,9 +322,9 @@ class AutofillRecords {
|
||||||
includeDeleted: true,
|
includeDeleted: true,
|
||||||
});
|
});
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
let existing = this.data[index];
|
let existing = this._data[index];
|
||||||
if (existing.deleted) {
|
if (existing.deleted) {
|
||||||
this.data.splice(index, 1);
|
this._data.splice(index, 1);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Record ${recordToSave.guid} already exists`);
|
throw new Error(`Record ${recordToSave.guid} already exists`);
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ class AutofillRecords {
|
||||||
sync.changeCounter = 0;
|
sync.changeCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data.push(recordToSave);
|
this._data.push(recordToSave);
|
||||||
|
|
||||||
this._store.saveSoon();
|
this._store.saveSoon();
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ class AutofillRecords {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone the record before modifying it to avoid exposing incomplete changes.
|
// Clone the record before modifying it to avoid exposing incomplete changes.
|
||||||
let recordFound = this._clone(this.data[recordFoundIndex]);
|
let recordFound = this._clone(this._data[recordFoundIndex]);
|
||||||
this._stripComputedFields(recordFound);
|
this._stripComputedFields(recordFound);
|
||||||
|
|
||||||
let recordToUpdate = this._clone(record);
|
let recordToUpdate = this._clone(record);
|
||||||
|
@ -445,7 +445,7 @@ class AutofillRecords {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._computeFields(recordFound);
|
this._computeFields(recordFound);
|
||||||
this.data[recordFoundIndex] = recordFound;
|
this._data[recordFoundIndex] = recordFound;
|
||||||
|
|
||||||
this._store.saveSoon();
|
this._store.saveSoon();
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ class AutofillRecords {
|
||||||
this.log.warn("attempting to remove non-existing entry", guid);
|
this.log.warn("attempting to remove non-existing entry", guid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let existing = this.data[index];
|
let existing = this._data[index];
|
||||||
if (existing.deleted) {
|
if (existing.deleted) {
|
||||||
return; // already a tombstone - don't touch it.
|
return; // already a tombstone - don't touch it.
|
||||||
}
|
}
|
||||||
|
@ -504,7 +504,7 @@ class AutofillRecords {
|
||||||
if (existingSync) {
|
if (existingSync) {
|
||||||
// existing sync metadata means it has been synced. This means we must
|
// existing sync metadata means it has been synced. This means we must
|
||||||
// leave a tombstone behind.
|
// leave a tombstone behind.
|
||||||
this.data[index] = {
|
this._data[index] = {
|
||||||
guid,
|
guid,
|
||||||
timeLastModified: Date.now(),
|
timeLastModified: Date.now(),
|
||||||
deleted: true,
|
deleted: true,
|
||||||
|
@ -514,7 +514,7 @@ class AutofillRecords {
|
||||||
} else {
|
} else {
|
||||||
// If there's no sync meta-data, this record has never been synced, so
|
// If there's no sync meta-data, this record has never been synced, so
|
||||||
// we can delete it.
|
// we can delete it.
|
||||||
this.data.splice(index, 1);
|
this._data.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,7 +564,7 @@ class AutofillRecords {
|
||||||
getAll({rawData = false, includeDeleted = false} = {}) {
|
getAll({rawData = false, includeDeleted = false} = {}) {
|
||||||
this.log.debug("getAll", rawData, includeDeleted);
|
this.log.debug("getAll", rawData, includeDeleted);
|
||||||
|
|
||||||
let records = this.data.filter(r => !r.deleted || includeDeleted);
|
let records = this._data.filter(r => !r.deleted || includeDeleted);
|
||||||
// Records are cloned to avoid accidental modifications from outside.
|
// Records are cloned to avoid accidental modifications from outside.
|
||||||
let clonedRecords = records.map(r => this._cloneAndCleanUp(r));
|
let clonedRecords = records.map(r => this._cloneAndCleanUp(r));
|
||||||
clonedRecords.forEach(record => {
|
clonedRecords.forEach(record => {
|
||||||
|
@ -712,12 +712,12 @@ class AutofillRecords {
|
||||||
* it's uploaded.
|
* it's uploaded.
|
||||||
*/
|
*/
|
||||||
_replaceRecordAt(index, remoteRecord, {keepSyncMetadata = false} = {}) {
|
_replaceRecordAt(index, remoteRecord, {keepSyncMetadata = false} = {}) {
|
||||||
let localRecord = this.data[index];
|
let localRecord = this._data[index];
|
||||||
let newRecord = this._clone(remoteRecord);
|
let newRecord = this._clone(remoteRecord);
|
||||||
|
|
||||||
this._stripComputedFields(newRecord);
|
this._stripComputedFields(newRecord);
|
||||||
|
|
||||||
this.data[index] = newRecord;
|
this._data[index] = newRecord;
|
||||||
|
|
||||||
if (keepSyncMetadata) {
|
if (keepSyncMetadata) {
|
||||||
// It's safe to move the Sync metadata from the old record to the new
|
// It's safe to move the Sync metadata from the old record to the new
|
||||||
|
@ -772,7 +772,7 @@ class AutofillRecords {
|
||||||
this._getSyncMetaData(forkedLocalRecord, true);
|
this._getSyncMetaData(forkedLocalRecord, true);
|
||||||
|
|
||||||
this._computeFields(forkedLocalRecord);
|
this._computeFields(forkedLocalRecord);
|
||||||
this.data.push(forkedLocalRecord);
|
this._data.push(forkedLocalRecord);
|
||||||
|
|
||||||
return forkedLocalRecord;
|
return forkedLocalRecord;
|
||||||
}
|
}
|
||||||
|
@ -803,7 +803,7 @@ class AutofillRecords {
|
||||||
throw new Error(`Record ${remoteRecord.guid} not found`);
|
throw new Error(`Record ${remoteRecord.guid} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let localRecord = this.data[localIndex];
|
let localRecord = this._data[localIndex];
|
||||||
let sync = this._getSyncMetaData(localRecord, true);
|
let sync = this._getSyncMetaData(localRecord, true);
|
||||||
|
|
||||||
let forkedGUID = null;
|
let forkedGUID = null;
|
||||||
|
@ -857,11 +857,11 @@ class AutofillRecords {
|
||||||
|
|
||||||
let sync = this._getSyncMetaData(tombstone, true);
|
let sync = this._getSyncMetaData(tombstone, true);
|
||||||
sync.changeCounter = 0;
|
sync.changeCounter = 0;
|
||||||
this.data.push(tombstone);
|
this._data.push(tombstone);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let existing = this.data[index];
|
let existing = this._data[index];
|
||||||
let sync = this._getSyncMetaData(existing, true);
|
let sync = this._getSyncMetaData(existing, true);
|
||||||
if (sync.changeCounter > 0) {
|
if (sync.changeCounter > 0) {
|
||||||
// Deleting a record with unsynced local changes. To avoid potential
|
// Deleting a record with unsynced local changes. To avoid potential
|
||||||
|
@ -878,7 +878,7 @@ class AutofillRecords {
|
||||||
|
|
||||||
// Removing a record that's not changed locally, and that's not already
|
// Removing a record that's not changed locally, and that's not already
|
||||||
// deleted. Replace the record with a synced tombstone.
|
// deleted. Replace the record with a synced tombstone.
|
||||||
this.data[index] = {
|
this._data[index] = {
|
||||||
guid,
|
guid,
|
||||||
timeLastModified: Date.now(),
|
timeLastModified: Date.now(),
|
||||||
deleted: true,
|
deleted: true,
|
||||||
|
@ -900,7 +900,7 @@ class AutofillRecords {
|
||||||
pullSyncChanges() {
|
pullSyncChanges() {
|
||||||
let changes = {};
|
let changes = {};
|
||||||
|
|
||||||
let profiles = this.data;
|
let profiles = this._data;
|
||||||
for (let profile of profiles) {
|
for (let profile of profiles) {
|
||||||
let sync = this._getSyncMetaData(profile, true);
|
let sync = this._getSyncMetaData(profile, true);
|
||||||
if (sync.changeCounter < 1) {
|
if (sync.changeCounter < 1) {
|
||||||
|
@ -957,7 +957,7 @@ class AutofillRecords {
|
||||||
* metadata for all items is removed.
|
* metadata for all items is removed.
|
||||||
*/
|
*/
|
||||||
resetSync() {
|
resetSync() {
|
||||||
for (let record of this.data) {
|
for (let record of this._data) {
|
||||||
delete record._sync;
|
delete record._sync;
|
||||||
}
|
}
|
||||||
// XXX - we should probably also delete all tombstones?
|
// XXX - we should probably also delete all tombstones?
|
||||||
|
@ -987,7 +987,7 @@ class AutofillRecords {
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = this._findIndexByGUID(oldID);
|
let index = this._findIndexByGUID(oldID);
|
||||||
let profile = this.data[index];
|
let profile = this._data[index];
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new Error("changeGUID: no source record");
|
throw new Error("changeGUID: no source record");
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1037,7 @@ class AutofillRecords {
|
||||||
// handled them separately when applying the record.
|
// handled them separately when applying the record.
|
||||||
throw new Error("Tombstones can't have duplicates");
|
throw new Error("Tombstones can't have duplicates");
|
||||||
}
|
}
|
||||||
let localRecords = this.data;
|
let localRecords = this._data;
|
||||||
for (let localRecord of localRecords) {
|
for (let localRecord of localRecords) {
|
||||||
if (localRecord.deleted) {
|
if (localRecord.deleted) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1110,11 +1110,11 @@ class AutofillRecords {
|
||||||
|
|
||||||
_findByGUID(guid, {includeDeleted = false} = {}) {
|
_findByGUID(guid, {includeDeleted = false} = {}) {
|
||||||
let found = this._findIndexByGUID(guid, {includeDeleted});
|
let found = this._findIndexByGUID(guid, {includeDeleted});
|
||||||
return found < 0 ? undefined : this.data[found];
|
return found < 0 ? undefined : this._data[found];
|
||||||
}
|
}
|
||||||
|
|
||||||
_findIndexByGUID(guid, {includeDeleted = false} = {}) {
|
_findIndexByGUID(guid, {includeDeleted = false} = {}) {
|
||||||
return this.data.findIndex(record => {
|
return this._data.findIndex(record => {
|
||||||
return record.guid == guid && (!record.deleted || includeDeleted);
|
return record.guid == guid && (!record.deleted || includeDeleted);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1178,7 +1178,7 @@ class AutofillRecords {
|
||||||
*/
|
*/
|
||||||
mergeToStorage(targetRecord, strict = false) {
|
mergeToStorage(targetRecord, strict = false) {
|
||||||
let mergedGUIDs = [];
|
let mergedGUIDs = [];
|
||||||
for (let record of this.data) {
|
for (let record of this._data) {
|
||||||
if (!record.deleted && this.mergeIfPossible(record.guid, targetRecord, strict)) {
|
if (!record.deleted && this.mergeIfPossible(record.guid, targetRecord, strict)) {
|
||||||
mergedGUIDs.push(record.guid);
|
mergedGUIDs.push(record.guid);
|
||||||
}
|
}
|
||||||
|
@ -1665,7 +1665,7 @@ class CreditCards extends AutofillRecords {
|
||||||
getDuplicateGuid(targetCreditCard) {
|
getDuplicateGuid(targetCreditCard) {
|
||||||
let clonedTargetCreditCard = this._clone(targetCreditCard);
|
let clonedTargetCreditCard = this._clone(targetCreditCard);
|
||||||
this._normalizeRecord(clonedTargetCreditCard);
|
this._normalizeRecord(clonedTargetCreditCard);
|
||||||
for (let creditCard of this.data) {
|
for (let creditCard of this._data) {
|
||||||
let isDuplicate = this.VALID_FIELDS.every(field => {
|
let isDuplicate = this.VALID_FIELDS.every(field => {
|
||||||
if (!clonedTargetCreditCard[field]) {
|
if (!clonedTargetCreditCard[field]) {
|
||||||
return !creditCard[field];
|
return !creditCard[field];
|
||||||
|
|
|
@ -26,4 +26,4 @@ MOCHITEST_MANIFESTS += ['test/mochitest/mochitest.ini']
|
||||||
JAR_MANIFESTS += ['jar.mn']
|
JAR_MANIFESTS += ['jar.mn']
|
||||||
|
|
||||||
with Files('**'):
|
with Files('**'):
|
||||||
BUG_COMPONENT = ('Toolkit', 'Form Manager')
|
BUG_COMPONENT = ('Toolkit', 'Form Autofill')
|
||||||
|
|
|
@ -333,7 +333,7 @@ add_task(async function test_add() {
|
||||||
|
|
||||||
// Empty string should be deleted before saving.
|
// Empty string should be deleted before saving.
|
||||||
profileStorage.addresses.add(TEST_ADDRESS_WITH_EMPTY_FIELD);
|
profileStorage.addresses.add(TEST_ADDRESS_WITH_EMPTY_FIELD);
|
||||||
let address = profileStorage.addresses.data[2];
|
let address = profileStorage.addresses._data[2];
|
||||||
do_check_eq(address.name, TEST_ADDRESS_WITH_EMPTY_FIELD.name);
|
do_check_eq(address.name, TEST_ADDRESS_WITH_EMPTY_FIELD.name);
|
||||||
do_check_eq(address["street-address"], undefined);
|
do_check_eq(address["street-address"], undefined);
|
||||||
|
|
||||||
|
@ -393,8 +393,8 @@ add_task(async function test_update() {
|
||||||
do_check_eq(getSyncChangeCounter(profileStorage.addresses, guid), 2);
|
do_check_eq(getSyncChangeCounter(profileStorage.addresses, guid), 2);
|
||||||
|
|
||||||
// Empty string should be deleted while updating.
|
// Empty string should be deleted while updating.
|
||||||
profileStorage.addresses.update(profileStorage.addresses.data[0].guid, TEST_ADDRESS_WITH_EMPTY_FIELD);
|
profileStorage.addresses.update(profileStorage.addresses._data[0].guid, TEST_ADDRESS_WITH_EMPTY_FIELD);
|
||||||
address = profileStorage.addresses.data[0];
|
address = profileStorage.addresses._data[0];
|
||||||
do_check_eq(address.name, TEST_ADDRESS_WITH_EMPTY_FIELD.name);
|
do_check_eq(address.name, TEST_ADDRESS_WITH_EMPTY_FIELD.name);
|
||||||
do_check_eq(address["street-address"], undefined);
|
do_check_eq(address["street-address"], undefined);
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ add_task(async function test_add() {
|
||||||
|
|
||||||
// Empty string should be deleted before saving.
|
// Empty string should be deleted before saving.
|
||||||
profileStorage.creditCards.add(TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
|
profileStorage.creditCards.add(TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
|
||||||
let creditCard = profileStorage.creditCards.data[2];
|
let creditCard = profileStorage.creditCards._data[2];
|
||||||
do_check_eq(creditCard["cc-exp-month"], TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]);
|
do_check_eq(creditCard["cc-exp-month"], TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]);
|
||||||
do_check_eq(creditCard["cc-name"], undefined);
|
do_check_eq(creditCard["cc-name"], undefined);
|
||||||
|
|
||||||
|
@ -299,8 +299,8 @@ add_task(async function test_update() {
|
||||||
do_check_credit_card_matches(creditCard, TEST_CREDIT_CARD_3);
|
do_check_credit_card_matches(creditCard, TEST_CREDIT_CARD_3);
|
||||||
|
|
||||||
// Empty string should be deleted while updating.
|
// Empty string should be deleted while updating.
|
||||||
profileStorage.creditCards.update(profileStorage.creditCards.data[0].guid, TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
|
profileStorage.creditCards.update(profileStorage.creditCards._data[0].guid, TEST_CREDIT_CARD_WITH_EMPTY_FIELD);
|
||||||
creditCard = profileStorage.creditCards.data[0];
|
creditCard = profileStorage.creditCards._data[0];
|
||||||
do_check_eq(creditCard["cc-exp-month"], TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]);
|
do_check_eq(creditCard["cc-exp-month"], TEST_CREDIT_CARD_WITH_EMPTY_FIELD["cc-exp-month"]);
|
||||||
do_check_eq(creditCard["cc-name"], undefined);
|
do_check_eq(creditCard["cc-name"], undefined);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче