Reviewers: haraken
CL:
https://codereview.chromium.org/2287483003/Description:
Stop ResourceCallback from being an on-heap class
The first ResourceCallback::callbackHandler() call instantiates the
ResourceCallback singleton. As we call it in the pre-finalization
step, it should not be an on-heap class.
BUG=587663
Affected files (+6, -9 lines):
M third_party/WebKit/Source/core/fetch/Resource.cpp
Index: third_party/WebKit/Source/core/fetch/Resource.cpp
diff --git a/third_party/WebKit/Source/core/fetch/Resource.cpp b/third_party/WebKit/Source/core/fetch/Resource.cpp
index 31065b424de1b0d4ae6081c43870045d0a58e1d1..ca35056b36931d066b15d2287ead0f511db42717 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.cpp
+++ b/third_party/WebKit/Source/core/fetch/Resource.cpp
@@ -226,10 +226,12 @@ void Resource::ServiceWorkerResponseCachedMetadataHandler::sendToPlatform()
}
}
-class Resource::ResourceCallback final : public GarbageCollectedFinalized<ResourceCallback> {
+// This class cannot be on-heap because the first callbackHandler() call
+// instantiates the singleton object while we can call it in the
+// pre-finalization step.
+class Resource::ResourceCallback final {
public:
static ResourceCallback& callbackHandler();
- DECLARE_TRACE();
void schedule(Resource*);
void cancel(Resource*);
bool isScheduled(Resource*) const;
@@ -238,7 +240,7 @@ private:
void runTask();
std::unique_ptr<CancellableTaskFactory> m_callbackTaskFactory;
- HeapHashSet<Member<Resource>> m_resourcesWithPendingClients;
+ HashSet<Persistent<Resource>> m_resourcesWithPendingClients;
};
Resource::ResourceCallback& Resource::ResourceCallback::callbackHandler()
@@ -249,15 +251,10 @@ Resource::ResourceCallback& Resource::ResourceCallback::callbackHandler()
//
// Keep it out of LSan's reach instead.
LEAK_SANITIZER_DISABLED_SCOPE;
- DEFINE_STATIC_LOCAL(ResourceCallback, callbackHandler, (new ResourceCallback));
+ DEFINE_STATIC_LOCAL(ResourceCallback, callbackHandler, ());
return callbackHandler;
}
-DEFINE_TRACE(Resource::ResourceCallback)
-{
- visitor->trace(m_resourcesWithPendingClients);
-}
-
Resource::ResourceCallback::ResourceCallback()
: m_callbackTaskFactory(CancellableTaskFactory::create(this, &ResourceCallback::runTask))
{