// Copies a subscription key buffer into an array. nsresult CopySubscriptionKeyToArray(nsIPushSubscription* aSubscription, const nsAString& aKeyName, nsTArray<uint8_t>& aKey) { uint8_t* keyBuffer = nullptr; AutoFreeKeyBuffer autoFree(&keyBuffer); uint32_t keyLen; nsresult rv = aSubscription->GetKey(aKeyName, &keyLen, &keyBuffer); if (NS_FAILED(rv)) { return rv; } if (!aKey.SetCapacity(keyLen, fallible) || !aKey.InsertElementsAt(0, keyBuffer, keyLen, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; }
// This method is a hack to prioritize newly inserted messages, // without changing the size of the queue. It is required since // we cannot sort ranges in nsTArray. nsresult nsAutoSyncState::SortSubQueueBasedOnStrategy(nsTArray<nsMsgKey> &aQueue, uint32_t aStartingOffset) { NS_ASSERTION(aStartingOffset < aQueue.Length(), "*** Starting offset is out of range"); // Copy already downloaded messages into a temporary queue, // we want to exclude them from the sort. nsTArray<nsMsgKey> tmpQ; tmpQ.AppendElements(aQueue.Elements(), aStartingOffset); // Remove already downloaded messages and sort the resulting queue aQueue.RemoveElementsAt(0, aStartingOffset); nsresult rv = SortQueueBasedOnStrategy(aQueue); // copy excluded messages back aQueue.InsertElementsAt(0, tmpQ); return rv; }