diff --git a/services/sync/modules/base_records/crypto.js b/services/sync/modules/base_records/crypto.js index dad57111336d..c051de541cce 100644 --- a/services/sync/modules/base_records/crypto.js +++ b/services/sync/modules/base_records/crypto.js @@ -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 ") + " }", diff --git a/services/sync/modules/base_records/wbo.js b/services/sync/modules/base_records/wbo.js index aca6083ba6e9..eb719b33764c 100644 --- a/services/sync/modules/base_records/wbo.js +++ b/services/sync/modules/base_records/wbo.js @@ -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 ") + " }", }; diff --git a/services/sync/modules/type_records/clients.js b/services/sync/modules/type_records/clients.js index 653e043da3e3..f1e43ef8007b 100644 --- a/services/sync/modules/type_records/clients.js +++ b/services/sync/modules/type_records/clients.js @@ -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"]); diff --git a/services/sync/modules/type_records/forms.js b/services/sync/modules/type_records/forms.js index 0ee64c98cfb1..9319937601cc 100644 --- a/services/sync/modules/type_records/forms.js +++ b/services/sync/modules/type_records/forms.js @@ -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"]); diff --git a/services/sync/modules/type_records/history.js b/services/sync/modules/type_records/history.js index a77e2dd2a67a..19a8d93aa9af 100644 --- a/services/sync/modules/type_records/history.js +++ b/services/sync/modules/type_records/history.js @@ -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"]); diff --git a/services/sync/modules/type_records/tabs.js b/services/sync/modules/type_records/tabs.js index 1e3f8d4982b5..f35b171dfde9 100644 --- a/services/sync/modules/type_records/tabs.js +++ b/services/sync/modules/type_records/tabs.js @@ -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"]); diff --git a/services/sync/tests/unit/test_records_wbo.js b/services/sync/tests/unit/test_records_wbo.js index fdd4bf2c3a7d..950c43876669 100644 --- a/services/sync/tests/unit/test_records_wbo.js +++ b/services/sync/tests/unit/test_records_wbo.js @@ -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(); }