Refactor so WebsiteDataStores always have a StorageManager.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Apr 2017 22:38:24 +0000 (22:38 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Apr 2017 22:38:24 +0000 (22:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170521

Reviewed by Geoff Garen.

This basically involves teaching StorageManager how to work without a LocalStorageDatabaseTracker,
since there will never be ephemeral bits on disk to track.

* UIProcess/Storage/StorageManager.cpp:
(WebKit::StorageManager::StorageArea::openDatabaseAndImportItemsIfNeeded):
(WebKit::StorageManager::createEphemeral):
(WebKit::StorageManager::StorageManager):
(WebKit::StorageManager::getLocalStorageOrigins):
(WebKit::StorageManager::getLocalStorageOriginDetails):
(WebKit::StorageManager::deleteLocalStorageEntriesForOrigin):
(WebKit::StorageManager::deleteLocalStorageOriginsModifiedSince):
(WebKit::StorageManager::deleteLocalStorageEntriesForOrigins):
* UIProcess/Storage/StorageManager.h:

* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::WebsiteDataStore):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Storage/StorageManager.cpp
Source/WebKit2/UIProcess/Storage/StorageManager.h
Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp

index 98b382e..1023872 100644 (file)
@@ -1,3 +1,27 @@
+2017-04-05  Brady Eidson  <beidson@apple.com>
+
+        Refactor so WebsiteDataStores always have a StorageManager.
+        https://bugs.webkit.org/show_bug.cgi?id=170521
+
+        Reviewed by Geoff Garen.
+
+        This basically involves teaching StorageManager how to work without a LocalStorageDatabaseTracker,
+        since there will never be ephemeral bits on disk to track.
+        
+        * UIProcess/Storage/StorageManager.cpp:
+        (WebKit::StorageManager::StorageArea::openDatabaseAndImportItemsIfNeeded):
+        (WebKit::StorageManager::createEphemeral):
+        (WebKit::StorageManager::StorageManager):
+        (WebKit::StorageManager::getLocalStorageOrigins):
+        (WebKit::StorageManager::getLocalStorageOriginDetails):
+        (WebKit::StorageManager::deleteLocalStorageEntriesForOrigin):
+        (WebKit::StorageManager::deleteLocalStorageOriginsModifiedSince):
+        (WebKit::StorageManager::deleteLocalStorageEntriesForOrigins):
+        * UIProcess/Storage/StorageManager.h:
+        
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::WebsiteDataStore):
+
 2017-04-05  Brent Fulgham  <bfulgham@apple.com>
 
         [WK2][iOS] Add entitlements to enable audio/video capture in WebProcess
 2017-04-05  Brent Fulgham  <bfulgham@apple.com>
 
         [WK2][iOS] Add entitlements to enable audio/video capture in WebProcess
index 5803e2c..3a2e4be 100644 (file)
@@ -281,12 +281,12 @@ void StorageManager::StorageArea::clear()
 
 void StorageManager::StorageArea::openDatabaseAndImportItemsIfNeeded() const
 {
 
 void StorageManager::StorageArea::openDatabaseAndImportItemsIfNeeded() const
 {
-    if (!m_localStorageNamespace)
+    if (!m_localStorageNamespace || !m_localStorageNamespace->storageManager()->m_localStorageDatabaseTracker)
         return;
 
     // We open the database here even if we've already imported our items to ensure that the database is open if we need to write to it.
     if (!m_localStorageDatabase)
         return;
 
     // We open the database here even if we've already imported our items to ensure that the database is open if we need to write to it.
     if (!m_localStorageDatabase)
-        m_localStorageDatabase = LocalStorageDatabase::create(m_localStorageNamespace->storageManager()->m_queue.copyRef(), m_localStorageNamespace->storageManager()->m_localStorageDatabaseTracker.copyRef(), m_securityOrigin);
+        m_localStorageDatabase = LocalStorageDatabase::create(m_localStorageNamespace->storageManager()->m_queue.copyRef(), *m_localStorageNamespace->storageManager()->m_localStorageDatabaseTracker, m_securityOrigin);
 
     if (m_didImportItemsFromDatabase)
         return;
 
     if (m_didImportItemsFromDatabase)
         return;
@@ -451,10 +451,17 @@ Ref<StorageManager> StorageManager::create(const String& localStorageDirectory)
     return adoptRef(*new StorageManager(localStorageDirectory));
 }
 
     return adoptRef(*new StorageManager(localStorageDirectory));
 }
 
