1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/nsPlacesMacros.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsIConsoleService.h" 1.10 +#include "nsIScriptError.h" 1.11 + 1.12 +#ifndef __FUNCTION__ 1.13 +#define __FUNCTION__ __func__ 1.14 +#endif 1.15 + 1.16 +// Call a method on each observer in a category cache, then call the same 1.17 +// method on the observer array. 1.18 +#define NOTIFY_OBSERVERS(canFire, cache, array, type, method) \ 1.19 + PR_BEGIN_MACRO \ 1.20 + if (canFire) { \ 1.21 + nsCOMArray<type> entries; \ 1.22 + cache.GetEntries(entries); \ 1.23 + for (int32_t idx = 0; idx < entries.Count(); ++idx) \ 1.24 + entries[idx]->method; \ 1.25 + ENUMERATE_WEAKARRAY(array, type, method) \ 1.26 + } \ 1.27 + PR_END_MACRO; 1.28 + 1.29 +#define PLACES_FACTORY_SINGLETON_IMPLEMENTATION(_className, _sInstance) \ 1.30 + _className * _className::_sInstance = nullptr; \ 1.31 + \ 1.32 + already_AddRefed<_className> \ 1.33 + _className::GetSingleton() \ 1.34 + { \ 1.35 + if (_sInstance) { \ 1.36 + nsRefPtr<_className> ret = _sInstance; \ 1.37 + return ret.forget(); \ 1.38 + } \ 1.39 + _sInstance = new _className(); \ 1.40 + nsRefPtr<_className> ret = _sInstance; \ 1.41 + if (NS_FAILED(_sInstance->Init())) { \ 1.42 + /* Null out ret before _sInstance so the destructor doesn't assert */ \ 1.43 + ret = nullptr; \ 1.44 + _sInstance = nullptr; \ 1.45 + return nullptr; \ 1.46 + } \ 1.47 + return ret.forget(); \ 1.48 + } 1.49 + 1.50 +#define PLACES_WARN_DEPRECATED() \ 1.51 + PR_BEGIN_MACRO \ 1.52 + nsCString msg = NS_LITERAL_CSTRING(__FUNCTION__); \ 1.53 + msg.AppendLiteral(" is deprecated and will be removed in the next version.");\ 1.54 + NS_WARNING(msg.get()); \ 1.55 + nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);\ 1.56 + if (cs) { \ 1.57 + nsCOMPtr<nsIScriptError> e = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID); \ 1.58 + if (e && NS_SUCCEEDED(e->Init(NS_ConvertUTF8toUTF16(msg), EmptyString(), \ 1.59 + EmptyString(), 0, 0, \ 1.60 + nsIScriptError::errorFlag, "Places"))) { \ 1.61 + cs->LogMessage(e); \ 1.62 + } \ 1.63 + } \ 1.64 + PR_END_MACRO