diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /services/cloudsync/CloudSyncAdapters.jsm | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'services/cloudsync/CloudSyncAdapters.jsm')
-rw-r--r-- | services/cloudsync/CloudSyncAdapters.jsm | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/services/cloudsync/CloudSyncAdapters.jsm b/services/cloudsync/CloudSyncAdapters.jsm new file mode 100644 index 000000000..16264a4f7 --- /dev/null +++ b/services/cloudsync/CloudSyncAdapters.jsm @@ -0,0 +1,88 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +this.EXPORTED_SYMBOLS = ["Adapters"]; + +Components.utils.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://gre/modules/CloudSyncEventSource.jsm"); + +this.Adapters = function () { + let eventTypes = [ + "sync", + ]; + + let suspended = true; + + let suspend = function () { + if (!suspended) { + Services.obs.removeObserver(observer, "cloudsync:user-sync", false); + suspended = true; + } + }.bind(this); + + let resume = function () { + if (suspended) { + Services.obs.addObserver(observer, "cloudsync:user-sync", false); + suspended = false; + } + }.bind(this); + + let eventSource = new EventSource(eventTypes, suspend, resume); + let registeredAdapters = new Map(); + + function register (name, opts) { + opts = opts || {}; + registeredAdapters.set(name, opts); + } + + function unregister (name) { + if (!registeredAdapters.has(name)) { + throw new Error("adapter is not registered: " + name) + } + registeredAdapters.delete(name); + } + + function getAdapterNames () { + let result = []; + for (let name of registeredAdapters.keys()) { + result.push(name); + } + return result; + } + + function getAdapter (name) { + if (!registeredAdapters.has(name)) { + throw new Error("adapter is not registered: " + name) + } + return registeredAdapters.get(name); + } + + function countAdapters () { + return registeredAdapters.size; + } + + let observer = { + observe: function (subject, topic, data) { + switch (topic) { + case "cloudsync:user-sync": + eventSource.emit("sync"); + break; + } + } + }; + + this.addEventListener = eventSource.addEventListener; + this.removeEventListener = eventSource.removeEventListener; + this.register = register.bind(this); + this.get = getAdapter.bind(this); + this.unregister = unregister.bind(this); + this.__defineGetter__("names", getAdapterNames); + this.__defineGetter__("count", countAdapters); +}; + +Adapters.prototype = { + +}; |