+Ref<StorageManager> StorageManager::createEphemeral()
+{
+    return adoptRef(*new StorageManager({ }));
+}
+
 StorageManager::StorageManager(const String& localStorageDirectory)
     : m_queue(WorkQueue::create("com.apple.WebKit.StorageManager"))
 StorageManager::StorageManager(const String& localStorageDirectory)
     : m_queue(WorkQueue::create("com.apple.WebKit.StorageManager"))
-    , m_localStorageDatabaseTracker(LocalStorageDatabaseTracker::create(m_queue.copyRef(), localStorageDirectory))
 {
 {
+    if (!localStorageDirectory.isEmpty())
+        m_localStorageDatabaseTracker = LocalStorageDatabaseTracker::create(m_queue.copyRef(), localStorageDirectory);
+
     // Make sure the encoding is initialized before we start dispatching things to the queue.
     UTF8Encoding();
 }
     // Make sure the encoding is initialized before we start dispatching things to the queue.
     UTF8Encoding();
 }
@@ -580,8 +587,10 @@ void StorageManager::getLocalStorageOrigins(std::function<void(HashSet<WebCore::
     m_queue->dispatch([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable {
         HashSet<SecurityOriginData> origins;
 
     m_queue->dispatch([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable {
         HashSet<SecurityOriginData> origins;
 
-        for (auto& origin : m_localStorageDatabaseTracker->origins())
-            origins.add(origin);
+        if (m_localStorageDatabaseTracker) {
+            for (auto& origin : m_localStorageDatabaseTracker->origins())
+                origins.add(origin);
+        }
 
         for (auto& transientLocalStorageNamespace : m_transientLocalStorageNamespaces.values()) {
             for (auto& origin : transientLocalStorageNamespace->origins())
 
         for (auto& transientLocalStorageNamespace : m_transientLocalStorageNamespaces.values()) {
             for (auto& origin : transientLocalStorageNamespace->origins())
@@ -597,7 +606,9 @@ void StorageManager::getLocalStorageOrigins(std::function<void(HashSet<WebCore::
 void StorageManager::getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)>&& completionHandler)
 {
     m_queue->dispatch([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable {
 void StorageManager::getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)>&& completionHandler)
 {
     m_queue->dispatch([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable {
-        auto originDetails = m_localStorageDatabaseTracker->originDetails();
+        Vector<LocalStorageDatabaseTracker::OriginDetails> originDetails;
+        if (m_localStorageDatabaseTracker)
+            originDetails = m_localStorageDatabaseTracker->originDetails();
 
         RunLoop::main().dispatch([originDetails = WTFMove(originDetails), completionHandler = WTFMove(completionHandler)]() mutable {
             completionHandler(WTFMove(originDetails));
 
         RunLoop::main().dispatch([originDetails = WTFMove(originDetails), completionHandler = WTFMove(completionHandler)]() mutable {
             completionHandler(WTFMove(originDetails));
@@ -614,14 +625,17 @@ void StorageManager::deleteLocalStorageEntriesForOrigin(SecurityOriginData&& sec
         for (auto& transientLocalStorageNamespace : m_transientLocalStorageNamespaces.values())
             transientLocalStorageNamespace->clearStorageAreasMatchingOrigin(copiedOrigin);
 
         for (auto& transientLocalStorageNamespace : m_transientLocalStorageNamespaces.values())
             transientLocalStorageNamespace->clearStorageAreasMatchingOrigin(copiedOrigin);
 
-        m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(copiedOrigin);
+        if (m_localStorageDatabaseTracker)
+            m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(copiedOrigin);
     });
 }
 
 void StorageManager::deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point time, std::function<void()>&& completionHandler)
 {
     m_queue->dispatch([this, protectedThis = makeRef(*this), time, completionHandler = WTFMove(completionHandler)]() mutable {
     });
 }
 
 void StorageManager::deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point time, std::function<void()>&& completionHandler)
 {
     m_queue->dispatch([this, protectedThis = makeRef(*this), time, completionHandler = WTFMove(completionHandler)]() mutable {
-        auto deletedOrigins = m_localStorageDatabaseTracker->deleteDatabasesModifiedSince(time);
+        Vector<WebCore::SecurityOriginData> deletedOrigins;
+        if (m_localStorageDatabaseTracker)
+            deletedOrigins = m_localStorageDatabaseTracker->deleteDatabasesModifiedSince(time);
 
         for (const auto& origin : deletedOrigins) {
             for (auto& localStorageNamespace : m_localStorageNamespaces.values())
 
         for (const auto& origin : deletedOrigins) {
             for (auto& localStorageNamespace : m_localStorageNamespaces.values())
@@ -651,7 +665,8 @@ void StorageManager::deleteLocalStorageEntriesForOrigins(const Vector<WebCore::S
             for (auto& transientLocalStorageNamespace : m_transientLocalStorageNamespaces.values())
                 transientLocalStorageNamespace->clearStorageAreasMatchingOrigin(origin);
 
             for (auto& transientLocalStorageNamespace : m_transientLocalStorageNamespaces.values())
                 transientLocalStorageNamespace->clearStorageAreasMatchingOrigin(origin);
 
-            m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(origin);
+            if (m_localStorageDatabaseTracker)
+                m_localStorageDatabaseTracker->deleteDatabaseWithOrigin(origin);
         }
 
         RunLoop::main().dispatch(WTFMove(completionHandler));
         }
 
         RunLoop::main().dispatch(WTFMove(completionHandler));
index 52f093e..d573fcb 100644 (file)
@@ -47,6 +47,7 @@ class WebProcessProxy;
 class StorageManager : public IPC::Connection::WorkQueueMessageReceiver {
 public:
     static Ref<StorageManager> create(const String& localStorageDirectory);
 class StorageManager : public IPC::Connection::WorkQueueMessageReceiver {
 public:
     static Ref<StorageManager> create(const String& localStorageDirectory);
+    static Ref<StorageManager> createEphemeral();
     ~StorageManager();
 
     void createSessionStorageNamespace(uint64_t storageNamespaceID, unsigned quotaInBytes);
     ~StorageManager();
 
     void createSessionStorageNamespace(uint64_t storageNamespaceID, unsigned quotaInBytes);
@@ -99,7 +100,7 @@ private:
 
     Ref<WorkQueue> m_queue;
 
 
     Ref<WorkQueue> m_queue;
 
-    Ref<LocalStorageDatabaseTracker> m_localStorageDatabaseTracker;
+    RefPtr<LocalStorageDatabaseTracker> m_localStorageDatabaseTracker;
     HashMap<uint64_t, RefPtr<LocalStorageNamespace>> m_localStorageNamespaces;
 
     HashMap<std::pair<uint64_t, WebCore::SecurityOriginData>, RefPtr<TransientLocalStorageNamespace>> m_transientLocalStorageNamespaces;
     HashMap<uint64_t, RefPtr<LocalStorageNamespace>> m_localStorageNamespaces;
 
     HashMap<std::pair<uint64_t, WebCore::SecurityOriginData>, RefPtr<TransientLocalStorageNamespace>> m_transientLocalStorageNamespaces;
index 1fc3538..ebe1a06 100644 (file)
@@ -91,6 +91,7 @@ WebsiteDataStore::WebsiteDataStore(WebCore::SessionID sessionID)
     : m_identifier(generateIdentifier())
     , m_sessionID(sessionID)
     , m_configuration()
     : m_identifier(generateIdentifier())
     , m_sessionID(sessionID)
     , m_configuration()
+    , m_storageManager(StorageManager::createEphemeral())
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
 {
     platformInitialize();
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
 {
     platformInitialize();