Bug 591103 - use TTL for history, form history, clients, tabs. r=mconnor

This commit is contained in:
Philipp von Weitershausen 2011-01-14 13:22:20 -08:00
Родитель 4fe6c0c11f
Коммит f46d33c149
7 изменённых файлов: 39 добавлений и 0 удалений

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

@ -129,6 +129,7 @@ CryptoWrapper.prototype = {
"id: " + this.id,
"index: " + this.sortindex,
"modified: " + this.modified,
"ttl: " + this.ttl,
"payload: " + (this.deleted ? "DELETED" : JSON.stringify(this.cleartext)),
"collection: " + (this.collection || "undefined")
].join("\n ") + " }",

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

@ -98,6 +98,8 @@ WBORecord.prototype = {
let obj = {};
for (let [key, val] in Iterator(this.data))
obj[key] = key == "payload" ? JSON.stringify(val) : val;
if (this.ttl)
obj.ttl = this.ttl;
return obj;
},
@ -105,6 +107,7 @@ WBORecord.prototype = {
"id: " + this.id,
"index: " + this.sortindex,
"modified: " + this.modified,
"ttl: " + this.ttl,
"payload: " + JSON.stringify(this.payload)
].join("\n ") + " }",
};

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

@ -44,12 +44,15 @@ const Cu = Components.utils;
Cu.import("resource://services-sync/base_records/crypto.js");
Cu.import("resource://services-sync/util.js");
const CLIENTS_TTL = 1814400; // 21 days
function ClientsRec(collection, id) {
CryptoWrapper.call(this, collection, id);
}
ClientsRec.prototype = {
__proto__: CryptoWrapper.prototype,
_logName: "Record.Clients",
ttl: CLIENTS_TTL
};
Utils.deferGetSet(ClientsRec, "cleartext", ["name", "type", "commands"]);

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

@ -44,12 +44,15 @@ const Cu = Components.utils;
Cu.import("resource://services-sync/base_records/crypto.js");
Cu.import("resource://services-sync/util.js");
const FORMS_TTL = 5184000; // 60 days
function FormRec(collection, id) {
CryptoWrapper.call(this, collection, id);
}
FormRec.prototype = {
__proto__: CryptoWrapper.prototype,
_logName: "Record.Form",
ttl: FORMS_TTL
};
Utils.deferGetSet(FormRec, "cleartext", ["name", "value"]);

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

@ -44,12 +44,15 @@ const Cu = Components.utils;
Cu.import("resource://services-sync/base_records/crypto.js");
Cu.import("resource://services-sync/util.js");
const HISTORY_TTL = 5184000; // 60 days
function HistoryRec(collection, id) {
CryptoWrapper.call(this, collection, id);
}
HistoryRec.prototype = {
__proto__: CryptoWrapper.prototype,
_logName: "Record.History",
ttl: HISTORY_TTL
};
Utils.deferGetSet(HistoryRec, "cleartext", ["histUri", "title", "visits"]);

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

@ -44,12 +44,15 @@ const Cu = Components.utils;
Cu.import("resource://services-sync/base_records/crypto.js");
Cu.import("resource://services-sync/util.js");
const TABS_TTL = 604800; // 7 days
function TabSetRecord(collection, id) {
CryptoWrapper.call(this, collection, id);
}
TabSetRecord.prototype = {
__proto__: CryptoWrapper.prototype,
_logName: "Record.Tabs",
ttl: TABS_TTL
};
Utils.deferGetSet(TabSetRecord, "cleartext", ["clientName", "tabs"]);

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

@ -6,6 +6,27 @@ Cu.import("resource://services-sync/resource.js");
Cu.import("resource://services-sync/util.js");
function test_toJSON() {
_("Create a record, for now without a TTL.");
let wbo = new WBORecord("coll", "a_record");
wbo.modified = 12345;
wbo.sortindex = 42;
wbo.payload = {};
_("Verify that the JSON representation contains the WBO properties, but not TTL.");
let json = JSON.parse(JSON.stringify(wbo));
do_check_eq(json.modified, 12345);
do_check_eq(json.sortindex, 42);
do_check_eq(json.payload, "{}");
do_check_false("ttl" in json);
_("Set a TTL, make sure it's present in the JSON representation.");
wbo.ttl = 30*60;
json = JSON.parse(JSON.stringify(wbo));
do_check_eq(json.ttl, 30*60);
}
function test_fetch() {
let record = {id: "asdf-1234-asdf-1234",
modified: 2454725.98283,
@ -55,5 +76,7 @@ function test_fetch() {
function run_test() {
initTestLogging("Trace");
test_toJSON();
test_fetch();
}