Chromium Code Reviews| Index: Source/modules/filesystem/FileSystemCallbacks.cpp |
| diff --git a/Source/modules/filesystem/FileSystemCallbacks.cpp b/Source/modules/filesystem/FileSystemCallbacks.cpp |
| index a1f6fc8f4b32354c6279769e366341ac8389ef29..2a7c3e73dcbc6e0d9dcd324f77750f7126c270c1 100644 |
| --- a/Source/modules/filesystem/FileSystemCallbacks.cpp |
| +++ b/Source/modules/filesystem/FileSystemCallbacks.cpp |
| @@ -35,6 +35,7 @@ |
| #include "core/fileapi/File.h" |
| #include "core/fileapi/FileError.h" |
| #include "core/html/VoidCallback.h" |
| +#include "core/inspector/InspectorInstrumentation.h" |
| #include "modules/filesystem/DOMFilePath.h" |
| #include "modules/filesystem/DOMFileSystem.h" |
| #include "modules/filesystem/DOMFileSystemBase.h" |
| @@ -55,6 +56,34 @@ |
| namespace WebCore { |
| +namespace { |
| + |
| +class HandleCallbackScope FINAL { |
| + WTF_MAKE_NONCOPYABLE(HandleCallbackScope); |
| +public: |
| + HandleCallbackScope(PassRefPtrWillBeRawPtr<ExecutionContext> executionContext, FileSystemCallbacksBase* callback, bool reschedule = false, bool hasMore = false) |
| + : m_executionContext(executionContext) |
| + , m_callback(callback) |
| + , m_reschedule(reschedule) |
| + { |
| + if (m_executionContext) |
| + InspectorInstrumentation::willHandleAsyncFileSystemCallback(m_executionContext.get(), m_callback, m_reschedule, hasMore); |
|
yurys
2014/07/14 14:55:54
Consider inlining these instrumentation calls. We
|
| + } |
| + |
| + ~HandleCallbackScope() |
| + { |
| + if (m_executionContext) |
| + InspectorInstrumentation::didHandleAsyncFileSystemCallback(m_executionContext.get(), m_callback, m_reschedule); |
| + } |
| + |
| +private: |
| + RefPtrWillBePersistent<ExecutionContext> m_executionContext; |
| + FileSystemCallbacksBase* m_callback; |
| + bool m_reschedule; |
| +}; |
| + |
| +} // namespace |
| + |
| FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> errorCallback, DOMFileSystemBase* fileSystem, ExecutionContext* context) |
| : m_errorCallback(errorCallback) |
| , m_fileSystem(fileSystem) |
| @@ -62,10 +91,14 @@ FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error |
| { |
| if (m_fileSystem) |
| m_fileSystem->addPendingCallbacks(); |
| + if (m_executionContext) |
| + InspectorInstrumentation::didEnqueueAsyncFileSystemCallback(m_executionContext.get(), this); |
| } |
| FileSystemCallbacksBase::~FileSystemCallbacksBase() |
| { |
| + if (m_executionContext) |
| + InspectorInstrumentation::didRemoveAsyncFileSystemCallback(m_executionContext.get(), this); |
| if (m_fileSystem) |
| m_fileSystem->removePendingCallbacks(); |
| } |
| @@ -85,10 +118,14 @@ template <typename CB, typename CBArg> |
| void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callback, CBArg* arg) |
| { |
| ASSERT(callback.get()); |
| - if (shouldScheduleCallback()) |
| + if (shouldScheduleCallback()) { |
| + HandleCallbackScope scope(m_executionContext, this, true /* reschedule */); |
| DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg); |
| - else if (callback) |
| - callback->handleEvent(arg); |
| + } else { |
| + HandleCallbackScope scope(m_executionContext, this); |
| + if (callback) |
| + callback->handleEvent(arg); |
| + } |
| m_executionContext.clear(); |
| } |
| @@ -96,10 +133,14 @@ template <typename CB, typename CBArg> |
| void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callback, PassRefPtrWillBeRawPtr<CBArg> arg) |
| { |
| ASSERT(callback.get()); |
| - if (shouldScheduleCallback()) |
| + if (shouldScheduleCallback()) { |
| + HandleCallbackScope scope(m_executionContext, this, true /* reschedule */); |
| DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg); |
| - else if (callback) |
| - callback->handleEvent(arg.get()); |
| + } else { |
| + HandleCallbackScope scope(m_executionContext, this); |
| + if (callback) |
| + callback->handleEvent(arg.get()); |
| + } |
| m_executionContext.clear(); |
| } |
| @@ -107,10 +148,14 @@ template <typename CB> |
| void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callback) |
| { |
| ASSERT(callback.get()); |
| - if (shouldScheduleCallback()) |
| + if (shouldScheduleCallback()) { |
| + HandleCallbackScope scope(m_executionContext, this, true /* reschedule */); |
| DOMFileSystem::scheduleCallback(m_executionContext.get(), callback); |
| - else if (callback) |
| - callback->handleEvent(); |
| + } else { |
| + HandleCallbackScope scope(m_executionContext, this); |
| + if (callback) |
| + callback->handleEvent(); |
| + } |
| m_executionContext.clear(); |
| } |
| @@ -169,6 +214,7 @@ void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) |
| EntryHeapVector entries; |
| entries.swap(m_entries); |
| // FIXME: delay the callback iff shouldScheduleCallback() is true. |
| + HandleCallbackScope scope(m_executionContext, this, false /* reschedule */, hasMore); |
| if (m_successCallback) |
| m_successCallback->handleEvent(entries); |
| } |