Introduce the use of Chromium types (issue #1336).

Changes to the CEF public API:
- Add base::Bind, base::Callback, base::Lock, base::WeakPtr, scoped_refptr, scoped_ptr and supporting types.
- Add include/wrapper/cef_closure_task.h helpers for converting a base::Closure to a CefTask.
- Change CefRefPtr to extend scoped_refptr.
-- Change CefBase method signatures to match RefCountedThreadSafeBase.
- Change IMPLEMENT_REFCOUNTING to use base::AtomicRefCount*.
-- Remove the CefAtomic* functions.
-- IMPLEMENT_REFCOUNTING now enforces via a compile-time error that the correct class name was passed to the macro.
- Change IMPLEMENT_LOCKING to use base::Lock.
-- Remove the CefCriticalSection class.
-- Deprecate the IMPLEMENT_LOCKING macro.
-- base::Lock will DCHECK() in Debug builds if lock usage is reentrant.
- Move include/internal/cef_tuple.h to include/base/cef_tuple.h.
- Allow an empty |callback| parameter passed to CefBeginTracing.

Changes to the CEF implementation:
- Fix incorrect names passed to the IMPLEMENT_REFCOUNTING macro.
- Fix instances of reentrant locking in the CefXmlObject and CefRequest implementations.
- Remove use of the IMPLEMENT_LOCKING macro.

Changes to cef_unittests:
- Add tests/unittests/chromium_includes.h and always include it first from unit test .cc files to avoid name conflicts with Chromium types.
- Fix wrong header include ordering.
- Remove use of the IMPLEMENT_LOCKING macro.

Changes to cefclient and cefsimple:
- Use base::Bind and cef_closure_task.h instead of NewCefRunnable*.
- Remove use of the IMPEMENT_LOCKING macro.
- Fix incorrect/unnecessary locking.
- Add additional runtime thread checks.
- Windows: Perform actions on the UI thread instead of the main thread when running in multi-threaded-message-loop mode to avoid excessive locking.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1769 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2014-07-14 22:18:51 +00:00
parent c260a2d166
commit 122397acfc
314 changed files with 13077 additions and 1242 deletions

View File

@@ -26,24 +26,19 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// The contents of this file must follow a specific format in order to
// support the CEF translator tool. See the translator.README.txt file in the
// tools directory for more information.
//
#ifndef CEF_INCLUDE_CEF_BASE_H_
#define CEF_INCLUDE_CEF_BASE_H_
#pragma once
#include "include/base/cef_atomic_ref_count.h"
#include "include/base/cef_build.h"
#include "include/base/cef_macros.h"
// Bring in common C++ type definitions used by CEF consumers.
#include "include/internal/cef_ptr.h"
#include "include/internal/cef_types_wrappers.h"
// Bring in platform-specific definitions.
#if defined(OS_WIN)
#include "include/internal/cef_win.h"
#elif defined(OS_MACOSX)
@@ -59,59 +54,57 @@
class CefBase {
public:
///
// The AddRef method increments the reference count for the object. It should
// be called for every new copy of a pointer to a given object. The resulting
// reference count value is returned and should be used for diagnostic/testing
// purposes only.
// Called to increment the reference count for the object. Should be called
// for every new copy of a pointer to a given object.
///
virtual int AddRef() =0;
virtual void AddRef() const =0;
///
// The Release method decrements the reference count for the object. If the
// reference count on the object falls to 0, then the object should free
// itself from memory. The resulting reference count value is returned and
// should be used for diagnostic/testing purposes only.
// Called to decrement the reference count for the object. Returns true if
// the reference count is 0, in which case the object should self-delete.
///
virtual int Release() =0;
virtual bool Release() const =0;
///
// Return the current number of references.
// Returns true if the reference count is 1.
///
virtual int GetRefCt() =0;
virtual bool HasOneRef() const =0;
protected:
virtual ~CefBase() {}
};
///
// Class that implements atomic reference counting.
///
class CefRefCount {
public:
CefRefCount() : refct_(0) {}
CefRefCount() : ref_count_(0) {}
///
// Atomic reference increment.
// Increment the reference count.
///
int AddRef() {
return CefAtomicIncrement(&refct_);
void AddRef() const {
base::AtomicRefCountInc(&ref_count_);
}
///
// Atomic reference decrement. Delete the object when no references remain.
// Decrement the reference count. Returns true if the reference count is 0.
///
int Release() {
return CefAtomicDecrement(&refct_);
bool Release() const {
return !base::AtomicRefCountDec(&ref_count_);
}
///
// Return the current number of references.
// Returns true if the reference count is 1.
///
int GetRefCt() { return refct_; }
bool HasOneRef() const {
return base::AtomicRefCountIsOne(&ref_count_);
}
private:
long refct_; // NOLINT(runtime/int)
mutable base::AtomicRefCount ref_count_;
DISALLOW_COPY_AND_ASSIGN(CefRefCount);
};
///
@@ -120,22 +113,54 @@ class CefRefCount {
///
#define IMPLEMENT_REFCOUNTING(ClassName) \
public: \
int AddRef() { return refct_.AddRef(); } \
int Release() { \
int retval = refct_.Release(); \
if (retval == 0) \
delete this; \
return retval; \
void AddRef() const { \
ref_count_.AddRef(); \
} \
bool Release() const { \
if (ref_count_.Release()) { \
delete static_cast<const ClassName*>(this); \
return true; \
} \
return false; \
} \
bool HasOneRef() const { \
return ref_count_.HasOneRef(); \
} \
int GetRefCt() { return refct_.GetRefCt(); } \
private: \
CefRefCount refct_;
CefRefCount ref_count_;
///
// Macro that provides a locking implementation. Use the Lock() and Unlock()
// methods to protect a section of code from simultaneous access by multiple
// threads. The AutoLock class is a helper that will hold the lock while in
// scope.
//
// THIS MACRO IS DEPRECATED. Use an explicit base::Lock member variable and
// base::AutoLock instead. For example:
//
// #include "include/base/cef_lock.h"
//
// // Class declaration.
// class MyClass : public CefBase {
// public:
// MyClass() : value_(0) {}
// // Method that may be called on multiple threads.
// void IncrementValue();
// private:
// // Value that may be accessed on multiple theads.
// int value_;
// // Lock used to protect access to |value_|.
// base::Lock lock_;
// IMPLEMENT_REFCOUNTING(MyClass);
// };
//
// // Class implementation.
// void MyClass::IncrementValue() {
// // Acquire the lock for the scope of this method.
// base::AutoLock lock_scope(lock_);
// // |value_| can now be modified safely.
// value_++;
// }
///
#define IMPLEMENT_LOCKING(ClassName) \
public: \
@@ -145,10 +170,11 @@ class CefRefCount {
~AutoLock() { base_->Unlock(); } \
private: \
ClassName* base_; \
DISALLOW_COPY_AND_ASSIGN(AutoLock); \
}; \
void Lock() { critsec_.Lock(); } \
void Unlock() { critsec_.Unlock(); } \
void Lock() { lock_.Acquire(); } \
void Unlock() { lock_.Release(); } \
private: \
CefCriticalSection critsec_;
base::Lock lock_;
#endif // CEF_INCLUDE_CEF_BASE_H_