/* vim:set ts=4 sw=2 sts=2 et cin: */ /* 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/. */
// HttpLog.h should generally be included first #include"HttpLog.h"
// Log on level :5, instead of default :4. #undef LOG #define LOG(args) LOG5(args) #undef LOG_ENABLED #define LOG_ENABLED() LOG5_ENABLED()
// This function decides the transaction's order in the pending queue. // Given two transactions t1 and t2, returning true means that t2 is // more important than t1 and thus should be dispatched first. staticbool TransactionComparator(nsHttpTransaction* t1,
nsHttpTransaction* t2) { bool t1Blocking =
t1->Caps() & (NS_HTTP_LOAD_AS_BLOCKING | NS_HTTP_LOAD_UNBLOCKED); bool t2Blocking =
t2->Caps() & (NS_HTTP_LOAD_AS_BLOCKING | NS_HTTP_LOAD_UNBLOCKED);
// XXX At least if a new array was empty before, this isn't efficient, as it // does an insert-sort. It would be better to just append all elements and // then sort.
InsertTransactionSorted(*infoArray, info, aInsertAsFirstForTheSamePriority);
}
void PendingTransactionQueue::InsertTransactionSorted(
nsTArray<RefPtr<PendingTransactionInfo>>& pendingQ,
PendingTransactionInfo* pendingTransInfo, bool aInsertAsFirstForTheSamePriority /*= false*/) { // insert the transaction into the front of the queue based on following // rules: // 1. The transaction has NS_HTTP_LOAD_AS_BLOCKING or NS_HTTP_LOAD_UNBLOCKED. // 2. The transaction's priority is higher. // // search in reverse order under the assumption that many of the // existing transactions will have the same priority (usually 0).
nsHttpTransaction* trans = pendingTransInfo->Transaction();
for (int32_t i = pendingQ.Length() - 1; i >= 0; --i) {
nsHttpTransaction* t = pendingQ[i]->Transaction(); if (TransactionComparator(trans, t)) { if (ChaosMode::isActive(ChaosFeature::NetworkScheduling) ||
aInsertAsFirstForTheSamePriority) {
int32_t samePriorityCount; for (samePriorityCount = 0; i - samePriorityCount >= 0;
++samePriorityCount) { if (pendingQ[i - samePriorityCount]->Transaction()->Priority() !=
trans->Priority()) { break;
}
} if (aInsertAsFirstForTheSamePriority) {
i -= samePriorityCount;
} else { // skip over 0...all of the elements with the same priority.
i -= ChaosMode::randomUint32LessThan(samePriorityCount + 1);
}
}
pendingQ.InsertElementAt(i + 1, pendingTransInfo); return;
}
}
pendingQ.InsertElementAt(0, pendingTransInfo);
}
void PendingTransactionQueue::InsertTransaction(
PendingTransactionInfo* pendingTransInfo, bool aInsertAsFirstForTheSamePriority /* = false */) { if (pendingTransInfo->Transaction()->Caps() & NS_HTTP_URGENT_START) {
LOG(
(" adding transaction to pending queue " "[trans=%p urgent-start-count=%zu]\n",
pendingTransInfo->Transaction(), mUrgentStartQ.Length() + 1)); // put this transaction on the urgent-start queue...
InsertTransactionSorted(mUrgentStartQ, pendingTransInfo);
} else {
LOG(
(" adding transaction to pending queue " "[trans=%p pending-count=%zu]\n",
pendingTransInfo->Transaction(), PendingQueueLength() + 1)); // put this transaction on the pending queue...
InsertTransactionNormal(pendingTransInfo);
}
}
void PendingTransactionQueue::AppendPendingQForNonFocusedWindows(
uint64_t windowId, nsTArray<RefPtr<PendingTransactionInfo>>& result,
uint32_t maxCount) { // XXX Adjust the order of transactions in a smarter manner.
uint32_t totalCount = 0; for (constauto& entry : mPendingTransactionTable) { if (windowId && entry.GetKey() == windowId) { continue;
}
uint32_t count = 0; for (; count < entry.GetWeak()->Length(); ++count) { if (maxCount && totalCount == maxCount) { break;
}
// Because elements in |result| could come from multiple penndingQ, // call |InsertTransactionSorted| to make sure the order is correct.
InsertTransactionSorted(result, entry.GetWeak()->ElementAt(count));
++totalCount;
}
entry.GetWeak()->RemoveElementsAt(0, count);
if (maxCount && totalCount == maxCount) { if (entry.GetWeak()->Length()) { // There are still some pending transactions for background // tabs but we limit their dispatch. This is considered as // an active tab optimization.
nsHttp::NotifyActiveTabLoadOptimization();
} break;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.