StreamControl.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* -*- Mode: C++; tab-width: 8; 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. #include "mozilla/dom/cache/StreamControl.h"
  6. namespace mozilla {
  7. namespace dom {
  8. namespace cache {
  9. void
  10. StreamControl::AddReadStream(ReadStream::Controllable* aReadStream)
  11. {
  12. AssertOwningThread();
  13. MOZ_DIAGNOSTIC_ASSERT(aReadStream);
  14. MOZ_ASSERT(!mReadStreamList.Contains(aReadStream));
  15. mReadStreamList.AppendElement(aReadStream);
  16. }
  17. void
  18. StreamControl::ForgetReadStream(ReadStream::Controllable* aReadStream)
  19. {
  20. AssertOwningThread();
  21. MOZ_ALWAYS_TRUE(mReadStreamList.RemoveElement(aReadStream));
  22. }
  23. void
  24. StreamControl::NoteClosed(ReadStream::Controllable* aReadStream,
  25. const nsID& aId)
  26. {
  27. AssertOwningThread();
  28. ForgetReadStream(aReadStream);
  29. NoteClosedAfterForget(aId);
  30. }
  31. StreamControl::~StreamControl()
  32. {
  33. // owning thread only, but can't call virtual AssertOwningThread in destructor
  34. MOZ_DIAGNOSTIC_ASSERT(mReadStreamList.IsEmpty());
  35. }
  36. void
  37. StreamControl::CloseReadStreams(const nsID& aId)
  38. {
  39. AssertOwningThread();
  40. #if defined(DEBUG) || !defined(RELEASE_OR_BETA)
  41. uint32_t closedCount = 0;
  42. #endif
  43. ReadStreamList::ForwardIterator iter(mReadStreamList);
  44. while (iter.HasMore()) {
  45. RefPtr<ReadStream::Controllable> stream = iter.GetNext();
  46. if (stream->MatchId(aId)) {
  47. stream->CloseStream();
  48. #if defined(DEBUG) || !defined(RELEASE_OR_BETA)
  49. closedCount += 1;
  50. #endif
  51. }
  52. }
  53. MOZ_DIAGNOSTIC_ASSERT(closedCount > 0);
  54. }
  55. void
  56. StreamControl::CloseAllReadStreams()
  57. {
  58. AssertOwningThread();
  59. auto readStreamList = mReadStreamList;
  60. ReadStreamList::ForwardIterator iter(readStreamList);
  61. while (iter.HasMore()) {
  62. iter.GetNext()->CloseStream();
  63. }
  64. }
  65. void
  66. StreamControl::CloseAllReadStreamsWithoutReporting()
  67. {
  68. AssertOwningThread();
  69. ReadStreamList::ForwardIterator iter(mReadStreamList);
  70. while (iter.HasMore()) {
  71. RefPtr<ReadStream::Controllable> stream = iter.GetNext();
  72. // Note, we cannot trigger IPC traffic here. So use
  73. // CloseStreamWithoutReporting().
  74. stream->CloseStreamWithoutReporting();
  75. }
  76. }
  77. bool
  78. StreamControl::HasEverBeenRead() const
  79. {
  80. ReadStreamList::ForwardIterator iter(mReadStreamList);
  81. while (iter.HasMore()) {
  82. if (iter.GetNext()->HasEverBeenRead()) {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. } // namespace cache
  89. } // namespace dom
  90. } // namespace mozilla