From d63e5bbd8a34fd56a117471f41f29afc2a1d8467 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 19 Aug 2020 18:26:33 -0400 Subject: [PATCH] wrapper: Add thread-specific IMPLEMENT_REFCOUNTING variant --- include/wrapper/cef_helpers.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/wrapper/cef_helpers.h b/include/wrapper/cef_helpers.h index 93c4a513e..15489034d 100644 --- a/include/wrapper/cef_helpers.h +++ b/include/wrapper/cef_helpers.h @@ -89,6 +89,32 @@ struct CefDeleteOnIOThread : public CefDeleteOnThread {}; struct CefDeleteOnFileThread : public CefDeleteOnThread {}; struct CefDeleteOnRendererThread : public CefDeleteOnThread {}; +// Same as IMPLEMENT_REFCOUNTING() but using the specified Destructor. +#define IMPLEMENT_REFCOUNTING_EX(ClassName, Destructor) \ + public: \ + void AddRef() const OVERRIDE { ref_count_.AddRef(); } \ + bool Release() const OVERRIDE { \ + if (ref_count_.Release()) { \ + Destructor::Destruct(this); \ + return true; \ + } \ + return false; \ + } \ + bool HasOneRef() const OVERRIDE { return ref_count_.HasOneRef(); } \ + bool HasAtLeastOneRef() const OVERRIDE { \ + return ref_count_.HasAtLeastOneRef(); \ + } \ + \ + private: \ + CefRefCount ref_count_ + +#define IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(ClassName) \ + IMPLEMENT_REFCOUNTING_EX(ClassName, CefDeleteOnUIThread) + +#define IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(ClassName) \ + IMPLEMENT_REFCOUNTING_EX(ClassName, CefDeleteOnIOThread) + + /// // Helper class to manage a scoped copy of |argv|. ///