tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SpeculativeTransaction.h (2722B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
      2 /* vim:set ts=4 sw=4 sts=4 et cin: */
      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 SpeculativeTransaction_h__
      8 #define SpeculativeTransaction_h__
      9 
     10 #include "mozilla/Maybe.h"
     11 #include "NullHttpTransaction.h"
     12 
     13 namespace mozilla {
     14 namespace net {
     15 
     16 class HTTPSRecordResolver;
     17 
     18 class SpeculativeTransaction : public NullHttpTransaction {
     19 public:
     20  SpeculativeTransaction(nsHttpConnectionInfo* aConnInfo,
     21                         nsIInterfaceRequestor* aCallbacks, uint32_t aCaps,
     22                         std::function<void(bool)>&& aCallback = nullptr);
     23 
     24  already_AddRefed<SpeculativeTransaction> CreateWithNewConnInfo(
     25      nsHttpConnectionInfo* aConnInfo);
     26 
     27  virtual nsresult FetchHTTPSRR() override;
     28 
     29  virtual nsresult OnHTTPSRRAvailable(nsIDNSHTTPSSVCRecord* aHTTPSSVCRecord,
     30                                      nsISVCBRecord* aHighestPriorityRecord,
     31                                      const nsACString& aCname) override;
     32 
     33  void SetParallelSpeculativeConnectLimit(uint32_t aLimit) {
     34    mParallelSpeculativeConnectLimit.emplace(aLimit);
     35  }
     36  void SetIgnoreIdle(bool aIgnoreIdle) { mIgnoreIdle.emplace(aIgnoreIdle); }
     37  void SetAllow1918(bool aAllow1918) { mAllow1918.emplace(aAllow1918); }
     38 
     39  const Maybe<uint32_t>& ParallelSpeculativeConnectLimit() {
     40    return mParallelSpeculativeConnectLimit;
     41  }
     42  const Maybe<bool>& IgnoreIdle() { return mIgnoreIdle; }
     43  const Maybe<bool>& Allow1918() { return mAllow1918; }
     44 
     45  void Close(nsresult aReason) override;
     46  nsresult ReadSegments(nsAHttpSegmentReader* aReader, uint32_t aCount,
     47                        uint32_t* aCountRead) override;
     48  void InvokeCallback() override;
     49 
     50 protected:
     51  virtual ~SpeculativeTransaction();
     52 
     53  Maybe<uint32_t> mParallelSpeculativeConnectLimit;
     54  Maybe<bool> mIgnoreIdle;
     55  Maybe<bool> mAllow1918;
     56 
     57  bool mTriedToWrite = false;
     58  std::function<void(bool)> mCloseCallback;
     59  RefPtr<HTTPSRecordResolver> mResolver;
     60 };
     61 
     62 class FallbackTransaction : public SpeculativeTransaction {
     63 public:
     64  FallbackTransaction(nsHttpConnectionInfo* aConnInfo,
     65                      nsIInterfaceRequestor* aCallbacks, uint32_t aCaps,
     66                      std::function<void(bool)>&& aCallback)
     67      : SpeculativeTransaction(aConnInfo, aCallbacks, aCaps,
     68                               std::move(aCallback)) {}
     69 
     70  bool IsForFallback() override { return true; }
     71 
     72 private:
     73  virtual ~FallbackTransaction() = default;
     74 };
     75 
     76 }  // namespace net
     77 }  // namespace mozilla
     78 
     79 #endif  // SpeculativeTransaction_h__