Changeset 251953 in webkit
- Timestamp:
- Nov 1, 2019 4:46:25 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251950 r251953 1 2019-11-01 Chris Dumez <cdumez@apple.com> 2 3 Port FileReader to the HTML5 event loop 4 https://bugs.webkit.org/show_bug.cgi?id=203749 5 6 Reviewed by Ryosuke Niwa. 7 8 * dom/AbstractEventLoop.h: 9 * fileapi/FileReader.cpp: 10 (WebCore::FileReader::FileReader): 11 (WebCore::FileReader::stop): 12 (WebCore::FileReader::hasPendingActivity const): 13 (WebCore::FileReader::abort): 14 (WebCore::FileReader::didStartLoading): 15 (WebCore::FileReader::didReceiveData): 16 (WebCore::FileReader::didFinishLoading): 17 (WebCore::FileReader::didFail): 18 (WebCore::FileReader::enqueueTask): 19 * fileapi/FileReader.h: 20 1 21 2019-11-01 Eric Carlson <eric.carlson@apple.com> 2 22 -
trunk/Source/WebCore/dom/AbstractEventLoop.h
r251934 r251953 35 35 enum class TaskSource : uint8_t { 36 36 DOMManipulation, 37 FileReading, 37 38 IdleTask, 38 39 Networking, -
trunk/Source/WebCore/fileapi/FileReader.cpp
r251327 r251953 32 32 #include "FileReader.h" 33 33 34 #include "AbstractEventLoop.h" 34 35 #include "EventNames.h" 35 36 #include "File.h" … … 37 38 #include "ProgressEvent.h" 38 39 #include "ScriptExecutionContext.h" 39 #include "SuspendableTaskQueue.h"40 40 #include <JavaScriptCore/ArrayBuffer.h> 41 41 #include <wtf/IsoMallocInlines.h> … … 58 58 FileReader::FileReader(ScriptExecutionContext& context) 59 59 : ActiveDOMObject(&context) 60 , m_taskQueue(SuspendableTaskQueue::create(&context))61 60 { 62 61 } … … 75 74 void FileReader::stop() 76 75 { 76 m_pendingTasks.clear(); 77 77 if (m_loader) { 78 78 m_loader->cancel(); … … 84 84 bool FileReader::hasPendingActivity() const 85 85 { 86 return m_ taskQueue->hasPendingTasks() || m_state == LOADING || ActiveDOMObject::hasPendingActivity();86 return m_state == LOADING || ActiveDOMObject::hasPendingActivity(); 87 87 } 88 88 … … 156 156 157 157 // Schedule to have the abort done later since abort() might be called from the event handler and we do not want the resource loading code to be in the stack. 158 m_ taskQueue->cancelAllTasks();159 m_taskQueue->enqueueTask([this] {158 m_pendingTasks.clear(); 159 enqueueTask([this] { 160 160 ASSERT(m_state != DONE); 161 161 … … 173 173 void FileReader::didStartLoading() 174 174 { 175 m_taskQueue->enqueueTask([this] {175 enqueueTask([this] { 176 176 fireEvent(eventNames().loadstartEvent); 177 177 }); … … 180 180 void FileReader::didReceiveData() 181 181 { 182 m_taskQueue->enqueueTask([this] {182 enqueueTask([this] { 183 183 auto now = MonotonicTime::now(); 184 184 if (std::isnan(m_lastProgressNotificationTime)) { … … 198 198 return; 199 199 200 m_taskQueue->enqueueTask([this] {200 enqueueTask([this] { 201 201 ASSERT(m_state != DONE); 202 202 m_state = DONE; … … 214 214 return; 215 215 216 m_taskQueue->enqueueTask([this, errorCode] {216 enqueueTask([this, errorCode] { 217 217 ASSERT(m_state != DONE); 218 218 m_state = DONE; … … 246 246 } 247 247 248 void FileReader::enqueueTask(Function<void()>&& task) 249 { 250 auto* context = scriptExecutionContext(); 251 if (!context) 252 return; 253 254 static uint64_t taskIdentifierSeed = 0; 255 uint64_t taskIdentifier = ++taskIdentifierSeed; 256 m_pendingTasks.add(taskIdentifier, WTFMove(task)); 257 context->eventLoop().queueTask(TaskSource::FileReading, *context, [this, protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this), taskIdentifier] { 258 auto task = m_pendingTasks.take(taskIdentifier); 259 if (task) 260 task(); 261 }); 262 } 263 248 264 } // namespace WebCore -
trunk/Source/WebCore/fileapi/FileReader.h
r251327 r251953 37 37 #include "FileReaderLoader.h" 38 38 #include "FileReaderLoaderClient.h" 39 #include <wtf/HashMap.h> 39 40 #include <wtf/UniqueRef.h> 40 41 … … 46 47 47 48 class Blob; 48 class SuspendableTaskQueue;49 49 50 50 class FileReader final : public RefCounted<FileReader>, public ActiveDOMObject, public EventTargetWithInlineData, private FileReaderLoaderClient { … … 92 92 void derefEventTarget() final { deref(); } 93 93 94 void enqueueTask(Function<void()>&&); 95 94 96 void didStartLoading() final; 95 97 void didReceiveData() final; … … 109 111 RefPtr<FileError> m_error; 110 112 MonotonicTime m_lastProgressNotificationTime { MonotonicTime::nan() }; 111 UniqueRef<SuspendableTaskQueue> m_taskQueue;113 HashMap<uint64_t, Function<void()>> m_pendingTasks; 112 114 }; 113 115
Note: See TracChangeset
for help on using the changeset viewer.