#ifndef BW_CEF_BW_HANDLE_MAP
#define BW_CEF_BW_HANDLE_MAP
#include "../browser_window.h"
#include <include/cef_browser.h>
#include <optional>
#include <map>
#include <mutex>
namespace bw {
class BwHandleMap {
std::map<int, bw_BrowserWindow*> map;
std::mutex mutex;
public:
BwHandleMap() {}
void drop( CefRefPtr<CefBrowser> cef_handle ) {
this->mutex.lock();
this->map.erase( cef_handle->GetIdentifier() );
this->mutex.unlock();
}
void store( CefRefPtr<CefBrowser> cef_handle, bw_BrowserWindow* our_handle ) {
this->mutex.lock();
this->map[ cef_handle->GetIdentifier() ] = our_handle;
this->mutex.unlock();
}
std::optional<bw_BrowserWindow*> fetch( CefRefPtr<CefBrowser> cef_handle ) {
this->mutex.lock();
auto it = this->map.find( cef_handle->GetIdentifier() );
if ( it == this->map.end() )
return std::optional<bw_BrowserWindow*>();
std::optional<bw_BrowserWindow*> result( (*it).second );
this->mutex.unlock();
return result;
}
};
extern BwHandleMap bw_handle_map;
}
#endif