NullHttpTransaction.h (2762B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_net_NullHttpTransaction_h 8 #define mozilla_net_NullHttpTransaction_h 9 10 #include "nsAHttpTransaction.h" 11 #include "TimingStruct.h" 12 13 // This is the minimal nsAHttpTransaction implementation. A NullHttpTransaction 14 // can be used to drive connection level semantics (such as SSL handshakes 15 // tunnels) so that a nsHttpConnection becomes fully established in 16 // anticipation of a real transaction needing to use it soon. 17 18 class nsIHttpActivityObserver; 19 20 namespace mozilla { 21 namespace net { 22 23 class nsAHttpConnection; 24 class nsHttpConnectionInfo; 25 class nsHttpRequestHead; 26 27 // 6c445340-3b82-4345-8efa-4902c3b8805a 28 #define NS_NULLHTTPTRANSACTION_IID \ 29 {0x6c445340, 0x3b82, 0x4345, {0x8e, 0xfa, 0x49, 0x02, 0xc3, 0xb8, 0x80, 0x5a}} 30 31 class NullHttpTransaction : public nsAHttpTransaction { 32 public: 33 NS_INLINE_DECL_STATIC_IID(NS_NULLHTTPTRANSACTION_IID) 34 NS_DECL_THREADSAFE_ISUPPORTS 35 NS_DECL_NSAHTTPTRANSACTION 36 37 NullHttpTransaction(nsHttpConnectionInfo* ci, 38 nsIInterfaceRequestor* callbacks, uint32_t caps); 39 40 [[nodiscard]] bool Claim(); 41 void Unclaim(); 42 43 // Overload of nsAHttpTransaction methods 44 bool IsNullTransaction() final { return true; } 45 NullHttpTransaction* QueryNullTransaction() final { return this; } 46 bool ResponseTimeoutEnabled() const final { return true; } 47 PRIntervalTime ResponseTimeout() final { return PR_SecondsToInterval(15); } 48 49 // We have to override this function because |mTransaction| in 50 // nsHalfOpenSocket could be either nsHttpTransaction or NullHttpTransaction. 51 // NullHttpTransaction will be activated on the connection immediately after 52 // creation and be never put in a pending queue, so it's OK to just return 0. 53 uint64_t BrowserId() override { return 0; } 54 55 TimingStruct Timings() { return mTimings; } 56 57 mozilla::TimeStamp GetTcpConnectEnd() { return mTimings.tcpConnectEnd; } 58 mozilla::TimeStamp GetSecureConnectionStart() { 59 return mTimings.secureConnectionStart; 60 } 61 62 protected: 63 virtual ~NullHttpTransaction(); 64 65 private: 66 nsresult mStatus; 67 68 protected: 69 uint32_t mCaps; 70 nsHttpRequestHead* mRequestHead; 71 72 private: 73 bool mIsDone; 74 bool mClaimed; 75 TimingStruct mTimings; 76 77 protected: 78 RefPtr<nsAHttpConnection> mConnection; 79 nsCOMPtr<nsIInterfaceRequestor> mCallbacks; 80 RefPtr<nsHttpConnectionInfo> mConnectionInfo; 81 nsCOMPtr<nsIHttpActivityObserver> mActivityDistributor; 82 }; 83 84 } // namespace net 85 } // namespace mozilla 86 87 #endif // mozilla_net_NullHttpTransaction_h