Move some ApplicationCache static member functions to ApplicationCacheStorage
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2015 17:52:15 +0000 (17:52 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2015 17:52:15 +0000 (17:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143524

Reviewed by Antti Koivisto.

Source/WebCore:

This is yet another step towards eliminating ApplicationCacheStorage::singleton() and making the storage be per page instead.

* loader/appcache/ApplicationCache.cpp:
(WebCore::ApplicationCache::deleteCacheForOrigin):
(WebCore::ApplicationCache::deleteAllCaches):
(WebCore::ApplicationCache::diskUsageForOrigin):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::deleteAllCaches):
(WebCore::ApplicationCacheStorage::deleteCacheForOrigin):
(WebCore::ApplicationCacheStorage::diskUsageForOrigin):
* loader/appcache/ApplicationCacheStorage.h:

Source/WebKit/mac:

* WebCoreSupport/WebApplicationCache.mm:
(+[WebApplicationCache diskUsageForOrigin:]):
(+[WebApplicationCache deleteAllApplicationCaches]):
(+[WebApplicationCache deleteCacheForOrigin:]):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/appcache/ApplicationCache.cpp
Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp
Source/WebCore/loader/appcache/ApplicationCacheStorage.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebApplicationCache.mm

index 5e1717576d4a1724f2683890801c12eaef602065..958b195213046ad3d4b28503b002715456a26ecf 100644 (file)
@@ -1,3 +1,22 @@
+2015-04-08  Anders Carlsson  <andersca@apple.com>
+
+        Move some ApplicationCache static member functions to ApplicationCacheStorage
+        https://bugs.webkit.org/show_bug.cgi?id=143524
+
+        Reviewed by Antti Koivisto.
+
+        This is yet another step towards eliminating ApplicationCacheStorage::singleton() and making the storage be per page instead.
+
+        * loader/appcache/ApplicationCache.cpp:
+        (WebCore::ApplicationCache::deleteCacheForOrigin):
+        (WebCore::ApplicationCache::deleteAllCaches):
+        (WebCore::ApplicationCache::diskUsageForOrigin):
+        * loader/appcache/ApplicationCacheStorage.cpp:
+        (WebCore::ApplicationCacheStorage::deleteAllCaches):
+        (WebCore::ApplicationCacheStorage::deleteCacheForOrigin):
+        (WebCore::ApplicationCacheStorage::diskUsageForOrigin):
+        * loader/appcache/ApplicationCacheStorage.h:
+
 2015-04-08  ChangSeok Oh  <changseok.oh@collabora.com>
 
         Fill list style background with same color with that of list background.
index dc4adcecf4d2dcc6fbf4d44c4cc66032f9e6c6a6..d8af68e1584e474894de835657ac8f44361a22a9 100644 (file)
@@ -192,45 +192,17 @@ void ApplicationCache::clearStorageID()
     
 void ApplicationCache::deleteCacheForOrigin(SecurityOrigin* origin)
 {
-    auto& cacheStorage = ApplicationCacheStorage::singleton();
-
-    Vector<URL> urls;
-    if (!cacheStorage.getManifestURLs(&urls)) {
-        LOG_ERROR("Failed to retrieve ApplicationCache manifest URLs");
-        return;
-    }
-
-    URL originURL(URL(), origin->toString());
-
-    size_t count = urls.size();
-    for (size_t i = 0; i < count; ++i) {
-        if (protocolHostAndPortAreEqual(urls[i], originURL)) {
-            ApplicationCacheGroup* group = cacheStorage.findInMemoryCacheGroup(urls[i]);
-            if (group)
-                group->makeObsolete();
-            else
-                cacheStorage.deleteCacheGroup(urls[i]);
-        }
-    }
+    ApplicationCacheStorage::singleton().deleteCacheForOrigin(*origin);
 }
 
 void ApplicationCache::deleteAllCaches()
 {
-    HashSet<RefPtr<SecurityOrigin>> origins;
-
-    auto& cacheStorage = ApplicationCacheStorage::singleton();
-    cacheStorage.getOriginsWithCache(origins);
-    for (auto& origin : origins)
-        deleteCacheForOrigin(origin.get());
-
-    cacheStorage.vacuumDatabaseFile();
+    ApplicationCacheStorage::singleton().deleteAllCaches();
 }
 
 int64_t ApplicationCache::diskUsageForOrigin(SecurityOrigin* origin)
 {
-    int64_t usage = 0;
-    ApplicationCacheStorage::singleton().calculateUsageForOrigin(origin, usage);
-    return usage;
+    return ApplicationCacheStorage::singleton().diskUsageForOrigin(*origin);
 }
 
 #ifndef NDEBUG
index 635abb67c4fee9aab7003d42c085ed1b0277e96b..c4cf7a616a0f5f124ad2b39da6ba8ece2fbc1100 100644 (file)
@@ -1542,6 +1542,45 @@ void ApplicationCacheStorage::deleteAllEntries()
     vacuumDatabaseFile();
 }
 
