diff --git a/widget/windows/WinWindowOcclusionTracker.cpp b/widget/windows/WinWindowOcclusionTracker.cpp index 1f6595b45e42..de20ddd9bb5d 100644 --- a/widget/windows/WinWindowOcclusionTracker.cpp +++ b/widget/windows/WinWindowOcclusionTracker.cpp @@ -86,16 +86,16 @@ class OcclusionUpdateRunnable : public CancelableRunnable { class UpdateOcclusionStateRunnable : public Runnable { public: - UpdateOcclusionStateRunnable( - ThreadSafeWeakPtr aOcclusionTracker, - std::unordered_map* aMap, bool aShowAllWindows) + UpdateOcclusionStateRunnable(std::unordered_map* aMap, + bool aShowAllWindows) : Runnable("UpdateOcclusionStateRunnable"), - mOcclusionTracker(aOcclusionTracker), mMap(aMap), mShowAllWindows(aShowAllWindows) {} NS_IMETHOD Run() override { - auto tracker = RefPtr(mOcclusionTracker); + MOZ_ASSERT(NS_IsMainThread()); + + auto* tracker = WinWindowOcclusionTracker::Get(); if (tracker) { tracker->UpdateOcclusionState(mMap, mShowAllWindows); } @@ -103,7 +103,6 @@ class UpdateOcclusionStateRunnable : public Runnable { } private: - ThreadSafeWeakPtr mOcclusionTracker; std::unordered_map* const mMap; const bool mShowAllWindows; }; @@ -334,7 +333,7 @@ already_AddRefed SerializedTaskDispatcher::GetNextTask( StaticRefPtr WinWindowOcclusionTracker::sTracker; /* static */ -RefPtr WinWindowOcclusionTracker::Get() { +WinWindowOcclusionTracker* WinWindowOcclusionTracker::Get() { MOZ_ASSERT(NS_IsMainThread()); return sTracker; } @@ -762,9 +761,8 @@ WinWindowOcclusionTracker::WindowOcclusionCalculator:: MOZ_ASSERT(NS_IsMainThread()); LOG(LogLevel::Info, "WindowOcclusionCalculator()"); - auto tracker = WinWindowOcclusionTracker::Get(); - mSerializedTaskDispatcher = tracker->GetSerializedTaskDispatcher(); - mOcclusionTracker = ThreadSafeWeakPtr(tracker); + mSerializedTaskDispatcher = + WinWindowOcclusionTracker::Get()->GetSerializedTaskDispatcher(); } WinWindowOcclusionTracker::WindowOcclusionCalculator:: @@ -989,7 +987,7 @@ void WinWindowOcclusionTracker::WindowOcclusionCalculator:: } RefPtr runnable = new UpdateOcclusionStateRunnable( - mOcclusionTracker, &mRootWindowHwndsOcclusionState, mShowingThumbnails); + &mRootWindowHwndsOcclusionState, mShowingThumbnails); mSerializedTaskDispatcher->PostTaskToMain(runnable.forget()); } @@ -1205,8 +1203,7 @@ void WinWindowOcclusionTracker::WindowOcclusionCalculator:: mShowingThumbnails = true; RefPtr runnable = new UpdateOcclusionStateRunnable( - mOcclusionTracker, &mRootWindowHwndsOcclusionState, - mShowingThumbnails); + &mRootWindowHwndsOcclusionState, mShowingThumbnails); mSerializedTaskDispatcher->PostTaskToMain(runnable.forget()); } } diff --git a/widget/windows/WinWindowOcclusionTracker.h b/widget/windows/WinWindowOcclusionTracker.h index 37ec5b33b9be..f00b69e8d657 100644 --- a/widget/windows/WinWindowOcclusionTracker.h +++ b/widget/windows/WinWindowOcclusionTracker.h @@ -39,16 +39,13 @@ class UpdateOcclusionStateRunnable; // This class handles window occlusion tracking by using HWND. // Implementation is borrowed from chromium's NativeWindowOcclusionTrackerWin. -class WinWindowOcclusionTracker final - : public SupportsThreadSafeWeakPtr, - public DisplayStatusListener, - public SessionChangeListener { +class WinWindowOcclusionTracker final : public DisplayStatusListener, + public SessionChangeListener { public: - MOZ_DECLARE_THREADSAFEWEAKREFERENCE_TYPENAME(WinWindowOcclusionTracker) - MOZ_DECLARE_REFCOUNTED_TYPENAME(WinWindowOcclusionTracker) + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WinWindowOcclusionTracker) /// Can only be called from the main thread. - static RefPtr Get(); + static WinWindowOcclusionTracker* Get(); /// Can only be called from the main thread. static void Ensure(); @@ -62,8 +59,6 @@ class WinWindowOcclusionTracker final /// Can be called from any thread. static bool IsInWinWindowOcclusionThread(); - virtual ~WinWindowOcclusionTracker(); - // Enables notifying to widget via NotifyOcclusionState() when the occlusion // state has been computed. void Enable(nsBaseWidget* aWindow, HWND aHwnd); @@ -86,6 +81,7 @@ class WinWindowOcclusionTracker final friend class ::WinWindowOcclusionTrackerInteractiveTest; explicit WinWindowOcclusionTracker(base::Thread* aThread); + virtual ~WinWindowOcclusionTracker(); // This class computes the occlusion state of the tracked windows. // It runs on a separate thread, and notifies the main thread of @@ -245,8 +241,6 @@ class WinWindowOcclusionTracker final // Used to serialize tasks related to mRootWindowHwndsOcclusionState. RefPtr mSerializedTaskDispatcher; - ThreadSafeWeakPtr mOcclusionTracker; - friend class OcclusionUpdateRunnable; };