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_backgroundchild_h__ michael@0: #define mozilla_ipc_backgroundchild_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: class nsIIPCBackgroundChildCreateCallback; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class ContentChild; michael@0: class ContentParent; michael@0: michael@0: } // namespace dom michael@0: michael@0: namespace ipc { michael@0: michael@0: class PBackgroundChild; michael@0: michael@0: // This class allows access to the PBackground protocol. PBackground allows michael@0: // communication between any thread (in the parent or a child process) and a michael@0: // single background thread in the parent process. Each PBackgroundChild michael@0: // instance is tied to the thread on which it is created and must not be shared michael@0: // across threads. Each PBackgroundChild is unique and valid as long as its michael@0: // designated thread lives. michael@0: // michael@0: // Creation of PBackground is asynchronous. GetForCurrentThread() will return michael@0: // null until the sequence is complete. GetOrCreateForCurrentThread() will start michael@0: // the creation sequence and will call back via the michael@0: // nsIIPCBackgroundChildCreateCallback interface when completed. Thereafter michael@0: // (assuming success) GetForCurrentThread() will return the same actor every michael@0: // time. michael@0: // michael@0: // The PBackgroundChild actor and all its sub-protocol actors will be michael@0: // automatically destroyed when its designated thread completes. michael@0: class BackgroundChild MOZ_FINAL michael@0: { michael@0: friend class mozilla::dom::ContentChild; michael@0: friend class mozilla::dom::ContentParent; michael@0: michael@0: typedef base::ProcessId ProcessId; michael@0: typedef mozilla::ipc::Transport Transport; michael@0: michael@0: public: michael@0: // See above. michael@0: static PBackgroundChild* michael@0: GetForCurrentThread(); michael@0: michael@0: // See above. michael@0: static bool michael@0: GetOrCreateForCurrentThread(nsIIPCBackgroundChildCreateCallback* aCallback); michael@0: michael@0: private: michael@0: // Only called by ContentChild or ContentParent. michael@0: static void michael@0: Startup(); michael@0: michael@0: // Only called by ContentChild. michael@0: static PBackgroundChild* michael@0: Alloc(Transport* aTransport, ProcessId aOtherProcess); michael@0: }; michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_ipc_backgroundchild_h__