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

Unified Diff: Source/modules/filesystem/LocalFileSystem.cpp

Issue 277353002: Use asynchronized api for file system request. [blink] (3/4) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Apply Kinuko's patch. Created 6 years, 7 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
« no previous file with comments | « Source/modules/filesystem/LocalFileSystem.h ('k') | Source/web/LocalFileSystemClient.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/filesystem/LocalFileSystem.cpp
diff --git a/Source/modules/filesystem/LocalFileSystem.cpp b/Source/modules/filesystem/LocalFileSystem.cpp
index 98d046d5beecfa556938bcf35821c9b5f255a86a..deb05efb48881dafef35e7dc20ba3b5979ba5589 100644
--- a/Source/modules/filesystem/LocalFileSystem.cpp
+++ b/Source/modules/filesystem/LocalFileSystem.cpp
@@ -41,8 +41,11 @@
#include "modules/filesystem/FileSystemClient.h"
#include "modules/filesystem/InspectorFileSystemAgent.h"
#include "platform/AsyncFileSystemCallbacks.h"
+#include "platform/PermissionCallbacks.h"
#include "public/platform/Platform.h"
#include "public/platform/WebFileSystem.h"
+#include "wtf/Functional.h"
+#include "wtf/RefCounted.h"
namespace WebCore {
@@ -55,6 +58,22 @@ void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks
} // namespace
+class CallbackWrapper : public RefCounted<CallbackWrapper> {
+public:
+ CallbackWrapper(PassOwnPtr<AsyncFileSystemCallbacks> c)
+ : m_callbacks(c)
+ {
+ }
+ virtual ~CallbackWrapper() { }
+ PassOwnPtr<AsyncFileSystemCallbacks> release()
+ {
+ return m_callbacks.release();
+ }
+
+private:
+ OwnPtr<AsyncFileSystemCallbacks> m_callbacks;
+};
+
PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileSystemClient> client)
{
return adoptPtrWillBeNoop(new LocalFileSystem(client));
@@ -66,34 +85,80 @@ LocalFileSystem::~LocalFileSystem()
void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSystemURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
{
- if (!client() || !client()->allowFileSystem(context)) {
- context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
- return;
- }
- blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callbacks);
+ RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks));
+ requestFileSystemAccessInternal(context,
+ bind(&LocalFileSystem::resolveURLInternal, this, fileSystemURL, wrapper),
+ bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, PassRefPtr<ExecutionContext>(context), wrapper));
}
void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemType type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
{
- if (!client() || !client()->allowFileSystem(context)) {
- context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
- return;
- }
- KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
- blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks);
+ RefPtr<ExecutionContext> contextPtr(context);
+ RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks));
+ requestFileSystemAccessInternal(context,
+ bind(&LocalFileSystem::fileSystemAllowedInternal, this, contextPtr, type, wrapper),
+ bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, wrapper));
}
void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
{
+ RefPtr<ExecutionContext> contextPtr(context);
ASSERT(context);
ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
- if (!client() || !client()->allowFileSystem(context)) {
- context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
+ RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks));
+ requestFileSystemAccessInternal(context,
+ bind(&LocalFileSystem::deleteFileSystemInternal, this, contextPtr, type, wrapper),
+ bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, wrapper));
+}
+
+void LocalFileSystem::requestFileSystemAccessInternal(ExecutionContext* context, const Closure& allowed, const Closure& denied)
+{
+ if (!client()) {
+ denied();
+ return;
+ }
+ if (!context->isDocument()) {
+ if (!client()->requestFileSystemAccessSync(context)) {
+ denied();
+ return;
+ }
+ allowed();
return;
}
+ client()->requestFileSystemAccessAsync(context, PermissionCallbacks::create(allowed, denied));
+}
+
+void LocalFileSystem::fileSystemNotAllowedInternal(
+ PassRefPtr<ExecutionContext> context,
+ PassRefPtr<CallbackWrapper> callbacks)
+{
+ context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks->release()));
+}
+
+void LocalFileSystem::fileSystemAllowedInternal(
+ PassRefPtr<ExecutionContext> context,
+ FileSystemType type,
+ PassRefPtr<CallbackWrapper> callbacks)
+{
+ KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
+ blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks->release());
+}
+
+void LocalFileSystem::resolveURLInternal(
+ const KURL& fileSystemURL,
+ PassRefPtr<CallbackWrapper> callbacks)
+{
+ blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callbacks->release());
+}
+
+void LocalFileSystem::deleteFileSystemInternal(
+ PassRefPtr<ExecutionContext> context,
+ FileSystemType type,
+ PassRefPtr<CallbackWrapper> callbacks)
+{
KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
- blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks);
+ blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks->release());
}
LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client)
« no previous file with comments | « Source/modules/filesystem/LocalFileSystem.h ('k') | Source/web/LocalFileSystemClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698