Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/cache/StreamControl.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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
#include "mozilla/dom/cache/StreamControl.h"
8
9
namespace mozilla {
10
namespace dom {
11
namespace cache {
12
13
void
14
StreamControl::AddReadStream(ReadStream::Controllable* aReadStream)
15
0
{
16
0
  AssertOwningThread();
17
0
  MOZ_DIAGNOSTIC_ASSERT(aReadStream);
18
0
  MOZ_ASSERT(!mReadStreamList.Contains(aReadStream));
19
0
  mReadStreamList.AppendElement(aReadStream);
20
0
}
21
22
void
23
StreamControl::ForgetReadStream(ReadStream::Controllable* aReadStream)
24
0
{
25
0
  AssertOwningThread();
26
0
  MOZ_ALWAYS_TRUE(mReadStreamList.RemoveElement(aReadStream));
27
0
}
28
29
void
30
StreamControl::NoteClosed(ReadStream::Controllable* aReadStream,
31
                          const nsID& aId)
32
0
{
33
0
  AssertOwningThread();
34
0
  ForgetReadStream(aReadStream);
35
0
  NoteClosedAfterForget(aId);
36
0
}
37
38
StreamControl::~StreamControl()
39
0
{
40
0
  // owning thread only, but can't call virtual AssertOwningThread in destructor
41
0
  MOZ_DIAGNOSTIC_ASSERT(mReadStreamList.IsEmpty());
42
0
}
43
44
void
45
StreamControl::CloseReadStreams(const nsID& aId)
46
0
{
47
0
  AssertOwningThread();
48
0
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
49
0
  uint32_t closedCount = 0;
50
0
#endif
51
0
52
0
  ReadStreamList::ForwardIterator iter(mReadStreamList);
53
0
  while (iter.HasMore()) {
54
0
    RefPtr<ReadStream::Controllable> stream = iter.GetNext();
55
0
    if (stream->MatchId(aId)) {
56
0
      stream->CloseStream();
57
0
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
58
0
      closedCount += 1;
59
0
#endif
60
0
    }
61
0
  }
62
0
63
0
  MOZ_DIAGNOSTIC_ASSERT(closedCount > 0);
64
0
}
65
66
void
67
StreamControl::CloseAllReadStreams()
68
0
{
69
0
  AssertOwningThread();
70
0
71
0
  ReadStreamList::ForwardIterator iter(mReadStreamList);
72
0
  while (iter.HasMore()) {
73
0
    iter.GetNext()->CloseStream();
74
0
  }
75
0
}
76
77
void
78
StreamControl::CloseAllReadStreamsWithoutReporting()
79
0
{
80
0
  AssertOwningThread();
81
0
82
0
  ReadStreamList::ForwardIterator iter(mReadStreamList);
83
0
  while (iter.HasMore()) {
84
0
    RefPtr<ReadStream::Controllable> stream = iter.GetNext();
85
0
    // Note, we cannot trigger IPC traffic here.  So use
86
0
    // CloseStreamWithoutReporting().
87
0
    stream->CloseStreamWithoutReporting();
88
0
  }
89
0
}
90
91
bool
92
StreamControl::HasEverBeenRead() const
93
0
{
94
0
  ReadStreamList::ForwardIterator iter(mReadStreamList);
95
0
  while (iter.HasMore()) {
96
0
    if (iter.GetNext()->HasEverBeenRead()) {
97
0
      return true;
98
0
    }
99
0
  }
100
0
  return false;
101
0
}
102
103
} // namespace cache
104
} // namespace dom
105
} // namespace mozilla