PendingTransactionQueue.h (3164B)
1 /* vim:t ts=4 sw=2 sts=2 et cin: */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef PendingTransactionQueue_h__ 7 #define PendingTransactionQueue_h__ 8 9 #include "nsClassHashtable.h" 10 #include "nsHttpTransaction.h" 11 #include "PendingTransactionInfo.h" 12 13 namespace mozilla { 14 namespace net { 15 16 class PendingTransactionQueue { 17 public: 18 PendingTransactionQueue() = default; 19 20 void ReschedTransaction(nsHttpTransaction* aTrans); 21 22 nsTArray<RefPtr<PendingTransactionInfo>>* GetTransactionPendingQHelper( 23 nsAHttpTransaction* trans); 24 25 void InsertTransactionSorted( 26 nsTArray<RefPtr<PendingTransactionInfo>>& pendingQ, 27 PendingTransactionInfo* pendingTransInfo, 28 bool aInsertAsFirstForTheSamePriority = false); 29 30 // Add a transaction information into the pending queue in 31 // |mPendingTransactionTable| according to the transaction's 32 // top level outer content window id. 33 void InsertTransaction(PendingTransactionInfo* pendingTransInfo, 34 bool aInsertAsFirstForTheSamePriority = false); 35 36 void AppendPendingUrgentStartQ( 37 nsTArray<RefPtr<PendingTransactionInfo>>& result); 38 39 // Append transactions to the |result| whose window id 40 // is equal to |windowId|. 41 // NOTE: maxCount == 0 will get all transactions in the queue. 42 void AppendPendingQForFocusedWindow( 43 uint64_t windowId, nsTArray<RefPtr<PendingTransactionInfo>>& result, 44 uint32_t maxCount = 0); 45 46 // Append transactions whose window id isn't equal to |windowId|. 47 // NOTE: windowId == 0 will get all transactions for both 48 // focused and non-focused windows. 49 void AppendPendingQForNonFocusedWindows( 50 uint64_t windowId, nsTArray<RefPtr<PendingTransactionInfo>>& result, 51 uint32_t maxCount = 0); 52 53 // Return the count of pending transactions for all window ids. 54 size_t PendingQueueLength() const; 55 size_t PendingQueueLengthForWindow(uint64_t windowId) const; 56 57 // Remove the empty pendingQ in |mPendingTransactionTable|. 58 void RemoveEmptyPendingQ(); 59 60 void PrintDiagnostics(nsCString& log); 61 62 size_t UrgentStartQueueLength(); 63 64 void PrintPendingQ(); 65 66 void Compact(); 67 68 void CancelAllTransactions(nsresult reason); 69 70 ~PendingTransactionQueue() = default; 71 72 private: 73 void InsertTransactionNormal(PendingTransactionInfo* info, 74 bool aInsertAsFirstForTheSamePriority = false); 75 76 nsTArray<RefPtr<PendingTransactionInfo>> 77 mUrgentStartQ; // the urgent start transaction queue 78 79 // This table provides a mapping from top level outer content window id 80 // to a queue of pending transaction information. 81 // The transaction's order in pending queue is decided by whether it's a 82 // blocking transaction and its priority. 83 // Note that the window id could be 0 if the http request 84 // is initialized without a window. 85 nsClassHashtable<nsUint64HashKey, nsTArray<RefPtr<PendingTransactionInfo>>> 86 mPendingTransactionTable; 87 }; 88 89 } // namespace net 90 } // namespace mozilla 91 92 #endif // !PendingTransactionQueue_h__