michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ipc_backgroundparent_h__ michael@0: #define mozilla_ipc_backgroundparent_h__ michael@0: michael@0: #include "base/process.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/ipc/Transport.h" michael@0: michael@0: template class already_AddRefed; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class ContentParent; michael@0: michael@0: } // namespace dom michael@0: michael@0: namespace ipc { michael@0: michael@0: class PBackgroundParent; michael@0: michael@0: // This class is not designed for public consumption beyond the few static michael@0: // member functions. michael@0: class BackgroundParent MOZ_FINAL michael@0: { michael@0: friend class mozilla::dom::ContentParent; michael@0: michael@0: typedef base::ProcessId ProcessId; michael@0: typedef mozilla::dom::ContentParent ContentParent; michael@0: typedef mozilla::ipc::Transport Transport; michael@0: michael@0: public: michael@0: // This function allows the caller to determine if the given parent actor michael@0: // corresponds to a child actor from another process or a child actor from a michael@0: // different thread in the same process. michael@0: // This function may only be called on the background thread. michael@0: static bool michael@0: IsOtherProcessActor(PBackgroundParent* aBackgroundActor); michael@0: michael@0: // This function returns the ContentParent associated with the parent actor if michael@0: // the parent actor corresponds to a child actor from another process. If the michael@0: // parent actor corresponds to a child actor from a different thread in the michael@0: // same process then this function returns null. michael@0: // This function may only be called on the background thread. However, michael@0: // ContentParent is not threadsafe and the returned pointer may not be used on michael@0: // any thread other than the main thread. Callers must take care to use (and michael@0: // release) the returned pointer appropriately. michael@0: static already_AddRefed michael@0: GetContentParent(PBackgroundParent* aBackgroundActor); michael@0: michael@0: private: michael@0: // Only called by ContentParent for cross-process actors. michael@0: static PBackgroundParent* michael@0: Alloc(ContentParent* aContent, michael@0: Transport* aTransport, michael@0: ProcessId aOtherProcess); michael@0: }; michael@0: michael@0: // Implemented in BackgroundImpl.cpp. michael@0: bool michael@0: IsOnBackgroundThread(); michael@0: michael@0: #ifdef DEBUG michael@0: michael@0: // Implemented in BackgroundImpl.cpp. michael@0: void michael@0: AssertIsOnBackgroundThread(); michael@0: michael@0: #else michael@0: michael@0: inline void michael@0: AssertIsOnBackgroundThread() michael@0: { } michael@0: michael@0: #endif // DEBUG michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_ipc_backgroundparent_h__