BackgroundChild.h (2465B)
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_ipc_backgroundchild_h__ 8 #define mozilla_ipc_backgroundchild_h__ 9 10 class nsIEventTarget; 11 12 namespace mozilla { 13 namespace dom { 14 15 class BlobImpl; 16 class ContentChild; 17 class ContentParent; 18 class ContentProcess; 19 20 } // namespace dom 21 22 namespace ipc { 23 24 class PBackgroundChild; 25 class PBackgroundStarterChild; 26 27 // This class allows access to the PBackground protocol. PBackground allows 28 // communication between any thread (in the parent or a child process) and a 29 // single background thread in the parent process. Each PBackgroundChild 30 // instance is tied to the thread on which it is created and must not be shared 31 // across threads. Each PBackgroundChild is unique and valid as long as its 32 // designated thread lives. 33 // 34 // Creation of PBackground is synchronous. GetOrCreateForCurrentThread will 35 // create the actor if it doesn't exist yet. Thereafter (assuming success) 36 // GetForCurrentThread() will return the same actor every time. 37 // 38 // CloseForCurrentThread() will close the current PBackground actor. Subsequent 39 // calls to GetForCurrentThread will return null. CloseForCurrentThread() may 40 // only be called exactly once for each thread-specific actor. Currently it is 41 // illegal to call this before the PBackground actor has been created. 42 // 43 // The PBackgroundChild actor and all its sub-protocol actors will be 44 // automatically destroyed when its designated thread completes. 45 // 46 // InitContentStarter must be called on the main thread 47 // with an actor bridging to the relevant target process type before these 48 // methods can be used. 49 class BackgroundChild final { 50 friend class mozilla::dom::ContentParent; 51 friend class mozilla::dom::ContentProcess; 52 53 public: 54 // See above. 55 static PBackgroundChild* GetForCurrentThread(); 56 57 // See above. 58 static PBackgroundChild* GetOrCreateForCurrentThread(); 59 60 // See above. 61 static void CloseForCurrentThread(); 62 63 // See above. 64 static void InitContentStarter(mozilla::dom::ContentChild* aContent); 65 66 private: 67 // Only called by this class's friends. 68 static void Startup(); 69 }; 70 71 } // namespace ipc 72 } // namespace mozilla 73 74 #endif // mozilla_ipc_backgroundchild_h__