summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/core/fetch/Resource.cpp
diff options
context:
space:
mode:
authorhiroshige <hiroshige@chromium.org>2016-03-25 17:50:09 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-26 00:52:02 +0000
commita4581858f57e20724f9b8a3166ef9c864f79a758 (patch)
treee4cd0359bc77080c16949c5f287f939906bb0aff /third_party/WebKit/Source/core/fetch/Resource.cpp
parenta36877470caa77972faf9a1313eba92d8cd67fde (diff)
downloadchromium_src-a4581858f57e20724f9b8a3166ef9c864f79a758.zip
chromium_src-a4581858f57e20724f9b8a3166ef9c864f79a758.tar.gz
chromium_src-a4581858f57e20724f9b8a3166ef9c864f79a758.tar.bz2
Split ImageResourceClient into ResourceClient and ImageResourceObserver [1/2]
We are planning to move ResourceClient to on-heap, but LayoutObject (an ImageResourceClient subclass) is hard to move to on-heap. This series of CLs splits ImageResourceClient into - ResourceClient (notified via Resource, to be moved to Oilpan heap) and - ImageResourceObserver (notified via ImageObserver, to remain non-heap) and makes LayoutObject to be ImageResourceObserver but not ResourceClient. This is the [1/2] CL that - Splits ImageResourceClient into ResourceClient and ImageResourceObserver, - Makes LayoutObject and all of its subclasses (except for LayoutImage and its subclasses) to be ImageResourceObserver but not ResourceClient. LayoutImage will be made non-ResourceClient by the [2/2] CL: https://codereview.chromium.org/1728313003/. Original CL: https://codereview.chromium.org/1697713002/ by Nate Chapin. In addition to Nate's original CL (Patch Set 1), this CL: - Fixes layout test (Patch Set 2). - Reuses ResourceClientWalker to iterate ImageResourceObserver (Patch Set 3). - Handles ResourceClient and ImageResourceObserver more similarly (Patch Set 4). - Renames methods to reflect whether they are for both ResourceClient and ImageResourceObserver (Patch Set 6). BUG=587663 Review URL: https://codereview.chromium.org/1706083002 Cr-Commit-Position: refs/heads/master@{#383425}
Diffstat (limited to 'third_party/WebKit/Source/core/fetch/Resource.cpp')
-rw-r--r--third_party/WebKit/Source/core/fetch/Resource.cpp48
1 files changed, 21 insertions, 27 deletions
diff --git a/third_party/WebKit/Source/core/fetch/Resource.cpp b/third_party/WebKit/Source/core/fetch/Resource.cpp
index 05d2e40..a311e3f 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.cpp
+++ b/third_party/WebKit/Source/core/fetch/Resource.cpp
@@ -28,7 +28,7 @@
#include "core/fetch/FetchInitiatorTypeNames.h"
#include "core/fetch/MemoryCache.h"
#include "core/fetch/ResourceClient.h"
-#include "core/fetch/ResourceClientWalker.h"
+#include "core/fetch/ResourceClientOrObserverWalker.h"
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ResourceLoader.h"
#include "core/inspector/InspectorInstrumentation.h"
@@ -426,7 +426,7 @@ bool Resource::unlock()
if (!m_data->isLocked())
return true;
- if (!memoryCache()->contains(this) || hasClients() || !m_revalidatingRequest.isNull() || !m_loadFinishTime || !isSafeToUnlock())
+ if (!memoryCache()->contains(this) || hasClientsOrObservers() || !m_revalidatingRequest.isNull() || !m_loadFinishTime || !isSafeToUnlock())
return false;
m_data->unlock();
@@ -506,7 +506,7 @@ WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr()
String Resource::reasonNotDeletable() const
{
StringBuilder builder;
- if (hasClients()) {
+ if (hasClientsOrObservers()) {
builder.append("hasClients(");
builder.appendNumber(m_clients.size());
if (!m_clientsAwaitingCallback.isEmpty()) {
@@ -581,10 +581,9 @@ static bool shouldSendCachedDataSynchronouslyForType(Resource::Type type)
return false;
}
-void Resource::addClient(ResourceClient* client)
+void Resource::willAddClientOrObserver()
{
ASSERT(!isPurgeable());
-
if (m_preloadResult == PreloadNotReferenced) {
if (isLoaded())
m_preloadResult = PreloadReferencedWhileComplete;
@@ -593,8 +592,13 @@ void Resource::addClient(ResourceClient* client)
else
m_preloadResult = PreloadReferenced;
}
- if (!hasClients())
+ if (!hasClientsOrObservers())
memoryCache()->makeLive(this);
+}
+
+void Resource::addClient(ResourceClient* client)
+{
+ willAddClientOrObserver();
if (!m_revalidatingRequest.isNull()) {
m_clients.add(client);
@@ -623,15 +627,19 @@ void Resource::removeClient(ResourceClient* client)
else
m_clients.remove(client);
- didRemoveClient(client);
-
if (m_clientsAwaitingCallback.isEmpty())
ResourceCallback::callbackHandler()->cancel(this);
- if (!hasClients()) {
+ didRemoveClientOrObserver();
+ // This object may be dead here.
+}
+
+void Resource::didRemoveClientOrObserver()
+{
+ if (!hasClientsOrObservers()) {
RefPtrWillBeRawPtr<Resource> protect(this);
memoryCache()->makeDead(this);
- allClientsRemoved();
+ allClientsAndObserversRemoved();
// RFC2616 14.9.2:
// "no-store: ... MUST make a best-effort attempt to remove the information from volatile storage as promptly as possible"
@@ -647,7 +655,7 @@ void Resource::removeClient(ResourceClient* client)
// This object may be dead here.
}
-void Resource::allClientsRemoved()
+void Resource::allClientsAndObserversRemoved()
{
if (!m_loader)
return;
@@ -662,7 +670,7 @@ void Resource::allClientsRemoved()
void Resource::cancelTimerFired(Timer<Resource>* timer)
{
ASSERT_UNUSED(timer, timer == &m_cancelTimer);
- if (hasClients() || !m_loader)
+ if (hasClientsOrObservers() || !m_loader)
return;
RefPtrWillBeRawPtr<Resource> protect(this);
m_loader->cancelIfNotFinishing();
@@ -877,7 +885,7 @@ bool Resource::lock()
if (m_data->isLocked())
return true;
- ASSERT(!hasClients());
+ ASSERT(!hasClientsOrObservers());
// If locking fails, our buffer has been purged. There's no point
// in leaving a purged resource in MemoryCache.
@@ -903,20 +911,6 @@ void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
m_loader->didChangePriority(loadPriority, intraPriorityValue);
}
-ResourcePriority Resource::priorityFromClients()
-{
- ResourcePriority priority;
- ResourceClientWalker<ResourceClient> walker(m_clients);
- while (ResourceClient* c = walker.next()) {
- ResourcePriority nextPriority = c->computeResourcePriority();
- if (nextPriority.visibility == ResourcePriority::NotVisible)
- continue;
- priority.visibility = ResourcePriority::Visible;
- priority.intraPriorityValue += nextPriority.intraPriorityValue;
- }
- return priority;
-}
-
Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler()
{
// Oilpan + LSan: as the callbackHandler() singleton is used by Resource