2012-04-03 03:34:16 +02:00
|
|
|
// 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.
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#ifndef CEF_LIBCEF_COMMON_TRACKER_H_
|
|
|
|
#define CEF_LIBCEF_COMMON_TRACKER_H_
|
2012-04-03 03:34:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
#include "base/synchronization/lock.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_base.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// 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:
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<CefTrackNode> track_next_ = nullptr;
|
|
|
|
raw_ptr<CefTrackNode> track_prev_ = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
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;
|
2017-02-09 23:07:43 +01:00
|
|
|
class CefTrackManager : public CefBaseRefCounted {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
|
|
|
CefTrackManager();
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefTrackManager() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// 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_;
|
2024-01-20 23:48:57 +01:00
|
|
|
int object_count_ = 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
base::Lock lock_;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefTrackManager);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_COMMON_TRACKER_H_
|