tor-browser

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

AltSvcTransactionChild.cpp (2411B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
      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 // HttpLog.h should generally be included first
      7 #include "HttpLog.h"
      8 
      9 #include "AltSvcTransactionChild.h"
     10 #include "AlternateServices.h"
     11 #include "nsHttpConnectionInfo.h"
     12 
     13 namespace mozilla {
     14 namespace net {
     15 
     16 AltSvcTransactionChild::AltSvcTransactionChild(nsHttpConnectionInfo* aConnInfo,
     17                                               uint32_t aCaps)
     18    : mConnInfo(aConnInfo), mCaps(aCaps) {
     19  LOG(("AltSvcTransactionChild %p ctor", this));
     20 }
     21 
     22 AltSvcTransactionChild::~AltSvcTransactionChild() {
     23  LOG(("AltSvcTransactionChild %p dtor", this));
     24 }
     25 
     26 void AltSvcTransactionChild::OnTransactionDestroy(bool aValidateResult) {
     27  LOG(("AltSvcTransactionChild::OnTransactionDestroy %p aValidateResult=%d",
     28       this, aValidateResult));
     29  RefPtr<AltSvcTransactionChild> self = this;
     30  auto task = [self, aValidateResult]() {
     31    if (self->CanSend()) {
     32      self->Send__delete__(self, aValidateResult);
     33    }
     34  };
     35  if (!NS_IsMainThread()) {
     36    NS_DispatchToMainThread(
     37        NS_NewRunnableFunction("AltSvcTransactionChild::OnTransactionClose",
     38                               std::move(task)),
     39        NS_DISPATCH_NORMAL);
     40    return;
     41  }
     42 
     43  task();
     44 }
     45 
     46 void AltSvcTransactionChild::OnTransactionClose(bool aValidateResult) {
     47  LOG(("AltSvcTransactionChild::OnTransactionClose %p aValidateResult=%d", this,
     48       aValidateResult));
     49  RefPtr<AltSvcTransactionChild> self = this;
     50  auto task = [self, aValidateResult]() {
     51    if (self->CanSend()) {
     52      self->SendOnTransactionClose(aValidateResult);
     53    }
     54  };
     55  if (!NS_IsMainThread()) {
     56    NS_DispatchToMainThread(
     57        NS_NewRunnableFunction("AltSvcTransactionChild::OnTransactionClose",
     58                               std::move(task)),
     59        NS_DISPATCH_NORMAL);
     60    return;
     61  }
     62 
     63  task();
     64 }
     65 
     66 already_AddRefed<SpeculativeTransaction>
     67 AltSvcTransactionChild::CreateTransaction() {
     68  RefPtr<SpeculativeTransaction> transaction =
     69      new AltSvcTransaction<AltSvcTransactionChild>(mConnInfo, nullptr, mCaps,
     70                                                    this, mConnInfo->IsHttp3());
     71  return transaction.forget();
     72 }
     73 
     74 }  // namespace net
     75 }  // namespace mozilla