Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: third_party/WebKit/Source/modules/quota/StorageManager.cpp

Issue 1855623002: Implement quota estimation API from Storage spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/quota/StorageManager.cpp
diff --git a/third_party/WebKit/Source/modules/quota/StorageManager.cpp b/third_party/WebKit/Source/modules/quota/StorageManager.cpp
index d52581b5fd75ff4c9015b2060bdcf00b4cec0dfa..783c855bfe9e6541c4ba602c4d5f22856210b2d0 100644
--- a/third_party/WebKit/Source/modules/quota/StorageManager.cpp
+++ b/third_party/WebKit/Source/modules/quota/StorageManager.cpp
@@ -5,10 +5,13 @@
#include "modules/quota/StorageManager.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/modules/v8/V8StorageEstimate.h"
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "modules/permissions/Permissions.h"
+#include "modules/quota/StorageEstimate.h"
+#include "platform/StorageQuotaCallbacks.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCallbacks.h"
#include "public/platform/modules/permissions/WebPermissionClient.h"
@@ -70,6 +73,37 @@ private:
Persistent<ScriptPromiseResolver> m_resolver;
};
+class EstimateCallbacks final : public StorageQuotaCallbacks {
+ WTF_MAKE_NONCOPYABLE(EstimateCallbacks);
+public:
+ explicit EstimateCallbacks(ScriptPromiseResolver* resolver)
+ : m_resolver(resolver) {}
+
+ ~EstimateCallbacks() override {}
+
+ void didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes) override
+ {
+ StorageEstimate estimate;
+ estimate.setUsage(usageInBytes);
+ estimate.setQuota(quotaInBytes);
+ m_resolver->resolve(estimate);
+ }
+
+ void didFail(WebStorageQuotaError error) override
+ {
+ m_resolver->reject(DOMException::create(static_cast<ExceptionCode>(error)));
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE()
+ {
+ visitor->trace(m_resolver);
+ StorageQuotaCallbacks::trace(visitor);
+ }
+
+private:
+ Member<ScriptPromiseResolver> m_resolver;
+};
+
} // namespace
ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState)
@@ -114,6 +148,28 @@ ScriptPromise StorageManager::persistentPermission(ScriptState* scriptState)
return promise;
}
+ScriptPromise StorageManager::estimate(ScriptState* scriptState)
+{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
+ SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin();
+ if (securityOrigin->isUnique()) {
+ resolver->reject(DOMException::create(NotSupportedError));
+ return promise;
+ }
+ // IDL has: [SecureContext]
+ String errorMessage;
+ if (!executionContext->isSecureContext(errorMessage)) {
+ resolver->reject(DOMException::create(SecurityError, errorMessage));
+ return promise;
+ }
+
+ KURL storagePartition = KURL(KURL(), securityOrigin->toString());
+ Platform::current()->queryStorageUsageAndQuota(storagePartition, WebStorageQuotaTypeTemporary, new EstimateCallbacks(resolver));
+ return promise;
+}
+
DEFINE_TRACE(StorageManager)
{
}
« no previous file with comments | « third_party/WebKit/Source/modules/quota/StorageManager.h ('k') | third_party/WebKit/Source/modules/quota/StorageManager.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698