AutoUtils.h (3038B)
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/. */ 6 7 #ifndef mozilla_dom_cache_AutoUtils_h 8 #define mozilla_dom_cache_AutoUtils_h 9 10 #include "mozilla/Attributes.h" 11 #include "mozilla/dom/SafeRefPtr.h" 12 #include "mozilla/dom/cache/CacheTypes.h" 13 #include "mozilla/dom/cache/TypeUtils.h" 14 #include "mozilla/dom/cache/Types.h" 15 #include "nsTArray.h" 16 17 struct nsID; 18 19 namespace mozilla { 20 21 class ErrorResult; 22 23 namespace ipc { 24 class PBackgroundParent; 25 } // namespace ipc 26 27 namespace dom { 28 29 class InternalRequest; 30 31 namespace cache { 32 33 class CacheStreamControlParent; 34 class Manager; 35 struct SavedRequest; 36 struct SavedResponse; 37 class StreamList; 38 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. 43 // 44 // Note, these should only be used when *sending* streams across IPC. The 45 // deserialization case is handled by creating a ReadStream object. 46 47 class MOZ_STACK_CLASS AutoChildOpArgs final { 48 public: 49 using BodyAction = TypeUtils::BodyAction; 50 using SchemeAction = TypeUtils::SchemeAction; 51 52 AutoChildOpArgs(TypeUtils* aTypeUtils, const CacheOpArgs& aOpArgs, 53 uint32_t aEntryCount); 54 ~AutoChildOpArgs(); 55 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); 61 62 const CacheOpArgs& SendAsOpArgs(); 63 64 private: 65 TypeUtils* mTypeUtils; 66 CacheOpArgs mOpArgs; 67 bool mSent; 68 }; 69 70 class MOZ_STACK_CLASS AutoParentOpResult final { 71 public: 72 AutoParentOpResult(const WeakRefParentType& aManager, 73 const CacheOpResult& aOpResult, uint32_t aEntryCount); 74 ~AutoParentOpResult(); 75 76 void Add(CacheId aOpenedCacheId, SafeRefPtr<Manager> aManager); 77 void Add(const SavedResponse& aSavedResponse, StreamList& aStreamList); 78 void Add(const SavedRequest& aSavedRequest, StreamList& aStreamList); 79 80 const CacheOpResult& SendAsOpResult(); 81 82 private: 83 void SerializeResponseBody(const SavedResponse& aSavedResponse, 84 StreamList& aStreamList, 85 CacheResponse* aResponseOut); 86 87 void SerializeReadStream(const nsID& aId, StreamList& aStreamList, 88 CacheReadStream* aReadStreamOut); 89 90 const WeakRefParentType mManager; 91 CacheOpResult mOpResult; 92 CacheStreamControlParent* mStreamControl; 93 bool mSent; 94 }; 95 96 } // namespace cache 97 } // namespace dom 98 } // namespace mozilla 99 100 #endif // mozilla_dom_cache_AutoUtils_h