diff options
author | slightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 05:11:58 +0000 |
---|---|---|
committer | slightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 05:11:58 +0000 |
commit | f781782dd67077478e117c61dca4ea5eefce3544 (patch) | |
tree | 4801f724123cfdcbb69c4e7fe40a565b331723ae /chrome_frame/ns_isupports_impl.h | |
parent | 63cf4759efa2373e33436fb5df6849f930081226 (diff) | |
download | chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.zip chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.gz chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.bz2 |
Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming in a separate CL.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/218019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/ns_isupports_impl.h')
-rw-r--r-- | chrome_frame/ns_isupports_impl.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/chrome_frame/ns_isupports_impl.h b/chrome_frame/ns_isupports_impl.h new file mode 100644 index 0000000..4873163 --- /dev/null +++ b/chrome_frame/ns_isupports_impl.h @@ -0,0 +1,68 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_FRAME_NS_ISUPPORTS_IMPL_H_ +#define CHROME_FRAME_NS_ISUPPORTS_IMPL_H_ + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/platform_thread.h" +#include "chrome_frame/utils.h" +#include "third_party/xulrunner-sdk/win/include/xpcom/nscore.h" +#include "third_party/xulrunner-sdk/win/include/xpcom/nsid.h" +#include "third_party/xulrunner-sdk/win/include/xpcom/nsISupportsBase.h" + +// A simple single-threaded implementation of methods needed to support +// nsISupports. Must be inherited by classes that also inherit from nsISupports. +template<class Derived> +class NsISupportsImplBase { + public: + NsISupportsImplBase() : nsiimpl_ref_count_(0) { + nsiimpl_thread_id_ = PlatformThread::CurrentId(); + } + + virtual ~NsISupportsImplBase() { + DCHECK(nsiimpl_thread_id_ == PlatformThread::CurrentId()); + } + + NS_IMETHOD QueryInterface(REFNSIID iid, void** ptr) { + DCHECK(nsiimpl_thread_id_ == PlatformThread::CurrentId()); + nsresult res = NS_NOINTERFACE; + + if (memcmp(&iid, &__uuidof(nsISupports), sizeof(nsIID)) == 0) { + *ptr = static_cast<nsISupports*>(static_cast<typename Derived*>(this)); + AddRef(); + res = NS_OK; + } + + return res; + } + + NS_IMETHOD_(nsrefcnt) AddRef() { + DCHECK(nsiimpl_thread_id_ == PlatformThread::CurrentId()); + nsiimpl_ref_count_++; + return nsiimpl_ref_count_; + } + + NS_IMETHOD_(nsrefcnt) Release() { + DCHECK(nsiimpl_thread_id_ == PlatformThread::CurrentId()); + nsiimpl_ref_count_--; + + if (!nsiimpl_ref_count_) { + Derived* me = static_cast<Derived*>(this); + delete me; + return 0; + } + + return nsiimpl_ref_count_; + } + + protected: + nsrefcnt nsiimpl_ref_count_; + AddRefModule nsiimpl_module_ref_; + // used to DCHECK on expected single-threaded usage + uint64 nsiimpl_thread_id_; +}; + +#endif // CHROME_FRAME_NS_ISUPPORTS_IMPL_H_ |