2015-03-20 21:01:57 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/cache/StreamControl.h"
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom::cache {
|
2015-03-20 21:01:57 +03:00
|
|
|
|
2020-06-23 16:34:52 +03:00
|
|
|
void StreamControl::AddReadStream(
|
|
|
|
SafeRefPtr<ReadStream::Controllable> aReadStream) {
|
2015-03-20 21:01:57 +03:00
|
|
|
AssertOwningThread();
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aReadStream);
|
2015-03-20 21:01:57 +03:00
|
|
|
MOZ_ASSERT(!mReadStreamList.Contains(aReadStream));
|
2020-06-23 16:34:52 +03:00
|
|
|
mReadStreamList.AppendElement(std::move(aReadStream));
|
2015-03-20 21:01:57 +03:00
|
|
|
}
|
|
|
|
|
2020-06-23 16:34:52 +03:00
|
|
|
void StreamControl::ForgetReadStream(
|
|
|
|
SafeRefPtr<ReadStream::Controllable> aReadStream) {
|
2015-03-20 21:01:57 +03:00
|
|
|
AssertOwningThread();
|
|
|
|
MOZ_ALWAYS_TRUE(mReadStreamList.RemoveElement(aReadStream));
|
|
|
|
}
|
|
|
|
|
2020-06-23 16:34:52 +03:00
|
|
|
void StreamControl::NoteClosed(SafeRefPtr<ReadStream::Controllable> aReadStream,
|
2015-03-20 21:01:57 +03:00
|
|
|
const nsID& aId) {
|
|
|
|
AssertOwningThread();
|
2020-06-23 16:34:52 +03:00
|
|
|
ForgetReadStream(std::move(aReadStream));
|
2015-03-20 21:01:57 +03:00
|
|
|
NoteClosedAfterForget(aId);
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamControl::~StreamControl() {
|
|
|
|
// owning thread only, but can't call virtual AssertOwningThread in destructor
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mReadStreamList.IsEmpty());
|
2015-03-20 21:01:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StreamControl::CloseAllReadStreams() {
|
|
|
|
AssertOwningThread();
|
|
|
|
|
2020-03-05 12:36:39 +03:00
|
|
|
// A copy of mReadStreamList is necessary here for two reasons:
|
|
|
|
// 1. mReadStreamList is modified in StreamControl::ForgetReadStream (called
|
|
|
|
// transitively)
|
|
|
|
// 2. the this pointer is deleted by CacheStreamControlParent::Shutdown
|
|
|
|
// (called transitively)
|
2020-05-07 11:49:15 +03:00
|
|
|
auto readStreamList = mReadStreamList.Clone();
|
2020-06-17 18:04:24 +03:00
|
|
|
for (const auto& stream : readStreamList.ForwardRange()) {
|
|
|
|
stream->CloseStream();
|
2015-03-20 21:01:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StreamControl::CloseAllReadStreamsWithoutReporting() {
|
|
|
|
AssertOwningThread();
|
|
|
|
|
2020-06-17 18:04:24 +03:00
|
|
|
for (const auto& stream : mReadStreamList.ForwardRange()) {
|
2015-03-20 21:01:57 +03:00
|
|
|
// Note, we cannot trigger IPC traffic here. So use
|
|
|
|
// CloseStreamWithoutReporting().
|
2020-06-23 16:34:52 +03:00
|
|
|
stream->CloseStreamWithoutReporting();
|
2015-03-20 21:01:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
bool StreamControl::HasEverBeenRead() const {
|
2020-06-22 11:21:24 +03:00
|
|
|
const auto range = mReadStreamList.NonObservingRange();
|
|
|
|
return std::any_of(range.begin(), range.end(), [](const auto& stream) {
|
|
|
|
return stream->HasEverBeenRead();
|
|
|
|
});
|
2015-04-16 22:00:15 +03:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom::cache
|