Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / profiler / public / ChildProfilerController.h
blob8febc25b65f2bae9e6052b6eb2428e157d557f3e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef ChildProfilerController_h
7 #define ChildProfilerController_h
9 #include "base/process.h"
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ipc/ProtocolUtils.h"
12 #include "mozilla/DataMutex.h"
13 #include "mozilla/RefPtr.h"
14 #include "nsISupportsImpl.h"
15 #include "nsStringFwd.h"
16 #include "ProfileAdditionalInformation.h"
18 namespace mozilla {
20 class ProfilerChild;
21 class PProfilerChild;
22 class PProfilerParent;
24 // ChildProfilerController manages the setup and teardown of ProfilerChild.
25 // It's used on the main thread.
26 // It manages a background thread that ProfilerChild runs on.
27 class ChildProfilerController final {
28 public:
29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChildProfilerController)
31 #ifdef MOZ_GECKO_PROFILER
32 static already_AddRefed<ChildProfilerController> Create(
33 mozilla::ipc::Endpoint<PProfilerChild>&& aEndpoint);
35 [[nodiscard]] ProfileAndAdditionalInformation
36 GrabShutdownProfileAndShutdown();
37 void Shutdown();
39 private:
40 ChildProfilerController();
41 ~ChildProfilerController();
42 void Init(mozilla::ipc::Endpoint<PProfilerChild>&& aEndpoint);
43 void ShutdownAndMaybeGrabShutdownProfileFirst(
44 ProfileAndAdditionalInformation* aOutShutdownProfileInformation);
46 // Called on mThread:
47 void SetupProfilerChild(mozilla::ipc::Endpoint<PProfilerChild>&& aEndpoint);
48 void ShutdownProfilerChild(
49 ProfileAndAdditionalInformation* aOutShutdownProfileInformation);
51 RefPtr<ProfilerChild> mProfilerChild; // only accessed on mThread
52 DataMutex<RefPtr<nsIThread>> mThread;
53 #else
54 static already_AddRefed<ChildProfilerController> Create(
55 mozilla::ipc::Endpoint<PProfilerChild>&& aEndpoint) {
56 return nullptr;
58 [[nodiscard]] ProfileAndAdditionalInformation
59 GrabShutdownProfileAndShutdown() {
60 return ProfileAndAdditionalInformation(std::move(EmptyCString()));
62 void Shutdown() {}
64 private:
65 ~ChildProfilerController() {}
66 #endif // MOZ_GECKO_PROFILER
69 } // namespace mozilla
71 #endif // ChildProfilerController_h