This source file includes following definitions.
- add
- remove
- remove
- init
- reset
#include "config.h"
#include "WebGeolocationPermissionRequestManager.h"
#include "WebGeolocationPermissionRequest.h"
#include "wtf/HashMap.h"
namespace blink {
using namespace WebCore;
typedef HashMap<Geolocation*, int> GeolocationIdMap;
typedef HashMap<int, Geolocation*> IdGeolocationMap;
class WebGeolocationPermissionRequestManagerPrivate {
public:
GeolocationIdMap m_geolocationIdMap;
IdGeolocationMap m_idGeolocationMap;
};
int WebGeolocationPermissionRequestManager::add(const blink::WebGeolocationPermissionRequest& permissionRequest)
{
Geolocation* geolocation = permissionRequest.geolocation();
ASSERT(!m_private->m_geolocationIdMap.contains(geolocation));
int id = ++m_lastId;
m_private->m_geolocationIdMap.add(geolocation, id);
m_private->m_idGeolocationMap.add(id, geolocation);
return id;
}
bool WebGeolocationPermissionRequestManager::remove(const blink::WebGeolocationPermissionRequest& permissionRequest, int& id)
{
Geolocation* geolocation = permissionRequest.geolocation();
GeolocationIdMap::iterator it = m_private->m_geolocationIdMap.find(geolocation);
if (it == m_private->m_geolocationIdMap.end())
return false;
id = it->value;
m_private->m_geolocationIdMap.remove(it);
m_private->m_idGeolocationMap.remove(id);
return true;
}
bool WebGeolocationPermissionRequestManager::remove(int id, blink::WebGeolocationPermissionRequest& permissionRequest)
{
IdGeolocationMap::iterator it = m_private->m_idGeolocationMap.find(id);
if (it == m_private->m_idGeolocationMap.end())
return false;
Geolocation* geolocation = it->value;
permissionRequest = WebGeolocationPermissionRequest(geolocation);
m_private->m_idGeolocationMap.remove(it);
m_private->m_geolocationIdMap.remove(geolocation);
return true;
}
void WebGeolocationPermissionRequestManager::init()
{
m_lastId = 0;
m_private.reset(new WebGeolocationPermissionRequestManagerPrivate);
}
void WebGeolocationPermissionRequestManager::reset()
{
m_private.reset(0);
}
}