Services/Sync/Features/Addon Sync: Difference between revisions

Jump to navigation Jump to search
pseudocode work
(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:


foreach record in records:
<pre>
  if record.isDeleted:
foreach record in records:
    found = this.getAddonBySyncGUID(record.syncGUID)
  if record.isDeleted:
    if found:
    found = this.getAddonBySyncGUID(record.syncGUID)
      this.deleteAddon(found)
    if found:
      this.deleteAddon(found)
    # else nothing to do since record not found
      
      
    callbackObj.onSuccess(record)
    callbackObj.onSuccess(record)
    continue
    continue


  existing = this.getExistingAddonBySyncData(record.syncData)
  existing = this.getExistingAddonBySyncData(record.syncData)
  if existing:
  result = null
    existing.merge(record.syncData)
  if existing:
  else:
    result = existing.updateFromSyncData(record.syncData)
    this.installAddonFromSyncData(syncGUID, syncData)
  else:
    result = this.installAddonFromSyncData(syncGUID, syncData)


  // call onSuccess on onFailure depending on result of above
  result ? callbackObj.onSuccess(record) : callbackObj.onFailure(record)


callbackObj.onFinished()
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:
canmove, Confirmed users
409

edits

Navigation menu