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

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

Issue 1855203002: Revert of Improve DEFINE_STATIC_LOCAL()'s handling of Blink GCed objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 ed78f219c6ce391df41adc1752f443337a7eb96e..9dc8f188a53146c13db9049a9729fe72559953d5 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.cpp
+++ b/third_party/WebKit/Source/core/fetch/Resource.cpp
@@ -144,73 +144,6 @@
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)
@@ -676,7 +609,7 @@
// 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;
}
@@ -696,7 +629,7 @@
m_clients.remove(client);
if (m_clientsAwaitingCallback.isEmpty())
- ResourceCallback::callbackHandler().cancel(this);
+ ResourceCallback::callbackHandler()->cancel(this);
didRemoveClientOrObserver();
// This object may be dead here.
@@ -794,9 +727,9 @@
// 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);
@@ -977,6 +910,60 @@
m_resourceRequest.setPriority(loadPriority, intraPriorityValue);
if (m_loader)
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)
« 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