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

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

Issue 2645613004: Provide a per-supplement implementation of LocalFileSystem.
Patch Set: Created 3 years, 11 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 | « third_party/WebKit/Source/modules/filesystem/LocalFileSystem.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/filesystem/LocalFileSystem.cpp
diff --git a/third_party/WebKit/Source/modules/filesystem/LocalFileSystem.cpp b/third_party/WebKit/Source/modules/filesystem/LocalFileSystem.cpp
index 094898ea4b7f41b93682400142578ba2540849c6..69865d341e7b36c69e1630ce6d5649046300991c 100644
--- a/third_party/WebKit/Source/modules/filesystem/LocalFileSystem.cpp
+++ b/third_party/WebKit/Source/modules/filesystem/LocalFileSystem.cpp
@@ -36,13 +36,15 @@
#include "core/dom/TaskRunnerHelper.h"
#include "core/fileapi/FileError.h"
#include "core/frame/LocalFrame.h"
+#include "core/workers/WorkerClients.h"
#include "core/workers/WorkerGlobalScope.h"
#include "modules/filesystem/FileSystemClient.h"
#include "platform/AsyncFileSystemCallbacks.h"
#include "platform/ContentSettingCallbacks.h"
+#include "platform/Supplementable.h"
+#include "platform/heap/Handle.h"
#include "public/platform/Platform.h"
#include "public/platform/WebFileSystem.h"
-#include "wtf/Functional.h"
#include <memory>
namespace blink {
@@ -59,9 +61,10 @@ void reportFailure(std::unique_ptr<AsyncFileSystemCallbacks> callbacks,
class CallbackWrapper final
: public GarbageCollectedFinalized<CallbackWrapper> {
public:
- CallbackWrapper(std::unique_ptr<AsyncFileSystemCallbacks> c)
+ explicit CallbackWrapper(std::unique_ptr<AsyncFileSystemCallbacks> c)
: m_callbacks(std::move(c)) {}
- virtual ~CallbackWrapper() {}
+ ~CallbackWrapper() {}
+
std::unique_ptr<AsyncFileSystemCallbacks> release() {
return std::move(m_callbacks);
}
@@ -72,37 +75,59 @@ class CallbackWrapper final
std::unique_ptr<AsyncFileSystemCallbacks> m_callbacks;
};
-LocalFileSystem::~LocalFileSystem() {}
+template <typename T>
+class LocalFileSystemImpl final
+ : public GarbageCollectedFinalized<LocalFileSystemImpl<T>>,
+ public LocalFileSystem,
+ public Supplement<T> {
+ WTF_MAKE_NONCOPYABLE(LocalFileSystemImpl);
+ USING_GARBAGE_COLLECTED_MIXIN(LocalFileSystemImpl);
-void LocalFileSystem::resolveURL(
- ExecutionContext* context,
- const KURL& fileSystemURL,
- std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
- CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks));
- requestFileSystemAccessInternal(
- context,
- WTF::bind(&LocalFileSystem::resolveURLInternal,
- wrapCrossThreadPersistent(this), wrapPersistent(context),
- fileSystemURL, wrapPersistent(wrapper)),
- WTF::bind(&LocalFileSystem::fileSystemNotAllowedInternal,
- wrapCrossThreadPersistent(this), wrapPersistent(context),
- wrapPersistent(wrapper)));
-}
+ public:
+ LocalFileSystemImpl(T& supplementable,
+ std::unique_ptr<FileSystemClient> client)
+ : LocalFileSystem(std::move(client)), Supplement<T>(supplementable) {}
+ ~LocalFileSystemImpl() = default;
+
+ void resolveURL(
+ ExecutionContext* context,
+ const KURL& fileSystemURL,
+ std::unique_ptr<AsyncFileSystemCallbacks> callbacks) override {
+ CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks));
+ requestFileSystemAccessInternal(
+ context,
+ WTF::bind(&LocalFileSystemImpl::resolveURLInternal,
+ wrapCrossThreadPersistent(this), wrapPersistent(context),
+ fileSystemURL, wrapPersistent(wrapper)),
+ WTF::bind(&LocalFileSystemImpl::fileSystemNotAllowedInternal,
+ wrapCrossThreadPersistent(this), wrapPersistent(context),
+ wrapPersistent(wrapper)));
+ }
-void LocalFileSystem::requestFileSystem(
- ExecutionContext* context,
- FileSystemType type,
- long long size,
- std::unique_ptr<AsyncFileSystemCallbacks> callbacks) {
- CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks));
- requestFileSystemAccessInternal(
- context,
- WTF::bind(&LocalFileSystem::fileSystemAllowedInternal,
- wrapCrossThreadPersistent(this), wrapPersistent(context), type,
- wrapPersistent(wrapper)),
- WTF::bind(&LocalFileSystem::fileSystemNotAllowedInternal,
- wrapCrossThreadPersistent(this), wrapPersistent(context),
- wrapPersistent(wrapper)));
+ void requestFileSystem(
+ ExecutionContext* context,
+ FileSystemType type,
+ long long size,
+ std::unique_ptr<AsyncFileSystemCallbacks> callbacks) override {
+ CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks));
+ requestFileSystemAccessInternal(
+ context,
+ WTF::bind(&LocalFileSystemImpl::fileSystemAllowedInternal,
+ wrapCrossThreadPersistent(this), wrapPersistent(context),
+ type, wrapPersistent(wrapper)),
+ WTF::bind(&LocalFileSystemImpl::fileSystemNotAllowedInternal,
+ wrapCrossThreadPersistent(this), wrapPersistent(context),
+ wrapPersistent(wrapper)));
+ }
+};
+
+LocalFileSystem::LocalFileSystem(std::unique_ptr<FileSystemClient> client)
+ : m_client(std::move(client)) {}
+
+LocalFileSystem::~LocalFileSystem() {}
+
+const char* LocalFileSystem::supplementName() {
+ return "LocalFileSystem";
}
WebFileSystem* LocalFileSystem::getFileSystem() const {
@@ -176,35 +201,18 @@ void LocalFileSystem::resolveURLInternal(ExecutionContext* context,
fileSystem->resolveURL(fileSystemURL, callbacks->release());
}
-LocalFileSystem::LocalFileSystem(LocalFrame& frame,
- std::unique_ptr<FileSystemClient> client)
- : Supplement<LocalFrame>(frame), m_client(std::move(client)) {}
-
-LocalFileSystem::LocalFileSystem(WorkerClients& workerClients,
- std::unique_ptr<FileSystemClient> client)
- : Supplement<WorkerClients>(workerClients), m_client(std::move(client)) {}
-
-DEFINE_TRACE(LocalFileSystem) {
- Supplement<LocalFrame>::trace(visitor);
- Supplement<WorkerClients>::trace(visitor);
-}
-
-const char* LocalFileSystem::supplementName() {
- return "LocalFileSystem";
-}
-
LocalFileSystem* LocalFileSystem::from(ExecutionContext& context) {
if (context.isDocument()) {
- LocalFileSystem* fileSystem =
- static_cast<LocalFileSystem*>(Supplement<LocalFrame>::from(
- toDocument(context).frame(), supplementName()));
+ auto fileSystem = static_cast<LocalFileSystemImpl<LocalFrame>*>(
+ Supplement<LocalFrame>::from(toDocument(context).frame(),
+ supplementName()));
DCHECK(fileSystem);
return fileSystem;
}
WorkerClients* clients = toWorkerGlobalScope(context).clients();
ASSERT(clients);
- LocalFileSystem* fileSystem = static_cast<LocalFileSystem*>(
+ auto fileSystem = static_cast<LocalFileSystemImpl<WorkerClients>*>(
Supplement<WorkerClients>::from(clients, supplementName()));
DCHECK(fileSystem);
return fileSystem;
@@ -212,15 +220,16 @@ LocalFileSystem* LocalFileSystem::from(ExecutionContext& context) {
void provideLocalFileSystemTo(LocalFrame& frame,
std::unique_ptr<FileSystemClient> client) {
- frame.provideSupplement(LocalFileSystem::supplementName(),
- new LocalFileSystem(frame, std::move(client)));
+ Supplement<LocalFrame>::provideTo(
+ frame, LocalFileSystem::supplementName(),
+ new LocalFileSystemImpl<LocalFrame>(frame, std::move(client)));
}
-void provideLocalFileSystemToWorker(WorkerClients* workerClients,
+void provideLocalFileSystemToWorker(WorkerClients* clients,
std::unique_ptr<FileSystemClient> client) {
Supplement<WorkerClients>::provideTo(
- *workerClients, LocalFileSystem::supplementName(),
- new LocalFileSystem(*workerClients, std::move(client)));
+ *clients, LocalFileSystem::supplementName(),
+ new LocalFileSystemImpl<WorkerClients>(*clients, std::move(client)));
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/filesystem/LocalFileSystem.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698