Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: Source/web/WebGeolocationPermissionRequestManager.cpp

Issue 1339353002: Lazily instantiate Geolocation permission manager maps. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | public/web/WebGeolocationPermissionRequestManager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebGeolocationPermissionRequestManager.cpp
diff --git a/Source/web/WebGeolocationPermissionRequestManager.cpp b/Source/web/WebGeolocationPermissionRequestManager.cpp
index 71e8ef2787462699255b5eaeebecff8f15273427..d54e3e7daf5402140dfc32c36251c7ded0939ba3 100644
--- a/Source/web/WebGeolocationPermissionRequestManager.cpp
+++ b/Source/web/WebGeolocationPermissionRequestManager.cpp
@@ -27,16 +27,23 @@
#include "public/web/WebGeolocationPermissionRequestManager.h"
#include "modules/geolocation/Geolocation.h"
+#include "platform/heap/Handle.h"
#include "public/web/WebGeolocationPermissionRequest.h"
#include "wtf/HashMap.h"
namespace blink {
-typedef PersistentHeapHashMap<Member<Geolocation>, int> GeolocationIdMap;
-typedef PersistentHeapHashMap<int, Member<Geolocation>> IdGeolocationMap;
+typedef HeapHashMap<Member<Geolocation>, int> GeolocationIdMap;
+typedef HeapHashMap<int, Member<Geolocation>> IdGeolocationMap;
-class WebGeolocationPermissionRequestManagerPrivate {
+class WebGeolocationPermissionRequestManagerPrivate final : public GarbageCollected<WebGeolocationPermissionRequestManagerPrivate> {
public:
+ DEFINE_INLINE_TRACE()
+ {
+ visitor->trace(m_geolocationIdMap);
+ visitor->trace(m_idGeolocationMap);
+ }
+
GeolocationIdMap m_geolocationIdMap;
IdGeolocationMap m_idGeolocationMap;
};
@@ -44,46 +51,52 @@ public:
int WebGeolocationPermissionRequestManager::add(const WebGeolocationPermissionRequest& permissionRequest)
{
Geolocation* geolocation = permissionRequest.geolocation();
- ASSERT(!m_private->m_geolocationIdMap.contains(geolocation));
+ WebGeolocationPermissionRequestManagerPrivate* manager = ensureManager();
+ ASSERT(!manager->m_geolocationIdMap.contains(geolocation));
static int lastId;
int id = ++lastId;
- m_private->m_geolocationIdMap.add(geolocation, id);
- m_private->m_idGeolocationMap.add(id, geolocation);
+ manager->m_geolocationIdMap.add(geolocation, id);
+ manager->m_idGeolocationMap.add(id, geolocation);
return id;
}
bool WebGeolocationPermissionRequestManager::remove(const WebGeolocationPermissionRequest& permissionRequest, int& id)
{
Geolocation* geolocation = permissionRequest.geolocation();
- GeolocationIdMap::iterator it = m_private->m_geolocationIdMap.find(geolocation);
- if (it == m_private->m_geolocationIdMap.end())
+ WebGeolocationPermissionRequestManagerPrivate* manager = ensureManager();
+ GeolocationIdMap::iterator it = manager->m_geolocationIdMap.find(geolocation);
+ if (it == manager->m_geolocationIdMap.end())
return false;
id = it->value;
- m_private->m_geolocationIdMap.remove(it);
- m_private->m_idGeolocationMap.remove(id);
+ manager->m_geolocationIdMap.remove(it);
+ manager->m_idGeolocationMap.remove(id);
return true;
}
bool WebGeolocationPermissionRequestManager::remove(int id, WebGeolocationPermissionRequest& permissionRequest)
{
- IdGeolocationMap::iterator it = m_private->m_idGeolocationMap.find(id);
- if (it == m_private->m_idGeolocationMap.end())
+ WebGeolocationPermissionRequestManagerPrivate* manager = ensureManager();
+ IdGeolocationMap::iterator it = manager->m_idGeolocationMap.find(id);
+ if (it == manager->m_idGeolocationMap.end())
return false;
Geolocation* geolocation = it->value;
permissionRequest = WebGeolocationPermissionRequest(geolocation);
- m_private->m_idGeolocationMap.remove(it);
- m_private->m_geolocationIdMap.remove(geolocation);
+ manager->m_idGeolocationMap.remove(it);
+ manager->m_geolocationIdMap.remove(geolocation);
return true;
}
-void WebGeolocationPermissionRequestManager::init()
+WebGeolocationPermissionRequestManagerPrivate* WebGeolocationPermissionRequestManager::ensureManager()
{
- m_private.reset(new WebGeolocationPermissionRequestManagerPrivate);
+ if (m_private.isNull())
+ m_private = new WebGeolocationPermissionRequestManagerPrivate;
+
+ return m_private.get();
}
void WebGeolocationPermissionRequestManager::reset()
{
- m_private.reset(0);
+ m_private.reset();
}
} // namespace blink
« no previous file with comments | « no previous file | public/web/WebGeolocationPermissionRequestManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698