| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 Result endRead(size_t readSize) override | 126 Result endRead(size_t readSize) override |
| 127 { | 127 { |
| 128 return m_readingContext->endRead(readSize); | 128 return m_readingContext->endRead(readSize); |
| 129 } | 129 } |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 RefPtr<ReadingContext> m_readingContext; | 132 RefPtr<ReadingContext> m_readingContext; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 static PassRefPtr<ReadingContext> create(ScriptState* scriptState, v8::Local
<v8::Value> stream) | 135 static PassRefPtr<ReadingContext> create(ScriptState* scriptState, ScriptVal
ue stream) |
| 136 { | 136 { |
| 137 return adoptRef(new ReadingContext(scriptState, stream)); | 137 return adoptRef(new ReadingContext(scriptState, stream)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void attachReader(WebDataConsumerHandle::Client* client) | 140 void attachReader(WebDataConsumerHandle::Client* client) |
| 141 { | 141 { |
| 142 m_client = client; | 142 m_client = client; |
| 143 notifyLater(); | 143 notifyLater(); |
| 144 } | 144 } |
| 145 | 145 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 162 *buffer = m_pendingBuffer->data() + m_pendingOffset; | 162 *buffer = m_pendingBuffer->data() + m_pendingOffset; |
| 163 *available = m_pendingBuffer->length() - m_pendingOffset; | 163 *available = m_pendingBuffer->length() - m_pendingOffset; |
| 164 return WebDataConsumerHandle::Ok; | 164 return WebDataConsumerHandle::Ok; |
| 165 } | 165 } |
| 166 ASSERT(!m_reader.isEmpty()); | 166 ASSERT(!m_reader.isEmpty()); |
| 167 m_isInRecursion = true; | 167 m_isInRecursion = true; |
| 168 if (!m_isReading) { | 168 if (!m_isReading) { |
| 169 m_isReading = true; | 169 m_isReading = true; |
| 170 ScriptState::Scope scope(m_reader.scriptState()); | 170 ScriptState::Scope scope(m_reader.scriptState()); |
| 171 V8RecursionScope recursionScope(m_reader.isolate()); | 171 V8RecursionScope recursionScope(m_reader.isolate()); |
| 172 ReadableStreamOperations::read(m_reader.scriptState(), m_reader.v8Va
lue()).then( | 172 ReadableStreamOperations::read(m_reader.scriptState(), m_reader).the
n(OnFulfilled::createFunction(m_reader.scriptState(), m_weakPtrFactory.createWea
kPtr()), OnRejected::createFunction(m_reader.scriptState(), m_weakPtrFactory.cre
ateWeakPtr())); |
| 173 OnFulfilled::createFunction(m_reader.scriptState(), m_weakPtrFac
tory.createWeakPtr()), | |
| 174 OnRejected::createFunction(m_reader.scriptState(), m_weakPtrFact
ory.createWeakPtr())); | |
| 175 // Note: Microtasks may run here. | 173 // Note: Microtasks may run here. |
| 176 } | 174 } |
| 177 m_isInRecursion = false; | 175 m_isInRecursion = false; |
| 178 return WebDataConsumerHandle::ShouldWait; | 176 return WebDataConsumerHandle::ShouldWait; |
| 179 } | 177 } |
| 180 | 178 |
| 181 Result endRead(size_t readSize) | 179 Result endRead(size_t readSize) |
| 182 { | 180 { |
| 183 ASSERT(m_pendingBuffer); | 181 ASSERT(m_pendingBuffer); |
| 184 ASSERT(m_pendingOffset + readSize <= m_pendingBuffer->length()); | 182 ASSERT(m_pendingOffset + readSize <= m_pendingBuffer->length()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 m_client->didGetReadable(); | 230 m_client->didGetReadable(); |
| 233 } | 231 } |
| 234 | 232 |
| 235 void notifyLater() | 233 void notifyLater() |
| 236 { | 234 { |
| 237 ASSERT(m_client); | 235 ASSERT(m_client); |
| 238 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this))); | 236 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this))); |
| 239 } | 237 } |
| 240 | 238 |
| 241 private: | 239 private: |
| 242 ReadingContext(ScriptState* scriptState, v8::Local<v8::Value> stream) | 240 ReadingContext(ScriptState* scriptState, ScriptValue stream) |
| 243 : m_client(nullptr) | 241 : m_client(nullptr) |
| 244 , m_weakPtrFactory(this) | 242 , m_weakPtrFactory(this) |
| 245 , m_pendingOffset(0) | 243 , m_pendingOffset(0) |
| 246 , m_isReading(false) | 244 , m_isReading(false) |
| 247 , m_isDone(false) | 245 , m_isDone(false) |
| 248 , m_hasError(false) | 246 , m_hasError(false) |
| 249 , m_isInRecursion(false) | 247 , m_isInRecursion(false) |
| 250 { | 248 { |
| 251 if (!ReadableStreamOperations::isLocked(scriptState, stream)) { | 249 if (!ReadableStreamOperations::isLocked(scriptState, stream)) { |
| 252 // Here the stream implementation must not throw an exception. | 250 // Here the stream implementation must not throw an exception. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 266 WebDataConsumerHandle::Client* m_client; | 264 WebDataConsumerHandle::Client* m_client; |
| 267 RefPtr<DOMUint8Array> m_pendingBuffer; | 265 RefPtr<DOMUint8Array> m_pendingBuffer; |
| 268 WeakPtrFactory<ReadingContext> m_weakPtrFactory; | 266 WeakPtrFactory<ReadingContext> m_weakPtrFactory; |
| 269 size_t m_pendingOffset; | 267 size_t m_pendingOffset; |
| 270 bool m_isReading; | 268 bool m_isReading; |
| 271 bool m_isDone; | 269 bool m_isDone; |
| 272 bool m_hasError; | 270 bool m_hasError; |
| 273 bool m_isInRecursion; | 271 bool m_isInRecursion; |
| 274 }; | 272 }; |
| 275 | 273 |
| 276 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState*
scriptState, v8::Local<v8::Value> stream) | 274 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState*
scriptState, ScriptValue stream) |
| 277 : m_readingContext(ReadingContext::create(scriptState, stream)) | 275 : m_readingContext(ReadingContext::create(scriptState, stream)) |
| 278 { | 276 { |
| 279 } | 277 } |
| 280 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; | 278 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; |
| 281 | 279 |
| 282 FetchDataConsumerHandle::Reader* ReadableStreamDataConsumerHandle::obtainReaderI
nternal(Client* client) | 280 FetchDataConsumerHandle::Reader* ReadableStreamDataConsumerHandle::obtainReaderI
nternal(Client* client) |
| 283 { | 281 { |
| 284 return new ReadingContext::ReaderImpl(m_readingContext, client); | 282 return new ReadingContext::ReaderImpl(m_readingContext, client); |
| 285 } | 283 } |
| 286 | 284 |
| 287 } // namespace blink | 285 } // namespace blink |
| 288 | 286 |
| OLD | NEW |