canmove, Confirmed users
409
edits
(rewrite addonmanager api changes) |
(pseudocode work) |
||
| Line 38: | Line 38: | ||
The AddonManager will support the following APIs: | The AddonManager will support the following APIs: | ||
; 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. This API technically isn't required, but it makes the Add-on engine's createRecord(syncGUID) API much simpler. Without it, Sync code would probably query for all add-ons and iterate until it finds a match. By pushing the logic to AddonManager, optimization can be done there, if needed. | ||
; 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. | ; 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. | ||
| Line 56: | Line 56: | ||
The implementation of applySyncDataRecords() will resemble the following pseudocode: | The implementation of applySyncDataRecords() will resemble the following pseudocode: | ||
<pre> | |||
foreach record in records: | |||
if record.isDeleted: | |||
found = this.getAddonBySyncGUID(record.syncGUID) | |||
if found: | |||
this.deleteAddon(found) | |||
# else nothing to do since record not found | |||
callbackObj.onSuccess(record) | |||
continue | |||
existing = this.getExistingAddonBySyncData(record.syncData) | |||
result = null | |||
if existing: | |||
result = existing.updateFromSyncData(record.syncData) | |||
else: | |||
result = this.installAddonFromSyncData(syncGUID, syncData) | |||
result ? callbackObj.onSuccess(record) : callbackObj.onFailure(record) | |||
callbackObj.onFinished() | |||
</pre> | |||
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: | ||