1 /* -*- Mode: C++; tab-width: 8; 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/. */ 5 6 // Call a method on each observer in a category cache, then call the same 7 // method on the observer array. 8 #define NOTIFY_OBSERVERS(canFire, array, type, method) \ 9 PR_BEGIN_MACRO \ 10 if (canFire) { \ 11 ENUMERATE_WEAKARRAY(array, type, method) \ 12 } \ 13 PR_END_MACRO; 14 15 #define NOTIFY_BOOKMARKS_OBSERVERS(canFire, array, skipIf, method) \ 16 PR_BEGIN_MACRO \ 17 if (canFire) { \ 18 for (uint32_t idx = 0; idx < array.Length(); ++idx) { \ 19 const nsCOMPtr<nsINavBookmarkObserver>& e = \ 20 array.ElementAt(idx).GetValue(); \ 21 if (e) { \ 22 if (skipIf(e)) continue; \ 23 e->method; \ 24 } \ 25 } \ 26 } \ 27 PR_END_MACRO; 28 29 #define PLACES_FACTORY_SINGLETON_IMPLEMENTATION(_className, _sInstance) \ 30 _className* _className::_sInstance = nullptr; \ 31 \ 32 already_AddRefed<_className> _className::GetSingleton() { \ 33 if (_sInstance) { \ 34 RefPtr<_className> ret = _sInstance; \ 35 return ret.forget(); \ 36 } \ 37 _sInstance = new _className(); \ 38 RefPtr<_className> ret = _sInstance; \ 39 if (NS_FAILED(_sInstance->Init())) { \ 40 /* Null out ret before _sInstance so the destructor doesn't assert */ \ 41 ret = nullptr; \ 42 _sInstance = nullptr; \ 43 return nullptr; \ 44 } \ 45 return ret.forget(); \ 46 } 47