Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/http/Http2Push.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 mozilla_net_Http2Push_Internal_h
7
#define mozilla_net_Http2Push_Internal_h
8
9
// HTTP/2 - RFC 7540
10
// https://www.rfc-editor.org/rfc/rfc7540.txt
11
12
#include "Http2Session.h"
13
#include "Http2Stream.h"
14
15
#include "mozilla/Attributes.h"
16
#include "mozilla/TimeStamp.h"
17
#include "mozilla/UniquePtr.h"
18
#include "nsHttpRequestHead.h"
19
#include "nsILoadGroup.h"
20
#include "nsIRequestContext.h"
21
#include "nsString.h"
22
#include "PSpdyPush.h"
23
24
namespace mozilla {
25
namespace net {
26
27
class Http2PushTransactionBuffer;
28
29
class Http2PushedStream final : public Http2Stream
30
{
31
public:
32
  Http2PushedStream(Http2PushTransactionBuffer *aTransaction,
33
                    Http2Session *aSession,
34
                    Http2Stream *aAssociatedStream,
35
                    uint32_t aID,
36
                    uint64_t aCurrentForegroundTabOuterContentWindowId);
37
0
  virtual ~Http2PushedStream() = default;
38
39
  bool GetPushComplete();
40
41
  // The consumer stream is the synthetic pull stream hooked up to this push
42
0
  virtual Http2Stream *GetConsumerStream() override { return mConsumerStream; };
43
44
  void SetConsumerStream(Http2Stream *aStream);
45
  MOZ_MUST_USE bool GetHashKey(nsCString &key);
46
47
  // override of Http2Stream
48
  MOZ_MUST_USE nsresult ReadSegments(nsAHttpSegmentReader *,
49
                                     uint32_t, uint32_t *) override;
50
  MOZ_MUST_USE nsresult WriteSegments(nsAHttpSegmentWriter *,
51
                                      uint32_t, uint32_t *) override;
52
  void AdjustInitialWindow() override;
53
54
0
  nsIRequestContext *RequestContext() override { return mRequestContext; };
55
  void ConnectPushedStream(Http2Stream *consumer);
56
57
  MOZ_MUST_USE bool TryOnPush();
58
  static MOZ_MUST_USE bool TestOnPush(Http2Stream *consumer);
59
60
  virtual bool DeferCleanup(nsresult status) override;
61
0
  void SetDeferCleanupOnSuccess(bool val) { mDeferCleanupOnSuccess = val; }
62
63
  bool IsOrphaned(TimeStamp now);
64
0
  void OnPushFailed() { mDeferCleanupOnPush = false; mOnPushFailed = true; }
65
66
  MOZ_MUST_USE nsresult GetBufferedData(char *buf, uint32_t count,
67
                                        uint32_t *countWritten);
68
69
  // overload of Http2Stream
70
0
  virtual bool HasSink() override { return !!mConsumerStream; }
71
0
  virtual void SetPushComplete() override { mPushCompleted = true; }
72
73
0
  nsCString &GetRequestString() { return mRequestString; }
74
75
private:
76
77
  Http2Stream *mConsumerStream; // paired request stream that consumes from
78
                                // real http/2 one.. null until a match is made.
79
80
  nsCOMPtr<nsIRequestContext> mRequestContext;
81
82
  nsAHttpTransaction *mAssociatedTransaction;
83
84
  Http2PushTransactionBuffer *mBufferedPush;
85
  mozilla::TimeStamp mLastRead;
86
87
  nsCString mHashKey;
88
  nsresult mStatus;
89
  bool mPushCompleted; // server push FIN received
90
  bool mDeferCleanupOnSuccess;
91
92
  // mDeferCleanupOnPush prevents Http2Session::CleanupStream() from
93
  // destroying the push stream on an error code during the period between
94
  // when we need to do OnPush() on another thread and the time it takes
95
  // for that event to create a synthetic pull stream attached to this
96
  // object. That synthetic pull will become mConsuemerStream.
97
  // Ths is essentially a delete protecting reference.
98
  bool mDeferCleanupOnPush;
99
  bool mOnPushFailed;
100
  nsCString mRequestString;
101
102
};
103
104
class Http2PushTransactionBuffer final : public nsAHttpTransaction
105
{
106
public:
107
  NS_DECL_ISUPPORTS
108
  NS_DECL_NSAHTTPTRANSACTION
109
110
  Http2PushTransactionBuffer();
111
112
  MOZ_MUST_USE nsresult GetBufferedData(char *buf, uint32_t count,
113
                                        uint32_t *countWritten);
114
0
  void SetPushStream(Http2PushedStream *stream) { mPushStream = stream; }
115
116
private:
117
  virtual ~Http2PushTransactionBuffer();
118
  uint64_t Available();
119
120
  const static uint32_t kDefaultBufferSize = 4096;
121
122
  nsresult mStatus;
123
  nsHttpRequestHead *mRequestHead;
124
  Http2PushedStream *mPushStream;
125
  bool mIsDone;
126
127
  UniquePtr<char[]> mBufferedHTTP1;
128
  uint32_t mBufferedHTTP1Size;
129
  uint32_t mBufferedHTTP1Used;
130
  uint32_t mBufferedHTTP1Consumed;
131
};
132
133
} // namespace net
134
} // namespace mozilla
135
136
#endif // mozilla_net_Http2Push_Internal_h