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

Unified Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 1850413002: Improve DEFINE_STATIC_LOCAL()'s handling of Blink GCed objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address compilation failure Created 4 years, 8 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 | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/frame/Frame.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9dc8f188a53146c13db9049a9729fe72559953d5..ed78f219c6ce391df41adc1752f443337a7eb96e 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.cpp
+++ b/third_party/WebKit/Source/core/fetch/Resource.cpp
@@ -144,6 +144,73 @@ String Resource::CacheHandler::encoding() const
return m_resource->encoding();
}
+class Resource::ResourceCallback final : public GarbageCollectedFinalized<ResourceCallback> {
+public:
+ static ResourceCallback& callbackHandler();
+ DECLARE_TRACE();
+ void schedule(Resource*);
+ void cancel(Resource*);
+ bool isScheduled(Resource*) const;
+private:
+ ResourceCallback();
+
+ void runTask();
+ OwnPtr<CancellableTaskFactory> m_callbackTaskFactory;
+ HeapHashSet<Member<Resource>> m_resourcesWithPendingClients;
+};
+
+Resource::ResourceCallback& Resource::ResourceCallback::callbackHandler()
+{
+ // Oilpan + LSan: as the callbackHandler() singleton is used by Resource
+ // and ResourcePtr finalizers, it cannot be released upon shutdown in
+ // preparation for leak detection.
+ //
+ // Keep it out of LSan's reach instead.
+ LEAK_SANITIZER_DISABLED_SCOPE;
+ DEFINE_STATIC_LOCAL(ResourceCallback, callbackHandler, (new ResourceCallback));
+ return callbackHandler;
+}
+
+DEFINE_TRACE(Resource::ResourceCallback)
+{
+ visitor->trace(m_resourcesWithPendingClients);
+}
+
+Resource::ResourceCallback::ResourceCallback()
+ : m_callbackTaskFactory(CancellableTaskFactory::create(this, &ResourceCallback::runTask))
+{
+}
+
+void Resource::ResourceCallback::schedule(Resource* resource)
+{
+ if (!m_callbackTaskFactory->isPending())
+ Platform::current()->currentThread()->scheduler()->loadingTaskRunner()->postTask(BLINK_FROM_HERE, m_callbackTaskFactory->cancelAndCreate());
+ m_resourcesWithPendingClients.add(resource);
+}
+
+void Resource::ResourceCallback::cancel(Resource* resource)
+{
+ m_resourcesWithPendingClients.remove(resource);
+ if (m_callbackTaskFactory->isPending() && m_resourcesWithPendingClients.isEmpty())
+ m_callbackTaskFactory->cancel();
+}
+
+bool Resource::ResourceCallback::isScheduled(Resource* resource) const
+{
+ return m_resourcesWithPendingClients.contains(resource);
+}
+
+void Resource::ResourceCallback::runTask()
+{
+ HeapVector<Member<Resource>> resources;
+ for (const Member<Resource>& resource : m_resourcesWithPendingClients)
+ resources.append(resource.get());
+ m_resourcesWithPendingClients.clear();
+
+ for (const auto& resource : resources)
+ resource->finishPendingClients();
+}
+
Resource::Resource(const ResourceRequest& request, Type type, const ResourceLoaderOptions& options)
: m_resourceRequest(request)
, m_options(options)
@@ -609,7 +676,7 @@ void Resource::addClient(ResourceClient* client)
// If we have existing data to send to the new client and the resource type supprts it, send it asynchronously.
if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getType()) && !m_needsSynchronousCacheHit) {
m_clientsAwaitingCallback.add(client);
- ResourceCallback::callbackHandler()->schedule(this);
+ ResourceCallback::callbackHandler().schedule(this);
return;
}
@@ -629,7 +696,7 @@ void Resource::removeClient(ResourceClient* client)
m_clients.remove(client);
if (m_clientsAwaitingCallback.isEmpty())
- ResourceCallback::callbackHandler()->cancel(this);
+ ResourceCallback::callbackHandler().cancel(this);
didRemoveClientOrObserver();
// This object may be dead here.
@@ -727,9 +794,9 @@ void Resource::finishPendingClients()
// It is still possible for the above loop to finish a new client synchronously.
// If there's no client waiting we should deschedule.
- bool scheduled = ResourceCallback::callbackHandler()->isScheduled(this);
+ bool scheduled = ResourceCallback::callbackHandler().isScheduled(this);
if (scheduled && m_clientsAwaitingCallback.isEmpty())
- ResourceCallback::callbackHandler()->cancel(this);
+ ResourceCallback::callbackHandler().cancel(this);
// Prevent the case when there are clients waiting but no callback scheduled.
ASSERT(m_clientsAwaitingCallback.isEmpty() || scheduled);
@@ -912,60 +979,6 @@ void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
m_loader->didChangePriority(loadPriority, intraPriorityValue);
}
-Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler()
-{
- // Oilpan + LSan: as the callbackHandler() singleton is used by Resource
- // and ResourcePtr finalizers, it cannot be released upon shutdown in
- // preparation for leak detection.
- //
- // Keep it out of LSan's reach instead.
- LEAK_SANITIZER_DISABLED_SCOPE;
- DEFINE_STATIC_LOCAL(Persistent<ResourceCallback>, callbackHandler, (new ResourceCallback));
- return callbackHandler.get();
-}
-
-DEFINE_TRACE(Resource::ResourceCallback)
-{
-#if ENABLE(OILPAN)
- visitor->trace(m_resourcesWithPendingClients);
-#endif
-}
-
-Resource::ResourceCallback::ResourceCallback()
- : m_callbackTaskFactory(CancellableTaskFactory::create(this, &ResourceCallback::runTask))
-{
-}
-
-void Resource::ResourceCallback::schedule(Resource* resource)
-{
- if (!m_callbackTaskFactory->isPending())
- Platform::current()->currentThread()->scheduler()->loadingTaskRunner()->postTask(BLINK_FROM_HERE, m_callbackTaskFactory->cancelAndCreate());
- m_resourcesWithPendingClients.add(resource);
-}
-
-void Resource::ResourceCallback::cancel(Resource* resource)
-{
- m_resourcesWithPendingClients.remove(resource);
- if (m_callbackTaskFactory->isPending() && m_resourcesWithPendingClients.isEmpty())
- m_callbackTaskFactory->cancel();
-}
-
-bool Resource::ResourceCallback::isScheduled(Resource* resource) const
-{
- return m_resourcesWithPendingClients.contains(resource);
-}
-
-void Resource::ResourceCallback::runTask()
-{
- HeapVector<Member<Resource>> resources;
- for (const Member<Resource>& resource : m_resourcesWithPendingClients)
- resources.append(resource.get());
- m_resourcesWithPendingClients.clear();
-
- for (const auto& resource : resources)
- resource->finishPendingClients();
-}
-
static const char* initatorTypeNameToString(const AtomicString& initiatorTypeName)
{
if (initiatorTypeName == FetchInitiatorTypeNames::css)
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/frame/Frame.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698