summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/http/AltSvcTransactionChild.cpp
blob: 096d584c0e82648abbccbcb3c6f341ad5e895a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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"

#include "AltSvcTransactionChild.h"
#include "AlternateServices.h"
#include "nsHttpConnectionInfo.h"

namespace mozilla {
namespace net {

AltSvcTransactionChild::AltSvcTransactionChild(nsHttpConnectionInfo* aConnInfo,
                                               uint32_t aCaps)
    : mConnInfo(aConnInfo), mCaps(aCaps) {
  LOG(("AltSvcTransactionChild %p ctor", this));
}

AltSvcTransactionChild::~AltSvcTransactionChild() {
  LOG(("AltSvcTransactionChild %p dtor", this));
}

void AltSvcTransactionChild::OnTransactionDestroy(bool aValidateResult) {
  LOG(("AltSvcTransactionChild::OnTransactionDestroy %p aValidateResult=%d",
       this, aValidateResult));
  RefPtr<AltSvcTransactionChild> self = this;
  auto task = [self, aValidateResult]() {
    if (self->CanSend()) {
      self->Send__delete__(self, aValidateResult);
    }
  };
  if (!NS_IsMainThread()) {
    NS_DispatchToMainThread(
        NS_NewRunnableFunction("AltSvcTransactionChild::OnTransactionClose",
                               std::move(task)),
        NS_DISPATCH_NORMAL);
    return;
  }

  task();
}

void AltSvcTransactionChild::OnTransactionClose(bool aValidateResult) {
  LOG(("AltSvcTransactionChild::OnTransactionClose %p aValidateResult=%d", this,
       aValidateResult));
  RefPtr<AltSvcTransactionChild> self = this;
  auto task = [self, aValidateResult]() {
    if (self->CanSend()) {
      self->SendOnTransactionClose(aValidateResult);
    }
  };
  if (!NS_IsMainThread()) {
    NS_DispatchToMainThread(
        NS_NewRunnableFunction("AltSvcTransactionChild::OnTransactionClose",
                               std::move(task)),
        NS_DISPATCH_NORMAL);
    return;
  }

  task();
}

already_AddRefed<SpeculativeTransaction>
AltSvcTransactionChild::CreateTransaction() {
  RefPtr<SpeculativeTransaction> transaction =
      new AltSvcTransaction<AltSvcTransactionChild>(mConnInfo, nullptr, mCaps,
                                                    this, mConnInfo->IsHttp3());
  return transaction.forget();
}

}  // namespace net
}  // namespace mozilla