IdleSchedulerChild.h (2182B)
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_ipc_IdleSchedulerChild_h__ 8 #define mozilla_ipc_IdleSchedulerChild_h__ 9 10 #include "mozilla/RefPtr.h" 11 #include "mozilla/ipc/PIdleSchedulerChild.h" 12 #include "mozilla/ipc/SharedMemoryMapping.h" 13 14 class nsIIdlePeriod; 15 16 namespace mozilla { 17 class IdlePeriodState; 18 19 namespace ipc { 20 21 class BackgroundChildImpl; 22 23 class IdleSchedulerChild final : public PIdleSchedulerChild { 24 public: 25 IdleSchedulerChild() = default; 26 27 NS_INLINE_DECL_REFCOUNTING(IdleSchedulerChild) 28 29 IPCResult RecvIdleTime(uint64_t aId, TimeDuration aBudget); 30 31 void Init(IdlePeriodState* aIdlePeriodState); 32 33 void Disconnect() { mIdlePeriodState = nullptr; } 34 35 // See similar methods on PrioritizedEventQueue. 36 void SetActive(); 37 // Returns true if activity state dropped below cpu count. 38 bool SetPaused(); 39 40 typedef MozPromise<bool, ResponseRejectReason, true> MayGCPromise; 41 42 // Returns null if a GC or GC request is already in progress. 43 RefPtr<MayGCPromise> MayGCNow(); 44 45 // Regardless of how a GC is started we get informed via these. 46 void StartedGC(); 47 void DoneGC(); 48 49 // Returns nullptr if this is the parent process or the IdleSchedulerChild has 50 // already been destroyed, eg if IPC is shutting down. 51 static IdleSchedulerChild* GetMainThreadIdleScheduler(); 52 53 private: 54 ~IdleSchedulerChild(); 55 56 friend class BackgroundChildImpl; 57 58 // See IdleScheduleParent::sActiveChildCounter 59 SharedMemoryMapping mActiveCounter; 60 61 IdlePeriodState* mIdlePeriodState = nullptr; 62 63 uint32_t mChildId = 0; 64 65 // These fields replicate those in IdleSchedulerParent. Tracking them here 66 // ensures we don't send confusing information to the parent, while 67 // nsJSEnvironment is free to tell us about any GCs. 68 bool mIsRequestingGC = false; 69 bool mIsDoingGC = false; 70 }; 71 72 } // namespace ipc 73 } // namespace mozilla 74 75 #endif // mozilla_ipc_IdleSchedulerChild_h__