Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / cache / AutoUtils.h
blob78c4813649fd6c5652016bb034bcad9a8bce1838
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/cache/CacheTypes.h"
12 #include "mozilla/dom/cache/Types.h"
13 #include "mozilla/dom/cache/TypeUtils.h"
14 #include "nsTArray.h"
16 struct nsID;
18 namespace mozilla {
20 class ErrorResult;
22 namespace ipc {
23 class PBackgroundParent;
24 class AutoIPCStream;
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 typedef TypeUtils::BodyAction BodyAction;
50 typedef TypeUtils::SchemeAction SchemeAction;
52 AutoChildOpArgs(TypeUtils* aTypeUtils, const CacheOpArgs& aOpArgs,
53 uint32_t aEntryCount);
54 ~AutoChildOpArgs();
56 void Add(InternalRequest* aRequest, BodyAction aBodyAction,
57 SchemeAction aSchemeAction, ErrorResult& aRv);
58 void Add(JSContext* aCx, InternalRequest* aRequest, BodyAction aBodyAction,
59 SchemeAction aSchemeAction, Response& aResponse, ErrorResult& aRv);
61 const CacheOpArgs& SendAsOpArgs();
63 private:
64 TypeUtils* mTypeUtils;
65 CacheOpArgs mOpArgs;
66 nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>> mStreamCleanupList;
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, 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 nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>> mStreamCleanupList;
94 bool mSent;
97 } // namespace cache
98 } // namespace dom
99 } // namespace mozilla
101 #endif // mozilla_dom_cache_AutoUtils_h