Bug 1787371 test AudioContext.suspend() with navigation r=padenot
[gecko.git] / dom / cache / AutoUtils.h
blobb24c07a37c9ef06c35070b551f263e4bdc094e15
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/. */
7 #ifndef mozilla_dom_cache_AutoUtils_h
8 #define mozilla_dom_cache_AutoUtils_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/SafeRefPtr.h"
12 #include "mozilla/dom/cache/CacheTypes.h"
13 #include "mozilla/dom/cache/Types.h"
14 #include "mozilla/dom/cache/TypeUtils.h"
15 #include "nsTArray.h"
17 struct nsID;
19 namespace mozilla {
21 class ErrorResult;
23 namespace ipc {
24 class PBackgroundParent;
25 } // namespace ipc
27 namespace dom {
29 class InternalRequest;
31 namespace cache {
33 class CacheStreamControlParent;
34 class Manager;
35 struct SavedRequest;
36 struct SavedResponse;
37 class StreamList;
39 // A collection of RAII-style helper classes to ensure that IPC
40 // FileDescriptorSet actors are properly cleaned up. The user of these actors
41 // must manually either Forget() the Fds or Send__delete__() the actor
42 // depending on if the descriptors were actually sent.
44 // Note, these should only be used when *sending* streams across IPC. The
45 // deserialization case is handled by creating a ReadStream object.
47 class MOZ_STACK_CLASS AutoChildOpArgs final {
48 public:
49 using BodyAction = TypeUtils::BodyAction;
50 using SchemeAction = TypeUtils::SchemeAction;
52 AutoChildOpArgs(TypeUtils* aTypeUtils, const CacheOpArgs& aOpArgs,
53 uint32_t aEntryCount);
54 ~AutoChildOpArgs();
56 void Add(const InternalRequest& aRequest, BodyAction aBodyAction,
57 SchemeAction aSchemeAction, ErrorResult& aRv);
58 void Add(JSContext* aCx, const InternalRequest& aRequest,
59 BodyAction aBodyAction, SchemeAction aSchemeAction,
60 Response& aResponse, ErrorResult& aRv);
62 const CacheOpArgs& SendAsOpArgs();
64 private:
65 TypeUtils* mTypeUtils;
66 CacheOpArgs mOpArgs;
67 bool mSent;
70 class MOZ_STACK_CLASS AutoParentOpResult final {
71 public:
72 AutoParentOpResult(mozilla::ipc::PBackgroundParent* aManager,
73 const CacheOpResult& aOpResult, uint32_t aEntryCount);
74 ~AutoParentOpResult();
76 void Add(CacheId aOpenedCacheId, SafeRefPtr<Manager> aManager);
77 void Add(const SavedResponse& aSavedResponse, StreamList& aStreamList);
78 void Add(const SavedRequest& aSavedRequest, StreamList& aStreamList);
80 const CacheOpResult& SendAsOpResult();
82 private:
83 void SerializeResponseBody(const SavedResponse& aSavedResponse,
84 StreamList& aStreamList,
85 CacheResponse* aResponseOut);
87 void SerializeReadStream(const nsID& aId, StreamList& aStreamList,
88 CacheReadStream* aReadStreamOut);
90 mozilla::ipc::PBackgroundParent* mManager;
91 CacheOpResult mOpResult;
92 CacheStreamControlParent* mStreamControl;
93 bool mSent;
96 } // namespace cache
97 } // namespace dom
98 } // namespace mozilla
100 #endif // mozilla_dom_cache_AutoUtils_h