Skip to content

Commit

Permalink
FileSystem: Migrate ExecutionContextTask to WTF::Closure
Browse files Browse the repository at this point in the history
BUG=625927

Review-Url: https://codereview.chromium.org/2645473005
Cr-Commit-Position: refs/heads/master@{#444661}
  • Loading branch information
nhiroki authored and Commit bot committed Jan 19, 2017
1 parent bd1f56e commit e65b92f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
35 changes: 31 additions & 4 deletions third_party/WebKit/Source/modules/filesystem/DOMFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "modules/filesystem/DOMFileSystem.h"

#include "core/fileapi/BlobCallback.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "modules/filesystem/DOMFilePath.h"
#include "modules/filesystem/DirectoryEntry.h"
#include "modules/filesystem/FileEntry.h"
Expand All @@ -40,6 +41,7 @@
#include "modules/filesystem/FileWriterCallback.h"
#include "modules/filesystem/MetadataCallback.h"
#include "platform/FileMetadata.h"
#include "platform/WebTaskRunner.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/Platform.h"
#include "public/platform/WebFileSystem.h"
Expand All @@ -51,6 +53,20 @@

namespace blink {

namespace {

void runCallback(ExecutionContext* executionContext,
std::unique_ptr<WTF::Closure> task) {
if (!executionContext)
return;
DCHECK(executionContext->isContextThread());
InspectorInstrumentation::AsyncTask asyncTask(executionContext, task.get(),
true /* isInstrumented */);
(*task)();
}

} // namespace

// static
DOMFileSystem* DOMFileSystem::create(ExecutionContext* context,
const String& name,
Expand Down Expand Up @@ -122,10 +138,10 @@ void DOMFileSystem::reportError(ErrorCallbackBase* errorCallback,
void DOMFileSystem::reportError(ExecutionContext* executionContext,
ErrorCallbackBase* errorCallback,
FileError::ErrorCode fileError) {
if (errorCallback)
scheduleCallback(
executionContext,
createSameThreadTask(&ErrorCallbackBase::invoke,
if (!errorCallback)
return;
scheduleCallback(executionContext,
WTF::bind(&ErrorCallbackBase::invoke,
wrapPersistent(errorCallback), fileError));
}

Expand Down Expand Up @@ -189,6 +205,17 @@ void DOMFileSystem::createFile(const FileEntry* fileEntry,
successCallback, errorCallback, m_context));
}

void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext,
std::unique_ptr<WTF::Closure> task) {
DCHECK(executionContext->isContextThread());
InspectorInstrumentation::asyncTaskScheduled(
executionContext, taskNameForInstrumentation(), task.get());
TaskRunnerHelper::get(TaskType::FileReading, executionContext)
->postTask(BLINK_FROM_HERE,
WTF::bind(&runCallback, wrapWeakPersistent(executionContext),
WTF::passed(std::move(task))));
}

DEFINE_TRACE(DOMFileSystem) {
DOMFileSystemBase::trace(visitor);
ContextLifecycleObserver::trace(visitor);
Expand Down
6 changes: 1 addition & 5 deletions third_party/WebKit/Source/modules/filesystem/DOMFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ class MODULES_EXPORT DOMFileSystem final
// Schedule a callback. This should not cross threads (should be called on the
// same context thread).
static void scheduleCallback(ExecutionContext* executionContext,
std::unique_ptr<ExecutionContextTask> task) {
DCHECK(executionContext->isContextThread());
executionContext->postTask(TaskType::FileReading, BLINK_FROM_HERE,
std::move(task), taskNameForInstrumentation());
}
std::unique_ptr<WTF::Closure> task);

DECLARE_VIRTUAL_TRACE();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ void DirectoryReader::readEntries(EntriesCallback* entriesCallback,
}

if (!m_hasMoreEntries || !m_entries.isEmpty()) {
if (entriesCallback)
if (entriesCallback) {
DOMFileSystem::scheduleCallback(
filesystem()->getExecutionContext(),
createSameThreadTask(&EntriesCallback::handleEvent,
wrapPersistent(entriesCallback),
PersistentHeapVector<Member<Entry>>(m_entries)));
WTF::bind(&EntriesCallback::handleEvent,
wrapPersistent(entriesCallback),
PersistentHeapVector<Member<Entry>>(m_entries)));
}
m_entries.clear();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ void FileSystemCallbacksBase::invokeOrScheduleCallback(CB* callback,
CBArg arg) {
DCHECK(callback);
if (callback) {
if (shouldScheduleCallback())
if (shouldScheduleCallback()) {
DOMFileSystem::scheduleCallback(
m_executionContext.get(),
createSameThreadTask(&CB::invoke, wrapPersistent(callback), arg));
else
WTF::bind(&CB::invoke, wrapPersistent(callback), arg));
} else {
callback->invoke(arg);
}
}
m_executionContext.clear();
}
Expand All @@ -103,13 +104,14 @@ void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback,
CBArg* arg) {
DCHECK(callback);
if (callback) {
if (shouldScheduleCallback())
if (shouldScheduleCallback()) {
DOMFileSystem::scheduleCallback(
m_executionContext.get(),
createSameThreadTask(&CB::handleEvent, wrapPersistent(callback),
wrapPersistent(arg)));
else
WTF::bind(&CB::handleEvent, wrapPersistent(callback),
wrapPersistent(arg)));
} else {
callback->handleEvent(arg);
}
}
m_executionContext.clear();
}
Expand All @@ -118,12 +120,13 @@ template <typename CB>
void FileSystemCallbacksBase::handleEventOrScheduleCallback(CB* callback) {
DCHECK(callback);
if (callback) {
if (shouldScheduleCallback())
if (shouldScheduleCallback()) {
DOMFileSystem::scheduleCallback(
m_executionContext.get(),
createSameThreadTask(&CB::handleEvent, wrapPersistent(callback)));
else
WTF::bind(&CB::handleEvent, wrapPersistent(callback)));
} else {
callback->handleEvent();
}
}
m_executionContext.clear();
}
Expand Down

0 comments on commit e65b92f

Please sign in to comment.