| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" | 5 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ReadableStreamOperations.h" | 8 #include "bindings/core/v8/ReadableStreamOperations.h" |
| 9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 Result endRead(size_t readSize) override | 113 Result endRead(size_t readSize) override |
| 114 { | 114 { |
| 115 return m_readingContext->endRead(readSize); | 115 return m_readingContext->endRead(readSize); |
| 116 } | 116 } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 RefPtr<ReadingContext> m_readingContext; | 119 RefPtr<ReadingContext> m_readingContext; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 static PassRefPtr<ReadingContext> create(ScriptState* scriptState, v8::Local
<v8::Value> stream) | 122 static PassRefPtr<ReadingContext> create(ScriptState* scriptState, ScriptVal
ue stream) |
| 123 { | 123 { |
| 124 return adoptRef(new ReadingContext(scriptState, stream)); | 124 return adoptRef(new ReadingContext(scriptState, stream)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void attachReader(WebDataConsumerHandle::Client* client) | 127 void attachReader(WebDataConsumerHandle::Client* client) |
| 128 { | 128 { |
| 129 m_client = client; | 129 m_client = client; |
| 130 notifyLater(); | 130 notifyLater(); |
| 131 } | 131 } |
| 132 | 132 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 149 *buffer = m_pendingBuffer->data() + m_pendingOffset; | 149 *buffer = m_pendingBuffer->data() + m_pendingOffset; |
| 150 *available = m_pendingBuffer->length() - m_pendingOffset; | 150 *available = m_pendingBuffer->length() - m_pendingOffset; |
| 151 return WebDataConsumerHandle::Ok; | 151 return WebDataConsumerHandle::Ok; |
| 152 } | 152 } |
| 153 ASSERT(!m_reader.isEmpty()); | 153 ASSERT(!m_reader.isEmpty()); |
| 154 m_isInRecursion = true; | 154 m_isInRecursion = true; |
| 155 if (!m_isReading) { | 155 if (!m_isReading) { |
| 156 m_isReading = true; | 156 m_isReading = true; |
| 157 ScriptState::Scope scope(m_reader.scriptState()); | 157 ScriptState::Scope scope(m_reader.scriptState()); |
| 158 V8RecursionScope recursionScope(m_reader.isolate()); | 158 V8RecursionScope recursionScope(m_reader.isolate()); |
| 159 ReadableStreamOperations::read(m_reader.scriptState(), m_reader.v8Va
lue()).then( | 159 ReadableStreamOperations::read(m_reader.scriptState(), m_reader).the
n( |
| 160 OnFulfilled::createFunction(m_reader.scriptState(), m_weakPtrFac
tory.createWeakPtr()), | 160 OnFulfilled::createFunction(m_reader.scriptState(), m_weakPtrFac
tory.createWeakPtr()), |
| 161 OnRejected::createFunction(m_reader.scriptState(), m_weakPtrFact
ory.createWeakPtr())); | 161 OnRejected::createFunction(m_reader.scriptState(), m_weakPtrFact
ory.createWeakPtr())); |
| 162 // Note: Microtasks may run here. | 162 // Note: Microtasks may run here. |
| 163 } | 163 } |
| 164 m_isInRecursion = false; | 164 m_isInRecursion = false; |
| 165 return WebDataConsumerHandle::ShouldWait; | 165 return WebDataConsumerHandle::ShouldWait; |
| 166 } | 166 } |
| 167 | 167 |
| 168 Result endRead(size_t readSize) | 168 Result endRead(size_t readSize) |
| 169 { | 169 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 m_client->didGetReadable(); | 219 m_client->didGetReadable(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void notifyLater() | 222 void notifyLater() |
| 223 { | 223 { |
| 224 ASSERT(m_client); | 224 ASSERT(m_client); |
| 225 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this))); | 225 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this))); |
| 226 } | 226 } |
| 227 | 227 |
| 228 private: | 228 private: |
| 229 ReadingContext(ScriptState* scriptState, v8::Local<v8::Value> stream) | 229 ReadingContext(ScriptState* scriptState, ScriptValue stream) |
| 230 : m_client(nullptr) | 230 : m_client(nullptr) |
| 231 , m_weakPtrFactory(this) | 231 , m_weakPtrFactory(this) |
| 232 , m_pendingOffset(0) | 232 , m_pendingOffset(0) |
| 233 , m_isReading(false) | 233 , m_isReading(false) |
| 234 , m_isDone(false) | 234 , m_isDone(false) |
| 235 , m_hasError(false) | 235 , m_hasError(false) |
| 236 , m_isInRecursion(false) | 236 , m_isInRecursion(false) |
| 237 { | 237 { |
| 238 if (!ReadableStreamOperations::isLocked(scriptState, stream)) { | 238 if (!ReadableStreamOperations::isLocked(scriptState, stream)) { |
| 239 // Here the stream implementation must not throw an exception. | 239 // Here the stream implementation must not throw an exception. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 253 WebDataConsumerHandle::Client* m_client; | 253 WebDataConsumerHandle::Client* m_client; |
| 254 RefPtr<DOMUint8Array> m_pendingBuffer; | 254 RefPtr<DOMUint8Array> m_pendingBuffer; |
| 255 WeakPtrFactory<ReadingContext> m_weakPtrFactory; | 255 WeakPtrFactory<ReadingContext> m_weakPtrFactory; |
| 256 size_t m_pendingOffset; | 256 size_t m_pendingOffset; |
| 257 bool m_isReading; | 257 bool m_isReading; |
| 258 bool m_isDone; | 258 bool m_isDone; |
| 259 bool m_hasError; | 259 bool m_hasError; |
| 260 bool m_isInRecursion; | 260 bool m_isInRecursion; |
| 261 }; | 261 }; |
| 262 | 262 |
| 263 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState*
scriptState, v8::Local<v8::Value> stream) | 263 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState*
scriptState, ScriptValue stream) |
| 264 : m_readingContext(ReadingContext::create(scriptState, stream)) | 264 : m_readingContext(ReadingContext::create(scriptState, stream)) |
| 265 { | 265 { |
| 266 } | 266 } |
| 267 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; | 267 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; |
| 268 | 268 |
| 269 FetchDataConsumerHandle::Reader* ReadableStreamDataConsumerHandle::obtainReaderI
nternal(Client* client) | 269 FetchDataConsumerHandle::Reader* ReadableStreamDataConsumerHandle::obtainReaderI
nternal(Client* client) |
| 270 { | 270 { |
| 271 return new ReadingContext::ReaderImpl(m_readingContext, client); | 271 return new ReadingContext::ReaderImpl(m_readingContext, client); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace blink | 274 } // namespace blink |
| 275 | 275 |
| OLD | NEW |