cef/libcef/common/tracker.h
Marshall Greenblatt 122397acfc 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
2014-07-14 22:18:51 +00:00

78 lines
2.4 KiB
C++

// Copyright (c) 2012 The Chromium Embedded Framework 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 CEF_LIBCEF_COMMON_TRACKER_H_
#define CEF_LIBCEF_COMMON_TRACKER_H_
#pragma once
#include "include/cef_base.h"
#include "base/synchronization/lock.h"
// Class extended by objects that must be tracked. After creating a tracked
// object you should add it to the appropriate track manager.
class CefTrackNode {
public:
CefTrackNode();
virtual ~CefTrackNode();
// Returns true if the object is currently being tracked.
inline bool IsTracked() { return (track_prev_ || track_next_); }
private:
inline CefTrackNode* GetTrackPrev() { return track_prev_; }
inline void SetTrackPrev(CefTrackNode* base) { track_prev_ = base; }
inline CefTrackNode* GetTrackNext() { return track_next_; }
inline void SetTrackNext(CefTrackNode* base) { track_next_ = base; }
// Insert a new object into the tracking list before this object.
void InsertTrackPrev(CefTrackNode* object);
// Insert a new object into the tracking list after this object.
void InsertTrackNext(CefTrackNode* object);
// Remove this object from the tracking list.
void RemoveTracking();
private:
CefTrackNode* track_next_;
CefTrackNode* track_prev_;
friend class CefTrackManager;
};
// Class used to manage tracked objects. A single instance of this class
// should be created for each intended usage. Any objects that have not been
// removed by explicit calls to the Destroy() method will be removed when the
// manager object is destroyed. A manager object can be created as either a
// member variable of another class or by using lazy initialization:
// base::LazyInstance<CefTrackManager> g_singleton = LAZY_INSTANCE_INITIALIZER;
class CefTrackManager : public CefBase {
public:
CefTrackManager();
virtual ~CefTrackManager();
// Add an object to be tracked by this manager.
void Add(CefTrackNode* object);
// Delete an object tracked by this manager.
bool Delete(CefTrackNode* object);
// Delete all objects tracked by this manager.
void DeleteAll();
// Returns the number of objects currently being tracked.
inline int GetCount() { return object_count_; }
private:
CefTrackNode tracker_;
int object_count_;
base::Lock lock_;
IMPLEMENT_REFCOUNTING(CefTrackManager);
};
#endif // CEF_LIBCEF_COMMON_TRACKER_H_