UniqueContentParentKeepAlive.h (1858B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_UniqueContentParentKeepAlive_h 8 #define mozilla_dom_UniqueContentParentKeepAlive_h 9 10 #include "mozilla/UniquePtr.h" 11 #include "nsIDOMProcessParent.h" 12 13 namespace mozilla::dom { 14 15 class ContentParent; 16 class ThreadsafeContentParentHandle; 17 18 struct ContentParentKeepAliveDeleter { 19 void operator()(ContentParent* const& aProcess); 20 void operator()(ThreadsafeContentParentHandle* const& aHandle); 21 uint64_t mBrowserId = 0; 22 }; 23 24 // Helper for managing a ContentParent combined with the KeepAlive which is 25 // keeping it alive for use by a specific BrowserId. 26 // 27 // This generally should not be created directly, but rather should be created 28 // using `ContentParent::AddKeepAlive`. 29 using UniqueContentParentKeepAlive = 30 UniquePtr<ContentParent, ContentParentKeepAliveDeleter>; 31 32 using UniqueThreadsafeContentParentKeepAlive = 33 UniquePtr<ThreadsafeContentParentHandle, ContentParentKeepAliveDeleter>; 34 35 UniqueContentParentKeepAlive UniqueContentParentKeepAliveFromThreadsafe( 36 UniqueThreadsafeContentParentKeepAlive&& aKeepAlive); 37 UniqueThreadsafeContentParentKeepAlive UniqueContentParentKeepAliveToThreadsafe( 38 UniqueContentParentKeepAlive&& aKeepAlive); 39 40 // Wrap a UniqueContentParentKeepAlive to make it usable from JS. 41 // 42 // Should not be called on a KeepAlive for a still-launching ContentParent. 43 already_AddRefed<nsIContentParentKeepAlive> WrapContentParentKeepAliveForJS( 44 UniqueContentParentKeepAlive&& aKeepAlive); 45 46 } // namespace mozilla::dom 47 48 #endif // mozilla_dom_UniqueContentParentKeepAlive_h