Add release logging for quota checks
https://bugs.webkit.org/show_bug.cgi?id=199697

Reviewed by Alex Christensen.

Source/WebCore:

Log whether a request to extend quota is made and the result of the request.
This logging should happen in the networking process.
No change of behavior.

* platform/Logging.h:
* storage/StorageQuotaManager.cpp:
(WebCore::StorageQuotaManager::askForMoreSpace):
(WebCore::StorageQuotaManager::processPendingRequests):

Source/WebKit:

Log requests made to the page and the result from the application.

* Platform/Logging.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::requestStorageSpace):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@247395 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index dbf92a6..6da8d7f 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,21 @@
 2019-07-12  Youenn Fablet  <youenn@apple.com>
 
+        Add release logging for quota checks
+        https://bugs.webkit.org/show_bug.cgi?id=199697
+
+        Reviewed by Alex Christensen.
+
+        Log whether a request to extend quota is made and the result of the request.
+        This logging should happen in the networking process.
+        No change of behavior.
+
+        * platform/Logging.h:
+        * storage/StorageQuotaManager.cpp:
+        (WebCore::StorageQuotaManager::askForMoreSpace):
+        (WebCore::StorageQuotaManager::processPendingRequests):
+
+2019-07-12  Youenn Fablet  <youenn@apple.com>
+
         Stopping a cloned MediaStream video track should not stop any other video track
         https://bugs.webkit.org/show_bug.cgi?id=199635
 
diff --git a/Source/WebCore/platform/Logging.h b/Source/WebCore/platform/Logging.h
index 27bfebb..1ef7256 100644
--- a/Source/WebCore/platform/Logging.h
+++ b/Source/WebCore/platform/Logging.h
@@ -96,6 +96,7 @@
     M(ServiceWorker) \
     M(SpellingAndGrammar) \
     M(SQLDatabase) \
+    M(Storage) \
     M(StorageAPI) \
     M(SVG) \
     M(TextAutosizing) \
diff --git a/Source/WebCore/storage/StorageQuotaManager.cpp b/Source/WebCore/storage/StorageQuotaManager.cpp
index 9933c0e..767ad2e 100644
--- a/Source/WebCore/storage/StorageQuotaManager.cpp
+++ b/Source/WebCore/storage/StorageQuotaManager.cpp
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "StorageQuotaManager.h"
 
+#include "Logging.h"
 #include "StorageQuotaUser.h"
 
 namespace WebCore {
@@ -155,10 +156,15 @@
 {
     ASSERT(shouldAskForMoreSpace(spaceIncrease));
     ASSERT(!m_isWaitingForSpaceIncreaseResponse);
+
+    RELEASE_LOG(Storage, "%p - StorageQuotaManager::askForMoreSpace %" PRIu64, this, spaceIncrease);
     m_isWaitingForSpaceIncreaseResponse = true;
     m_spaceIncreaseRequester(m_quota, spaceUsage(), spaceIncrease, [this, weakThis = makeWeakPtr(*this)](Optional<uint64_t> newQuota) {
         if (!weakThis)
             return;
+
+        RELEASE_LOG(Storage, "%p - StorageQuotaManager::askForMoreSpace received response %" PRIu64, this, newQuota ? *newQuota : 0);
+
         m_isWaitingForSpaceIncreaseResponse = false;
         processPendingRequests(newQuota, ShouldDequeueFirstPendingRequest::Yes);
     });
@@ -180,8 +186,11 @@
 
     if (shouldDequeueFirstPendingRequest == ShouldDequeueFirstPendingRequest::Yes) {
         auto request = m_pendingRequests.takeFirst();
-        auto decision = shouldAskForMoreSpace(request.spaceIncrease) ? Decision::Deny : Decision::Grant;
-        request.callback(decision);
+        bool shouldAllowRequest = !shouldAskForMoreSpace(request.spaceIncrease);
+
+        RELEASE_LOG(Storage, "%p - StorageQuotaManager::processPendingRequests first request decision is %d", this, shouldAllowRequest);
+
+        request.callback(shouldAllowRequest ? Decision::Grant : Decision::Deny);
     }
 
     while (!m_pendingRequests.isEmpty()) {
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 95095c8..3285e6f 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,5 +1,18 @@
 2019-07-12  Youenn Fablet  <youenn@apple.com>
 
+        Add release logging for quota checks
+        https://bugs.webkit.org/show_bug.cgi?id=199697
+
+        Reviewed by Alex Christensen.
+
+        Log requests made to the page and the result from the application.
+
+        * Platform/Logging.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::requestStorageSpace):
+
+2019-07-12  Youenn Fablet  <youenn@apple.com>
+
         Remove unneeded variable in LocalStorageNamespace::getOrCreateStorageArea
         https://bugs.webkit.org/show_bug.cgi?id=199477
 
diff --git a/Source/WebKit/Platform/Logging.h b/Source/WebKit/Platform/Logging.h
index d838e30..7aa9c72 100644
--- a/Source/WebKit/Platform/Logging.h
+++ b/Source/WebKit/Platform/Logging.h
@@ -82,6 +82,7 @@
     M(Selection) \
     M(ServiceWorker) \
     M(SessionState) \
+    M(Storage) \
     M(StorageAPI) \
     M(TextInput) \
     M(UIHitTesting) \
diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp
index 68d881c..24f1e60 100644
--- a/Source/WebKit/UIProcess/WebPageProxy.cpp
+++ b/Source/WebKit/UIProcess/WebPageProxy.cpp
@@ -7302,10 +7302,17 @@
 
 void WebPageProxy::requestStorageSpace(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, CompletionHandler<void(uint64_t)>&& completionHandler)
 {
+    RELEASE_LOG_IF_ALLOWED(Storage, "requestStorageSpace for frame %" PRIu64 ", current quota %" PRIu64 " current usage %" PRIu64 " expected usage %" PRIu64, frameID, currentQuota, currentDatabaseUsage, expectedUsage);
+
     StorageRequests::singleton().processOrAppend([this, protectedThis = makeRef(*this), pageURL = currentURL(), frameID, originIdentifier, databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, completionHandler = WTFMove(completionHandler)]() mutable {
-        this->makeStorageSpaceRequest(frameID, originIdentifier, databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, [this, protectedThis = WTFMove(protectedThis), pageURL = WTFMove(pageURL), completionHandler = WTFMove(completionHandler), currentQuota](auto quota) mutable {
-            if (quota <= currentQuota && this->currentURL() == pageURL)
+        this->makeStorageSpaceRequest(frameID, originIdentifier, databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, [this, protectedThis = WTFMove(protectedThis), frameID, pageURL = WTFMove(pageURL), completionHandler = WTFMove(completionHandler), currentQuota](auto quota) mutable {
+
+            RELEASE_LOG_IF_ALLOWED(Storage, "requestStorageSpace response for frame %" PRIu64 ", quota %" PRIu64, frameID, quota);
+
+            if (quota <= currentQuota && this->currentURL() == pageURL) {
+                RELEASE_LOG_IF_ALLOWED(Storage, "storage space increase denied");
                 m_isQuotaIncreaseDenied =  true;
+            }
             completionHandler(quota);
             StorageRequests::singleton().processNextIfAny();
         });