no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / ipc / glue / IdleSchedulerChild.h
blobcf93084bfc6903655760af86fd2c3b637319423e
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/. */
7 #ifndef mozilla_ipc_IdleSchedulerChild_h__
8 #define mozilla_ipc_IdleSchedulerChild_h__
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/ipc/PIdleSchedulerChild.h"
14 class nsIIdlePeriod;
16 namespace mozilla {
17 class IdlePeriodState;
19 namespace ipc {
21 class BackgroundChildImpl;
23 class IdleSchedulerChild final : public PIdleSchedulerChild {
24 public:
25 IdleSchedulerChild() = default;
27 NS_INLINE_DECL_REFCOUNTING(IdleSchedulerChild)
29 IPCResult RecvIdleTime(uint64_t aId, TimeDuration aBudget);
31 void Init(IdlePeriodState* aIdlePeriodState);
33 void Disconnect() { mIdlePeriodState = nullptr; }
35 // See similar methods on PrioritizedEventQueue.
36 void SetActive();
37 // Returns true if activity state dropped below cpu count.
38 bool SetPaused();
40 typedef MozPromise<bool, ResponseRejectReason, true> MayGCPromise;
42 // Returns null if a GC or GC request is already in progress.
43 RefPtr<MayGCPromise> MayGCNow();
45 // Regardless of how a GC is started we get informed via these.
46 void StartedGC();
47 void DoneGC();
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();
53 private:
54 ~IdleSchedulerChild();
56 friend class BackgroundChildImpl;
58 // See IdleScheduleParent::sActiveChildCounter
59 base::SharedMemory mActiveCounter;
61 IdlePeriodState* mIdlePeriodState = nullptr;
63 uint32_t mChildId = 0;
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;
72 } // namespace ipc
73 } // namespace mozilla
75 #endif // mozilla_ipc_IdleSchedulerChild_h__