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"
24 class PBackgroundParent
;
29 class InternalRequest
;
33 class CacheStreamControlParent
;
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
{
49 using BodyAction
= TypeUtils::BodyAction
;
50 using SchemeAction
= TypeUtils::SchemeAction
;
52 AutoChildOpArgs(TypeUtils
* aTypeUtils
, const CacheOpArgs
& aOpArgs
,
53 uint32_t aEntryCount
);
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();
65 TypeUtils
* mTypeUtils
;
70 class MOZ_STACK_CLASS AutoParentOpResult final
{
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();
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
;
98 } // namespace mozilla
100 #endif // mozilla_dom_cache_AutoUtils_h