Bug 1717887 Part 2: Make RenderThread backed by nsIThread, with a hang monitor. r...
[gecko.git] / layout / base / nsRefreshObservers.cpp
blobd5fbb67444bbdef316018a7e858078d082225180
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 #include "nsRefreshObservers.h"
8 #include "nsPresContext.h"
10 namespace mozilla {
12 ManagedPostRefreshObserver::ManagedPostRefreshObserver(nsPresContext* aPc,
13 Action&& aAction)
14 : mPresContext(aPc), mAction(std::move(aAction)) {}
16 ManagedPostRefreshObserver::ManagedPostRefreshObserver(nsPresContext* aPc)
17 : mPresContext(aPc) {}
19 ManagedPostRefreshObserver::~ManagedPostRefreshObserver() = default;
21 void ManagedPostRefreshObserver::Cancel() {
22 // Caller holds a strong reference, so no need to reference stuff from here.
23 mAction(true);
24 mAction = nullptr;
25 mPresContext = nullptr;
28 void ManagedPostRefreshObserver::DidRefresh() {
29 RefPtr<ManagedPostRefreshObserver> thisObject = this;
31 Unregister unregister = mAction(false);
32 if (unregister == Unregister::Yes) {
33 if (RefPtr<nsPresContext> pc = std::move(mPresContext)) {
34 // In theory mAction could've ended up in `Cancel` being called. In which
35 // case we're already unregistered so no need to do anything.
36 mAction = nullptr;
37 pc->UnregisterManagedPostRefreshObserver(this);
38 } else {
39 MOZ_DIAGNOSTIC_ASSERT(!mAction);
44 } // namespace mozilla