canmove, Confirmed users
409
edits
No edit summary |
(rewrite addonmanager api changes) |
||
| Line 30: | Line 30: | ||
For add-on objects, providers wishing to opt in to Sync will expose the following read-only, optional properties: | For add-on objects, providers wishing to opt in to Sync will expose the following read-only, optional properties: | ||
; syncData : a string that describes data necessary to synchronize the add-on between clients. The format of the string | ; syncData : a string that describes data necessary to synchronize the add-on between clients. The format of the string is opaque to Sync code. From the perspective of add-on providers, it should be a JSON object with a *type* field that is used to route it to the proper provider. | ||
; syncGUID : a GUID used to identify this add-on across Sync client instances. The GUID should be generated using Utils.makeGUID() from the Sync code. It is basically a Base64-encoded representation of 9 random bytes. | ; syncGUID : a GUID used to identify this add-on across Sync client instances. The GUID should be generated using Utils.makeGUID() from the Sync code. It is basically a Base64-encoded representation of 9 random bytes. | ||
| Line 40: | Line 40: | ||
; getAddonBySyncGUID(syncGUID, callback) : Obtain an add-on from its Sync GUID. Calls the supplied function when that add-on is retrieved. The callback receives null on unknown add-on or the add-on object (generated from the underlying provider) on success. | ; getAddonBySyncGUID(syncGUID, callback) : Obtain an add-on from its Sync GUID. Calls the supplied function when that add-on is retrieved. The callback receives null on unknown add-on or the add-on object (generated from the underlying provider) on success. | ||
; | ; applySyncDataRecords(records, callbackObj) : This applies an array of records that contain add-on metadata and makes the current state of the world agree with that data as much as possible. | ||
The callbackObj is an object containing the following optional keys: | |||
*onSuccess - Invoked when an individual record is processed successfully. Arguments are the record itself. | |||
*onFailure - Invoked when an individual record could not be processed successfully. Arguments are the record itself. | |||
*onFinished - Invoked when all records have finished processing. | |||
Each record is an object containing the following keys: | |||
* syncGUID (required) - The Sync GUID for this record | |||
* syncData (optional) - The .syncData field from an add-on | |||
* isDeleted (optional) - If evaluates to true, indicates that the record was deleted. Application of this record should involve trying to delete this add-on if present or no-op if not present. | |||
The implementation of applySyncDataRecords() will resemble the following pseudocode: | |||
foreach record in records: | |||
if record.isDeleted: | |||
found = this.getAddonBySyncGUID(record.syncGUID) | |||
if found: | |||
this.deleteAddon(found) | |||
callbackObj.onSuccess(record) | |||
continue | |||
existing = this.getExistingAddonBySyncData(record.syncData) | |||
if existing: | |||
existing.merge(record.syncData) | |||
else: | |||
this.installAddonFromSyncData(syncGUID, syncData) | |||
// call onSuccess on onFailure depending on result of above | |||
callbackObj.onFinished() | |||
The add-ons Sync engine will discover the set of add-ons that can be synced via the following procedure: | The add-ons Sync engine will discover the set of add-ons that can be synced via the following procedure: | ||