mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 545767 - Clean up various names/strings needed for each set of engines/stores/trackers
Pass the engine name when constructing a subclass engine and construct the store/tracker with the same name.
This commit is contained in:
parent
8c4c90a45d
commit
0e09a51b7a
@ -105,11 +105,12 @@ EngineManagerSvc.prototype = {
|
||||
return engineObject.map(this.register, this);
|
||||
|
||||
try {
|
||||
let name = engineObject.prototype.name;
|
||||
let engine = new engineObject();
|
||||
let name = engine.name;
|
||||
if (name in this._engines)
|
||||
this._log.error("Engine '" + name + "' is already registered!");
|
||||
else
|
||||
this._engines[name] = new engineObject();
|
||||
this._engines[name] = engine;
|
||||
}
|
||||
catch(ex) {
|
||||
let mesg = ex.message ? ex.message : ex;
|
||||
@ -132,9 +133,12 @@ EngineManagerSvc.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function Engine() {
|
||||
function Engine(name) {
|
||||
this.Name = name || "Unnamed";
|
||||
this.name = name.toLowerCase();
|
||||
|
||||
this._notify = Utils.notify("weave:engine:");
|
||||
this._log = Log4Moz.repository.getLogger("Engine." + this.logName);
|
||||
this._log = Log4Moz.repository.getLogger("Engine." + this.Name);
|
||||
let level = Svc.Prefs.get("log.logger.engine." + this.name, "Debug");
|
||||
this._log.level = Log4Moz.Level[level];
|
||||
|
||||
@ -142,13 +146,7 @@ function Engine() {
|
||||
this._log.debug("Engine initialized");
|
||||
}
|
||||
Engine.prototype = {
|
||||
name: "engine",
|
||||
_displayName: "Boring Engine",
|
||||
description: "An engine example - it doesn't actually sync anything",
|
||||
logName: "Engine",
|
||||
|
||||
// _storeObj, and _trackerObj should to be overridden in subclasses
|
||||
|
||||
_storeObj: Store,
|
||||
_trackerObj: Tracker,
|
||||
|
||||
@ -159,15 +157,15 @@ Engine.prototype = {
|
||||
get score() this._tracker.score,
|
||||
|
||||
get _store() {
|
||||
if (!this.__store)
|
||||
this.__store = new this._storeObj();
|
||||
return this.__store;
|
||||
let store = new this._storeObj(this.Name);
|
||||
this.__defineGetter__("_store", function() store);
|
||||
return store;
|
||||
},
|
||||
|
||||
get _tracker() {
|
||||
if (!this.__tracker)
|
||||
this.__tracker = new this._trackerObj();
|
||||
return this.__tracker;
|
||||
let tracker = new this._trackerObj(this.Name);
|
||||
this.__defineGetter__("_tracker", function() tracker);
|
||||
return tracker;
|
||||
},
|
||||
|
||||
get displayName() {
|
||||
@ -175,7 +173,7 @@ Engine.prototype = {
|
||||
return Str.engines.get(this.name);
|
||||
} catch (e) {}
|
||||
|
||||
return this._displayName;
|
||||
return this.Name;
|
||||
},
|
||||
|
||||
sync: function Engine_sync() {
|
||||
@ -291,8 +289,8 @@ Engine.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function SyncEngine() {
|
||||
Engine.call(this);
|
||||
function SyncEngine(name) {
|
||||
Engine.call(this, name || "SyncEngine");
|
||||
this.loadToFetch();
|
||||
}
|
||||
SyncEngine.prototype = {
|
||||
|
@ -92,15 +92,11 @@ function GUIDForId(placeId) {
|
||||
}
|
||||
|
||||
function BookmarksEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "Bookmarks");
|
||||
this._handleImport();
|
||||
}
|
||||
BookmarksEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "bookmarks",
|
||||
_displayName: "Bookmarks",
|
||||
description: "Keep your favorite links always at hand",
|
||||
logName: "Bookmarks",
|
||||
_recordObj: PlacesItem,
|
||||
_storeObj: BookmarksStore,
|
||||
_trackerObj: BookmarksTracker,
|
||||
@ -214,13 +210,11 @@ BookmarksEngine.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function BookmarksStore() {
|
||||
Store.call(this);
|
||||
function BookmarksStore(name) {
|
||||
Store.call(this, name);
|
||||
}
|
||||
BookmarksStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
name: "bookmarks",
|
||||
_logName: "BStore",
|
||||
|
||||
__bms: null,
|
||||
get _bms() {
|
||||
@ -955,8 +949,8 @@ BookmarksStore.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function BookmarksTracker() {
|
||||
Tracker.call(this);
|
||||
function BookmarksTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
|
||||
// Ignore changes to the special roots
|
||||
for (let guid in kSpecialIds)
|
||||
@ -966,9 +960,6 @@ function BookmarksTracker() {
|
||||
}
|
||||
BookmarksTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
name: "bookmarks",
|
||||
_logName: "BmkTracker",
|
||||
file: "bookmarks",
|
||||
|
||||
get _bms() {
|
||||
let bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
|
@ -49,7 +49,7 @@ Cu.import("resource://weave/type_records/clientData.js");
|
||||
Utils.lazy(this, 'Clients', ClientEngine);
|
||||
|
||||
function ClientEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "Clients");
|
||||
|
||||
// Reset the client on every startup so that we fetch recent clients
|
||||
this._resetClient();
|
||||
@ -57,10 +57,6 @@ function ClientEngine() {
|
||||
}
|
||||
ClientEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "clients",
|
||||
_displayName: "Clients",
|
||||
description: "Sync information about other clients connected to Weave Sync",
|
||||
logName: "Clients",
|
||||
_storeObj: ClientStore,
|
||||
_trackerObj: ClientTracker,
|
||||
_recordObj: ClientRecord,
|
||||
@ -172,8 +168,8 @@ ClientEngine.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function ClientStore() {
|
||||
Store.call(this);
|
||||
function ClientStore(name) {
|
||||
Store.call(this, name);
|
||||
}
|
||||
ClientStore.prototype = {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -199,12 +195,6 @@ ClientStore.prototype = {
|
||||
this.clients[id] = info;
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Store.prototype Attributes
|
||||
|
||||
name: "clients",
|
||||
_logName: "Clients.Store",
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Store.prototype Methods
|
||||
|
||||
@ -245,13 +235,10 @@ ClientStore.prototype = {
|
||||
},
|
||||
};
|
||||
|
||||
function ClientTracker() {
|
||||
Tracker.call(this);
|
||||
function ClientTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
}
|
||||
ClientTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
name: "clients",
|
||||
_logName: "ClientTracker",
|
||||
file: "clients",
|
||||
get score() 100 // always sync
|
||||
};
|
||||
|
@ -48,14 +48,10 @@ Cu.import("resource://weave/trackers.js");
|
||||
Cu.import("resource://weave/type_records/forms.js");
|
||||
|
||||
function FormEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "Forms");
|
||||
}
|
||||
FormEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "forms",
|
||||
_displayName: "Forms",
|
||||
description: "Take advantage of form-fill convenience on all your devices",
|
||||
logName: "Forms",
|
||||
_storeObj: FormStore,
|
||||
_trackerObj: FormTracker,
|
||||
_recordObj: FormRec,
|
||||
@ -81,13 +77,11 @@ FormEngine.prototype = {
|
||||
};
|
||||
|
||||
|
||||
function FormStore() {
|
||||
Store.call(this);
|
||||
function FormStore(name) {
|
||||
Store.call(this, name);
|
||||
}
|
||||
FormStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
name: "forms",
|
||||
_logName: "FormStore",
|
||||
_formItems: null,
|
||||
|
||||
get _formDB() {
|
||||
@ -203,15 +197,12 @@ FormStore.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function FormTracker() {
|
||||
Tracker.call(this);
|
||||
function FormTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
Svc.Observer.addObserver(this, "earlyformsubmit", false);
|
||||
}
|
||||
FormTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
name: "forms",
|
||||
_logName: "FormTracker",
|
||||
file: "form",
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver]),
|
||||
|
||||
|
@ -69,14 +69,10 @@ function GUIDForUri(uri, create) {
|
||||
}
|
||||
|
||||
function HistoryEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "History");
|
||||
}
|
||||
HistoryEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "history",
|
||||
_displayName: "History",
|
||||
description: "All the sites you've been to. Take your awesomebar with you!",
|
||||
logName: "History",
|
||||
_recordObj: HistoryRec,
|
||||
_storeObj: HistoryStore,
|
||||
_trackerObj: HistoryTracker,
|
||||
@ -88,13 +84,11 @@ HistoryEngine.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function HistoryStore() {
|
||||
Store.call(this);
|
||||
function HistoryStore(name) {
|
||||
Store.call(this, name);
|
||||
}
|
||||
HistoryStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
name: "history",
|
||||
_logName: "HistStore",
|
||||
|
||||
get _hsvc() {
|
||||
let hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
@ -277,15 +271,12 @@ HistoryStore.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function HistoryTracker() {
|
||||
Tracker.call(this);
|
||||
function HistoryTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
Svc.History.addObserver(this, false);
|
||||
}
|
||||
HistoryTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
name: "history",
|
||||
_logName: "HistoryTracker",
|
||||
file: "history",
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsINavHistoryObserver,
|
||||
|
@ -50,14 +50,10 @@ Cu.import("resource://weave/ext/Observers.js");
|
||||
Cu.import("resource://weave/type_records/passwords.js");
|
||||
|
||||
function PasswordEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "Passwords");
|
||||
}
|
||||
PasswordEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "passwords",
|
||||
_displayName: "Passwords",
|
||||
description: "Forget all your passwords, Weave will remember them for you",
|
||||
logName: "Passwords",
|
||||
_storeObj: PasswordStore,
|
||||
_trackerObj: PasswordTracker,
|
||||
_recordObj: LoginRec,
|
||||
@ -74,15 +70,13 @@ PasswordEngine.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function PasswordStore() {
|
||||
Store.call(this);
|
||||
function PasswordStore(name) {
|
||||
Store.call(this, name);
|
||||
this._nsLoginInfo = new Components.Constructor(
|
||||
"@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init");
|
||||
}
|
||||
PasswordStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
name: "passwords",
|
||||
_logName: "PasswordStore",
|
||||
|
||||
_nsLoginInfoFromRecord: function PasswordStore__nsLoginInfoRec(record) {
|
||||
let info = new this._nsLoginInfo(record.hostname,
|
||||
@ -208,15 +202,12 @@ PasswordStore.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function PasswordTracker() {
|
||||
Tracker.call(this);
|
||||
function PasswordTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
Observers.add("passwordmgr-storage-changed", this);
|
||||
}
|
||||
PasswordTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
_logName: "PasswordTracker",
|
||||
name: "passwords",
|
||||
file: "password",
|
||||
|
||||
/* A single add, remove or change is 15 points, all items removed is 50 */
|
||||
observe: function PasswordTracker_observe(aSubject, aTopic, aData) {
|
||||
|
@ -50,14 +50,10 @@ Cu.import("resource://weave/trackers.js");
|
||||
Cu.import("resource://weave/type_records/prefs.js");
|
||||
|
||||
function PrefsEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "Prefs");
|
||||
}
|
||||
PrefsEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "prefs",
|
||||
_displayName: "Preferences",
|
||||
description: "Synchronize your home page, selected persona, and more",
|
||||
logName: "Prefs",
|
||||
_storeObj: PrefStore,
|
||||
_trackerObj: PrefTracker,
|
||||
_recordObj: PrefRec,
|
||||
@ -78,13 +74,11 @@ PrefsEngine.prototype = {
|
||||
};
|
||||
|
||||
|
||||
function PrefStore() {
|
||||
Store.call(this);
|
||||
function PrefStore(name) {
|
||||
Store.call(this, name);
|
||||
}
|
||||
PrefStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
name: "prefs",
|
||||
_logName: "PrefStore",
|
||||
|
||||
get _prefs() {
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
@ -220,15 +214,12 @@ PrefStore.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function PrefTracker() {
|
||||
Tracker.call(this);
|
||||
function PrefTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
this._prefs.addObserver("", this, false);
|
||||
}
|
||||
PrefTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
name: "prefs",
|
||||
_logName: "PrefTracker",
|
||||
file: "prefs",
|
||||
|
||||
get _prefs() {
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
|
@ -50,17 +50,13 @@ Cu.import("resource://weave/type_records/tabs.js");
|
||||
Cu.import("resource://weave/engines/clientData.js");
|
||||
|
||||
function TabEngine() {
|
||||
SyncEngine.call(this);
|
||||
SyncEngine.call(this, "Tabs");
|
||||
|
||||
// Reset the client on every startup so that we fetch recent tabs
|
||||
this._resetClient();
|
||||
}
|
||||
TabEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
name: "tabs",
|
||||
_displayName: "Tabs",
|
||||
description: "Access tabs from other devices via the History menu",
|
||||
logName: "Tabs",
|
||||
_storeObj: TabStore,
|
||||
_trackerObj: TabTracker,
|
||||
_recordObj: TabSetRecord,
|
||||
@ -101,13 +97,11 @@ TabEngine.prototype = {
|
||||
};
|
||||
|
||||
|
||||
function TabStore() {
|
||||
Store.call(this);
|
||||
function TabStore(name) {
|
||||
Store.call(this, name);
|
||||
}
|
||||
TabStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
name: "tabs",
|
||||
_logName: "Tabs.Store",
|
||||
_remoteClients: {},
|
||||
|
||||
get _sessionStore() {
|
||||
@ -202,8 +196,8 @@ TabStore.prototype = {
|
||||
};
|
||||
|
||||
|
||||
function TabTracker() {
|
||||
Tracker.call(this);
|
||||
function TabTracker(name) {
|
||||
Tracker.call(this, name);
|
||||
|
||||
this.resetChanged();
|
||||
|
||||
@ -220,9 +214,6 @@ function TabTracker() {
|
||||
}
|
||||
TabTracker.prototype = {
|
||||
__proto__: Tracker.prototype,
|
||||
name: "tabs",
|
||||
_logName: "TabTracker",
|
||||
file: "tab_tracker",
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
||||
|
||||
|
@ -50,17 +50,15 @@ Cu.import("resource://weave/util.js");
|
||||
* These can wrap, serialize items and apply commands
|
||||
*/
|
||||
|
||||
function Store() {
|
||||
this._log = Log4Moz.repository.getLogger("Store." + this._logName);
|
||||
function Store(name) {
|
||||
name = name || "Unnamed";
|
||||
this.name = name.toLowerCase();
|
||||
|
||||
this._log = Log4Moz.repository.getLogger("Store." + name);
|
||||
let level = Svc.Prefs.get("log.logger.engine." + this.name, "Debug");
|
||||
this._log.level = Log4Moz.Level[level];
|
||||
}
|
||||
Store.prototype = {
|
||||
_logName: "BaseClass",
|
||||
|
||||
// set this property in child object's wrap()!
|
||||
_lookup: null,
|
||||
|
||||
get cache() {
|
||||
let cache = new Cache();
|
||||
this.__defineGetter__("cache", function() cache);
|
||||
|
@ -57,8 +57,11 @@ Cu.import("resource://weave/ext/Observers.js");
|
||||
* want to sync.
|
||||
*
|
||||
*/
|
||||
function Tracker() {
|
||||
this._log = Log4Moz.repository.getLogger(this._logName);
|
||||
function Tracker(name) {
|
||||
name = name || "Unnamed";
|
||||
this.name = this.file = name.toLowerCase();
|
||||
|
||||
this._log = Log4Moz.repository.getLogger("Tracker." + name);
|
||||
let level = Svc.Prefs.get("log.logger.engine." + this.name, "Debug");
|
||||
this._log.level = Log4Moz.Level[level];
|
||||
|
||||
@ -68,9 +71,6 @@ function Tracker() {
|
||||
this.loadChangedIDs();
|
||||
}
|
||||
Tracker.prototype = {
|
||||
_logName: "Tracker",
|
||||
file: "none",
|
||||
|
||||
/*
|
||||
* Score can be called as often as desired to decide which engines to sync
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user