1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/glue/nsWeakReference.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsWeakReference_h__ 1.11 +#define nsWeakReference_h__ 1.12 + 1.13 +// nsWeakReference.h 1.14 + 1.15 +// See mfbt/WeakPtr.h for a more typesafe C++ implementation of weak references 1.16 + 1.17 +#include "nsIWeakReferenceUtils.h" 1.18 + 1.19 +class nsWeakReference; 1.20 + 1.21 +// Set IMETHOD_VISIBILITY to empty so that the class-level NS_COM declaration 1.22 +// controls member method visibility. 1.23 +#undef IMETHOD_VISIBILITY 1.24 +#define IMETHOD_VISIBILITY NS_COM_GLUE 1.25 + 1.26 +class NS_COM_GLUE nsSupportsWeakReference : public nsISupportsWeakReference 1.27 + { 1.28 + public: 1.29 + nsSupportsWeakReference() 1.30 + : mProxy(0) 1.31 + { 1.32 + // nothing else to do here 1.33 + } 1.34 + 1.35 + NS_DECL_NSISUPPORTSWEAKREFERENCE 1.36 + 1.37 + protected: 1.38 + inline ~nsSupportsWeakReference(); 1.39 + 1.40 + private: 1.41 + friend class nsWeakReference; 1.42 + 1.43 + void 1.44 + NoticeProxyDestruction() 1.45 + // ...called (only) by an |nsWeakReference| from _its_ dtor. 1.46 + { 1.47 + mProxy = 0; 1.48 + } 1.49 + 1.50 + nsWeakReference* mProxy; 1.51 + 1.52 + protected: 1.53 + 1.54 + void ClearWeakReferences(); 1.55 + bool HasWeakReferences() const {return mProxy != 0;} 1.56 + }; 1.57 + 1.58 +#undef IMETHOD_VISIBILITY 1.59 +#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN 1.60 + 1.61 +inline 1.62 +nsSupportsWeakReference::~nsSupportsWeakReference() 1.63 + { 1.64 + ClearWeakReferences(); 1.65 + } 1.66 + 1.67 +#endif