зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1365143 - Add schema version number for each Form Fill record in ProfileStorage.; r=lchang
MozReview-Commit-ID: 6o7ThqX79Sx --HG-- extra : rebase_source : 19f8fca0e2502bf42edfd270915a1947f0b94389
This commit is contained in:
Родитель
4fc3418733
Коммит
26686ec4b8
|
@ -14,6 +14,7 @@
|
|||
* addresses: [
|
||||
* {
|
||||
* guid, // 12 characters
|
||||
* version, // schema version in integer
|
||||
*
|
||||
* // address fields
|
||||
* given-name,
|
||||
|
@ -45,6 +46,7 @@
|
|||
* creditCards: [
|
||||
* {
|
||||
* guid, // 12 characters
|
||||
* version, // schema version in integer
|
||||
*
|
||||
* // credit card fields
|
||||
* cc-name,
|
||||
|
@ -95,7 +97,9 @@ XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
|
|||
|
||||
const PROFILE_JSON_FILE_NAME = "autofill-profiles.json";
|
||||
|
||||
const SCHEMA_VERSION = 1;
|
||||
const STORAGE_SCHEMA_VERSION = 1;
|
||||
const ADDRESS_SCHEMA_VERSION = 1;
|
||||
const CREDIT_CARD_SCHEMA_VERSION = 1;
|
||||
|
||||
const VALID_PROFILE_FIELDS = [
|
||||
"given-name",
|
||||
|
@ -121,6 +125,7 @@ const VALID_CREDIT_CARD_FIELDS = [
|
|||
|
||||
const INTERNAL_FIELDS = [
|
||||
"guid",
|
||||
"version",
|
||||
"timeCreated",
|
||||
"timeLastUsed",
|
||||
"timeLastModified",
|
||||
|
@ -144,14 +149,17 @@ class AutofillRecords {
|
|||
* A key of "store.data".
|
||||
* @param {Array.<string>} validFields
|
||||
* A list containing non-metadata field names.
|
||||
* @param {number} schemaVersion
|
||||
* The schema version for the new record.
|
||||
*/
|
||||
constructor(store, collectionName, validFields) {
|
||||
constructor(store, collectionName, validFields, schemaVersion) {
|
||||
FormAutofillUtils.defineLazyLogGetter(this, "AutofillRecords:" + collectionName);
|
||||
|
||||
this.VALID_FIELDS = validFields;
|
||||
|
||||
this._store = store;
|
||||
this._collectionName = collectionName;
|
||||
this._schemaVersion = schemaVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +169,7 @@ class AutofillRecords {
|
|||
* The current schema version number.
|
||||
*/
|
||||
get version() {
|
||||
return SCHEMA_VERSION;
|
||||
return this._schemaVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,6 +192,7 @@ class AutofillRecords {
|
|||
.replace(/[{}-]/g, "").substring(0, 12);
|
||||
}
|
||||
recordToSave.guid = guid;
|
||||
recordToSave.version = this.version;
|
||||
|
||||
// Metadata
|
||||
let now = Date.now();
|
||||
|
@ -374,7 +383,7 @@ class AutofillRecords {
|
|||
|
||||
class Addresses extends AutofillRecords {
|
||||
constructor(store) {
|
||||
super(store, "addresses", VALID_PROFILE_FIELDS);
|
||||
super(store, "addresses", VALID_PROFILE_FIELDS, ADDRESS_SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
_recordReadProcessor(profile, {noComputedFields} = {}) {
|
||||
|
@ -449,7 +458,7 @@ class Addresses extends AutofillRecords {
|
|||
|
||||
class CreditCards extends AutofillRecords {
|
||||
constructor(store) {
|
||||
super(store, "creditCards", VALID_CREDIT_CARD_FIELDS);
|
||||
super(store, "creditCards", VALID_CREDIT_CARD_FIELDS, CREDIT_CARD_SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
_recordReadProcessor(creditCard, {noComputedFields} = {}) {
|
||||
|
@ -541,6 +550,10 @@ function ProfileStorage(path) {
|
|||
}
|
||||
|
||||
ProfileStorage.prototype = {
|
||||
get version() {
|
||||
return STORAGE_SCHEMA_VERSION;
|
||||
},
|
||||
|
||||
get addresses() {
|
||||
if (!this._addresses) {
|
||||
this._store.ensureDataReady();
|
||||
|
@ -576,7 +589,7 @@ ProfileStorage.prototype = {
|
|||
},
|
||||
|
||||
_dataPostProcessor(data) {
|
||||
data.version = SCHEMA_VERSION;
|
||||
data.version = this.version;
|
||||
if (!data.addresses) {
|
||||
data.addresses = [];
|
||||
}
|
||||
|
|
|
@ -175,6 +175,7 @@ add_task(async function test_add() {
|
|||
do_check_record_matches(addresses[1], TEST_ADDRESS_2);
|
||||
|
||||
do_check_neq(addresses[0].guid, undefined);
|
||||
do_check_eq(addresses[0].version, 1);
|
||||
do_check_neq(addresses[0].timeCreated, undefined);
|
||||
do_check_eq(addresses[0].timeLastModified, addresses[0].timeCreated);
|
||||
do_check_eq(addresses[0].timeLastUsed, 0);
|
||||
|
|
|
@ -187,6 +187,7 @@ add_task(async function test_add() {
|
|||
do_check_credit_card_matches(creditCards[1], TEST_CREDIT_CARD_2);
|
||||
|
||||
do_check_neq(creditCards[0].guid, undefined);
|
||||
do_check_eq(creditCards[0].version, 1);
|
||||
do_check_neq(creditCards[0].timeCreated, undefined);
|
||||
do_check_eq(creditCards[0].timeLastModified, creditCards[0].timeCreated);
|
||||
do_check_eq(creditCards[0].timeLastUsed, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче