DebuggerNotificationManager.cpp (1885B)
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 #include "DebuggerNotificationManager.h" 8 9 #include "nsIGlobalObject.h" 10 11 namespace mozilla::dom { 12 13 NS_IMPL_CYCLE_COLLECTION(DebuggerNotificationManager, mDebuggeeGlobal, 14 mNotificationObservers) 15 16 NS_IMPL_CYCLE_COLLECTING_ADDREF(DebuggerNotificationManager) 17 NS_IMPL_CYCLE_COLLECTING_RELEASE(DebuggerNotificationManager) 18 19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DebuggerNotificationManager) 20 NS_INTERFACE_MAP_ENTRY(nsISupports) 21 NS_INTERFACE_MAP_END 22 23 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DebuggerNotificationManager) 24 NS_IMPL_CYCLE_COLLECTION_TRACE_END 25 26 bool DebuggerNotificationManager::Attach( 27 DebuggerNotificationObserver* aObserver) { 28 RefPtr<DebuggerNotificationObserver> ptr(aObserver); 29 30 if (mNotificationObservers.Contains(ptr)) { 31 return false; 32 } 33 34 mNotificationObservers.AppendElement(ptr); 35 return true; 36 } 37 bool DebuggerNotificationManager::Detach( 38 DebuggerNotificationObserver* aObserver) { 39 RefPtr<DebuggerNotificationObserver> ptr(aObserver); 40 41 return mNotificationObservers.RemoveElement(ptr); 42 } 43 44 bool DebuggerNotificationManager::HasListeners() { 45 const auto [begin, end] = mNotificationObservers.NonObservingRange(); 46 return std::any_of(begin, end, [](const auto& observer) { 47 return observer->HasListeners(); 48 }); 49 } 50 51 void DebuggerNotificationManager::NotifyListeners( 52 DebuggerNotification* aNotification) { 53 for (RefPtr<DebuggerNotificationObserver> observer : 54 mNotificationObservers.ForwardRange()) { 55 observer->NotifyListeners(aNotification); 56 } 57 } 58 59 } // namespace mozilla::dom