Some ApplicationCache Origin Cleanup
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jul 2011 21:40:40 +0000 (21:40 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jul 2011 21:40:40 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=64431

Reviewed by Alexey Proskuryakov.

2011-07-13  Joseph Pecoraro  <joepeck@webkit.org>

        - m_loadedSize is inaccurate. This just replaces it with
        calls to ApplicationCache::estimatedSizeInStorage.

        - m_availableSpaceInQuota can get out of date, so we just
        recalculate it at the start of appcache downloads.

        * loader/appcache/ApplicationCacheGroup.h:
        * loader/appcache/ApplicationCacheGroup.cpp:
        (WebCore::ApplicationCacheGroup::ApplicationCacheGroup):
        (WebCore::ApplicationCacheGroup::didReceiveData):
        Remove references to m_loadedSize.

        (WebCore::ApplicationCacheGroup::didFinishLoading):
        Replace m_loadedSize with estimatedSizeInStorage after we
        add the new cached resource to the cache. The calculation
        already happened so this check is fast.

        (WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
        When we start the Downloading phase, recalculate the quota
        so that we have an up to date quota value so that we can
        break early if needed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90947 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/loader/appcache/ApplicationCacheGroup.h

index 8f56e7a..bd6de70 100644 (file)
@@ -1,3 +1,32 @@
+2011-07-13  Joseph Pecoraro  <joepeck@webkit.org>
+
+        Some ApplicationCache Origin Cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=64431
+
+        Reviewed by Alexey Proskuryakov.
+
+        - m_loadedSize is inaccurate. This just replaces it with
+        calls to ApplicationCache::estimatedSizeInStorage.
+
+        - m_availableSpaceInQuota can get out of date, so we just
+        recalculate it at the start of appcache downloads.
+
+        * loader/appcache/ApplicationCacheGroup.h:
+        * loader/appcache/ApplicationCacheGroup.cpp:
+        (WebCore::ApplicationCacheGroup::ApplicationCacheGroup):
+        (WebCore::ApplicationCacheGroup::didReceiveData):
+        Remove references to m_loadedSize.
+
+        (WebCore::ApplicationCacheGroup::didFinishLoading):
+        Replace m_loadedSize with estimatedSizeInStorage after we
+        add the new cached resource to the cache. The calculation
+        already happened so this check is fast.
+
+        (WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
+        When we start the Downloading phase, recalculate the quota
+        so that we have an up to date quota value so that we can
+        break early if needed.
+
 2011-07-12  Brent Fulgham  <bfulgham@webkit.org>
 
         Standardize WinCairo conditionalized code under PLATFORM macro.
index 5623562..92d9585 100644 (file)
@@ -70,7 +70,6 @@ ApplicationCacheGroup::ApplicationCacheGroup(const KURL& manifestURL, bool isCop
     , m_completionType(None)
     , m_isCopy(isCopy)
     , m_calledReachedMaxAppCacheSize(false)
-    , m_loadedSize(0)
     , m_availableSpaceInQuota(ApplicationCacheStorage::unknownQuota())
     , m_originQuotaExceededPreviously(false)
 {
@@ -583,8 +582,6 @@ void ApplicationCacheGroup::didReceiveData(ResourceHandle* handle, const char* d
     
     ASSERT(m_currentResource);
     m_currentResource->data()->append(data, length);
-
-    m_loadedSize += length;
 }
 
 void ApplicationCacheGroup::didFinishLoading(ResourceHandle* handle, double finishTime)
@@ -598,34 +595,27 @@ void ApplicationCacheGroup::didFinishLoading(ResourceHandle* handle, double fini
         return;
     }
 
-    // After finishing the loading of any resource, we check if it will
-    // fit in our last known quota limit.
-    // FIXME: The quota could be changed by another appcache in the same origin.
-    if (m_availableSpaceInQuota == ApplicationCacheStorage::unknownQuota())
-        recalculateAvailableSpaceInQuota();
+    ASSERT(m_currentHandle == handle);
+    ASSERT(m_pendingEntries.contains(handle->firstRequest().url()));
+    
+    m_pendingEntries.remove(handle->firstRequest().url());
+    
+    ASSERT(m_cacheBeingUpdated);
+
+    m_cacheBeingUpdated->addResource(m_currentResource.release());
+    m_currentHandle = 0;
 
     // While downloading check to see if we have exceeded the available quota.
     // We can stop immediately if we have already previously failed
     // due to an earlier quota restriction. The client was already notified
     // of the quota being reached and decided not to increase it then.
     // FIXME: Should we break earlier and prevent redownloading on later page loads?
-    // We could then also get rid of m_loadedSize.
-    if (m_originQuotaExceededPreviously && m_availableSpaceInQuota < m_loadedSize) {
+    if (m_originQuotaExceededPreviously && m_availableSpaceInQuota < m_cacheBeingUpdated->estimatedSizeInStorage()) {
         m_currentResource = 0;
         m_frame->domWindow()->console()->addMessage(OtherMessageSource, LogMessageType, ErrorMessageLevel, "Application Cache update failed, because size quota was exceeded.", 0, String());
         cacheUpdateFailed();
         return;
     }
-
-    ASSERT(m_currentHandle == handle);
-    ASSERT(m_pendingEntries.contains(handle->firstRequest().url()));
-    
-    m_pendingEntries.remove(handle->firstRequest().url());
-    
-    ASSERT(m_cacheBeingUpdated);
-
-    m_cacheBeingUpdated->addResource(m_currentResource.release());
-    m_currentHandle = 0;
     
     // Load the next resource, if any.
     startLoadingEntry();
@@ -786,6 +776,8 @@ void ApplicationCacheGroup::didFinishLoadingManifest()
     m_progressTotal = m_pendingEntries.size();
     m_progressDone = 0;
 
+    recalculateAvailableSpaceInQuota();
+
     startLoadingEntry();
 }
 
@@ -983,7 +975,6 @@ void ApplicationCacheGroup::checkIfLoadIsComplete()
     m_completionType = None;
     setUpdateStatus(Idle);
     m_frame = 0;
-    m_loadedSize = 0;
     m_availableSpaceInQuota = ApplicationCacheStorage::unknownQuota();
     m_calledReachedMaxAppCacheSize = false;
 }
index 6b22475..b8eeac4 100644 (file)
@@ -199,7 +199,6 @@ private:
     RefPtr<ApplicationCacheResource> m_manifestResource;
     RefPtr<ResourceHandle> m_manifestHandle;
 
-    int64_t m_loadedSize;
     int64_t m_availableSpaceInQuota;
     bool m_originQuotaExceededPreviously;