+void ApplicationCacheStorage::deleteAllCaches()
+{
+    HashSet<RefPtr<SecurityOrigin>> origins;
+
+    getOriginsWithCache(origins);
+    for (auto& origin : origins)
+        deleteCacheForOrigin(*origin);
+
+    vacuumDatabaseFile();
+}
+
+void ApplicationCacheStorage::deleteCacheForOrigin(const SecurityOrigin& securityOrigin)
+{
+    Vector<URL> urls;
+    if (!getManifestURLs(&urls)) {
+        LOG_ERROR("Failed to retrieve ApplicationCache manifest URLs");
+        return;
+    }
+
+    URL originURL(URL(), securityOrigin.toString());
+
+    for (const auto& url : urls) {
+        if (!protocolHostAndPortAreEqual(url, originURL))
+            continue;
+
+        if (auto* group = findInMemoryCacheGroup(url))
+            group->makeObsolete();
+        else
+            deleteCacheGroup(url);
+    }
+}
+
+int64_t ApplicationCacheStorage::diskUsageForOrigin(const SecurityOrigin& securityOrigin)
+{
+    int64_t usage = 0;
+    calculateUsageForOrigin(&securityOrigin, usage);
+    return usage;
+}
+
 ApplicationCacheStorage::ApplicationCacheStorage()
     : m_maximumSize(ApplicationCacheStorage::noQuota())
     , m_isMaximumSizeReached(false)
index e265b3da3d234778de8c30d11f3b999f15234599..b6607be1a7069de319ad3159583cab01e2ca62d6 100644 (file)
@@ -99,6 +99,15 @@ public:
     WEBCORE_EXPORT void getOriginsWithCache(HashSet<RefPtr<SecurityOrigin>, SecurityOriginHash>&);
     WEBCORE_EXPORT void deleteAllEntries();
 
+    // FIXME: This should be consolidated with deleteAllEntries().
+    WEBCORE_EXPORT void deleteAllCaches();
+
+    // FIXME: This should be consolidated with deleteCacheGroup().
+    WEBCORE_EXPORT void deleteCacheForOrigin(const SecurityOrigin&);
+
+    // FIXME: This should be consolidated with calculateUsageForOrigin().
+    WEBCORE_EXPORT int64_t diskUsageForOrigin(const SecurityOrigin&);
+
     static int64_t unknownQuota() { return -1; }
     static int64_t noQuota() { return std::numeric_limits<int64_t>::max(); }
 private:
index 062a52795a77b48693f72988739bfe24f0f180a3..0052c2344c2e01cb2e6831eb7a43f1a5f6439392 100644 (file)
@@ -1,3 +1,15 @@
+2015-04-08  Anders Carlsson  <andersca@apple.com>
+
+        Move some ApplicationCache static member functions to ApplicationCacheStorage
+        https://bugs.webkit.org/show_bug.cgi?id=143524
+
+        Reviewed by Antti Koivisto.
+
+        * WebCoreSupport/WebApplicationCache.mm:
+        (+[WebApplicationCache diskUsageForOrigin:]):
+        (+[WebApplicationCache deleteAllApplicationCaches]):
+        (+[WebApplicationCache deleteCacheForOrigin:]):
+
 2015-04-08  Chris Dumez  <cdumez@apple.com>
 
         Rename ActiveDOMObject::canSuspend() to canSuspendForPageCache() for clarity
index d17f07dbbd6e3e0b69f42fddd9bb5250208c329b..51ceccbe2899e332d7e49b83f97ca88b2ad84b1e 100644 (file)
@@ -82,17 +82,17 @@ using namespace WebCore;
 
 + (long long)diskUsageForOrigin:(WebSecurityOrigin *)origin
 {
-    return ApplicationCache::diskUsageForOrigin([origin _core]);
+    return webApplicationCacheStorage().diskUsageForOrigin(*[origin _core]);
 }
 
 + (void)deleteAllApplicationCaches
 {
-    ApplicationCache::deleteAllCaches();
+    webApplicationCacheStorage().deleteAllCaches();
 }
 
 + (void)deleteCacheForOrigin:(WebSecurityOrigin *)origin
 {
-    ApplicationCache::deleteCacheForOrigin([origin _core]);
+    webApplicationCacheStorage().deleteCacheForOrigin(*[origin _core]);
 }
 
 + (NSArray *)originsWithCache