AutoUtils.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifndef mozilla_dom_cache_AutoUtils_h
  6. #define mozilla_dom_cache_AutoUtils_h
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/dom/cache/CacheTypes.h"
  9. #include "mozilla/dom/cache/Types.h"
  10. #include "mozilla/dom/cache/TypeUtils.h"
  11. #include "nsTArray.h"
  12. struct nsID;
  13. namespace mozilla {
  14. class ErrorResult;
  15. namespace ipc {
  16. class PBackgroundParent;
  17. class AutoIPCStream;
  18. } // namespace ipc
  19. namespace dom {
  20. class InternalRequest;
  21. namespace cache {
  22. class CacheStreamControlParent;
  23. class Manager;
  24. struct SavedRequest;
  25. struct SavedResponse;
  26. class StreamList;
  27. // A collection of RAII-style helper classes to ensure that IPC
  28. // FileDescriptorSet actors are properly cleaned up. The user of these actors
  29. // must manually either Forget() the Fds or Send__delete__() the actor
  30. // depending on if the descriptors were actually sent.
  31. //
  32. // Note, these should only be used when *sending* streams across IPC. The
  33. // deserialization case is handled by creating a ReadStream object.
  34. class MOZ_STACK_CLASS AutoChildOpArgs final
  35. {
  36. public:
  37. typedef TypeUtils::BodyAction BodyAction;
  38. typedef TypeUtils::SchemeAction SchemeAction;
  39. AutoChildOpArgs(TypeUtils* aTypeUtils, const CacheOpArgs& aOpArgs,
  40. uint32_t aEntryCount);
  41. ~AutoChildOpArgs();
  42. void Add(InternalRequest* aRequest, BodyAction aBodyAction,
  43. SchemeAction aSchemeAction, ErrorResult& aRv);
  44. void Add(InternalRequest* aRequest, BodyAction aBodyAction,
  45. SchemeAction aSchemeAction, Response& aResponse, ErrorResult& aRv);
  46. const CacheOpArgs& SendAsOpArgs();
  47. private:
  48. TypeUtils* mTypeUtils;
  49. CacheOpArgs mOpArgs;
  50. nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>> mStreamCleanupList;
  51. bool mSent;
  52. };
  53. class MOZ_STACK_CLASS AutoParentOpResult final
  54. {
  55. public:
  56. AutoParentOpResult(mozilla::ipc::PBackgroundParent* aManager,
  57. const CacheOpResult& aOpResult,
  58. uint32_t aEntryCount);
  59. ~AutoParentOpResult();
  60. void Add(CacheId aOpenedCacheId, Manager* aManager);
  61. void Add(const SavedResponse& aSavedResponse, StreamList* aStreamList);
  62. void Add(const SavedRequest& aSavedRequest, StreamList* aStreamList);
  63. const CacheOpResult& SendAsOpResult();
  64. private:
  65. void SerializeResponseBody(const SavedResponse& aSavedResponse,
  66. StreamList* aStreamList,
  67. CacheResponse* aResponseOut);
  68. void SerializeReadStream(const nsID& aId, StreamList* aStreamList,
  69. CacheReadStream* aReadStreamOut);
  70. mozilla::ipc::PBackgroundParent* mManager;
  71. CacheOpResult mOpResult;
  72. CacheStreamControlParent* mStreamControl;
  73. nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>> mStreamCleanupList;
  74. bool mSent;
  75. };
  76. } // namespace cache
  77. } // namespace dom
  78. } // namespace mozilla
  79. #endif // mozilla_dom_cache_AutoUtils_h