Remove unused SnapshotStore. (Bug 524916)

This commit is contained in:
Edward Lee 2009-11-25 17:59:26 -08:00
parent d4295ef8e9
commit d851be860d

View File

@ -34,8 +34,7 @@
*
* ***** END LICENSE BLOCK ***** */
const EXPORTED_SYMBOLS = ['Store',
'SnapshotStore'];
const EXPORTED_SYMBOLS = ["Store"];
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -188,145 +187,3 @@ Cache.prototype = {
this._items = {};
}
};
function SnapshotStore(name) {
this._init(name);
}
SnapshotStore.prototype = {
_logName: "SnapStore",
_filename: null,
get filename() {
if (this._filename === null)
throw "filename is null";
return this._filename;
},
set filename(value) {
this._filename = value + ".json";
},
// Last synced tree, version, and GUID (to detect if the store has
// been completely replaced and invalidate the snapshot)
_data: {},
get data() { return this._data; },
set data(value) { this._data = value; },
_version: 0,
get version() { return this._version; },
set version(value) { this._version = value; },
_GUID: null,
get GUID() {
if (!this._GUID)
this._GUID = Utils.makeGUID();
return this._GUID;
},
set GUID(GUID) {
this._GUID = GUID;
},
_init: function SStore__init(name) {
this.filename = name;
this._log = Log4Moz.repository.getLogger("Service." + this._logName);
},
_createCommand: function SStore__createCommand(command) {
this._data[command.GUID] = Utils.deepCopy(command.data);
},
_removeCommand: function SStore__removeCommand(command) {
delete this._data[command.GUID];
},
_editCommand: function SStore__editCommand(command) {
if ("GUID" in command.data) {
// special-case guid changes
let newGUID = command.data.GUID,
oldGUID = command.GUID;
this._data[newGUID] = this._data[oldGUID];
delete this._data[oldGUID];
for (let GUID in this._data) {
if (("parentid" in this._data[GUID]) &&
(this._data[GUID].parentid == oldGUID))
this._data[GUID].parentid = newGUID;
}
}
for (let prop in command.data) {
if (prop == "GUID")
continue;
if (command.GUID in this._data)
this._data[command.GUID][prop] = command.data[prop];
else
this._log.warn("Warning! Edit command for unknown item: " + command.GUID);
}
},
save: function SStore_save() {
this._log.info("Saving snapshot to disk");
let file = Utils.getProfileFile(
{path: "weave/snapshots/" + this.filename,
autoCreate: true}
);
let out = {version: this.version,
GUID: this.GUID,
snapshot: this.data};
out = JSON.stringify(out);
let [fos] = Utils.open(file, ">");
fos.writeString(out);
fos.close();
},
load: function SStore_load() {
let file = Utils.getProfileFile("weave/snapshots/" + this.filename);
if (!file.exists())
return;
try {
let [is] = Utils.open(file, "<");
let json = Utils.readStream(is);
is.close();
json = JSON.parse(json);
if (json && 'snapshot' in json && 'version' in json && 'GUID' in json) {
this._log.debug("Read saved snapshot from disk");
this.data = json.snapshot;
this.version = json.version;
this.GUID = json.GUID;
}
} catch (e) {
this._log.warn("Could not parse saved snapshot; reverting to initial-sync state");
this._log.debug("Exception: " + e);
}
},
serialize: function SStore_serialize() {
let json = JSON.stringify(this.data);
json = json.replace(/:{type/g, ":\n\t{type");
json = json.replace(/}, /g, "},\n ");
json = json.replace(/, parentid/g, ",\n\t parentid");
json = json.replace(/, index/g, ",\n\t index");
json = json.replace(/, title/g, ",\n\t title");
json = json.replace(/, URI/g, ",\n\t URI");
json = json.replace(/, tags/g, ",\n\t tags");
json = json.replace(/, keyword/g, ",\n\t keyword");
return json;
},
wrap: function SStore_wrap() {
return this.data;
},
wipe: function SStore_wipe() {
this.data = {};
this.version = -1;
this.GUID = null;
this.save();
}
};
SnapshotStore.prototype.__proto__ = new Store();