| 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(OnFulfilled::createFunction(m_reader.scriptState(), m_weakPtrFactory.createWea
kPtr()), OnRejected::createFunction(m_reader.scriptState(), m_weakPtrFactory.cre
ateWeakPtr())); |
| 160 OnFulfilled::createFunction(m_reader.scriptState(), m_weakPtrFac
tory.createWeakPtr()), | |
| 161 OnRejected::createFunction(m_reader.scriptState(), m_weakPtrFact
ory.createWeakPtr())); | |
| 162 // Note: Microtasks may run here. | 160 // Note: Microtasks may run here. |
| 163 } | 161 } |
| 164 m_isInRecursion = false; | 162 m_isInRecursion = false; |
| 165 return WebDataConsumerHandle::ShouldWait; | 163 return WebDataConsumerHandle::ShouldWait; |
| 166 } | 164 } |
| 167 | 165 |
| 168 Result endRead(size_t readSize) | 166 Result endRead(size_t readSize) |
| 169 { | 167 { |
| 170 ASSERT(m_pendingBuffer); | 168 ASSERT(m_pendingBuffer); |
| 171 ASSERT(m_pendingOffset + readSize <= m_pendingBuffer->length()); | 169 ASSERT(m_pendingOffset + readSize <= m_pendingBuffer->length()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 m_client->didGetReadable(); | 217 m_client->didGetReadable(); |
| 220 } | 218 } |
| 221 | 219 |
| 222 void notifyLater() | 220 void notifyLater() |
| 223 { | 221 { |
| 224 ASSERT(m_client); | 222 ASSERT(m_client); |
| 225 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this))); | 223 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this))); |
| 226 } | 224 } |
| 227 | 225 |
| 228 private: | 226 private: |
| 229 ReadingContext(ScriptState* scriptState, v8::Local<v8::Value> stream) | 227 ReadingContext(ScriptState* scriptState, ScriptValue stream) |
| 230 : m_client(nullptr) | 228 : m_client(nullptr) |
| 231 , m_weakPtrFactory(this) | 229 , m_weakPtrFactory(this) |
| 232 , m_pendingOffset(0) | 230 , m_pendingOffset(0) |
| 233 , m_isReading(false) | 231 , m_isReading(false) |
| 234 , m_isDone(false) | 232 , m_isDone(false) |
| 235 , m_hasError(false) | 233 , m_hasError(false) |
| 236 , m_isInRecursion(false) | 234 , m_isInRecursion(false) |
| 237 { | 235 { |
| 238 if (!ReadableStreamOperations::isLocked(scriptState, stream)) { | 236 if (!ReadableStreamOperations::isLocked(scriptState, stream)) { |
| 239 // Here the stream implementation must not throw an exception. | 237 // Here the stream implementation must not throw an exception. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 253 WebDataConsumerHandle::Client* m_client; | 251 WebDataConsumerHandle::Client* m_client; |
| 254 RefPtr<DOMUint8Array> m_pendingBuffer; | 252 RefPtr<DOMUint8Array> m_pendingBuffer; |
| 255 WeakPtrFactory<ReadingContext> m_weakPtrFactory; | 253 WeakPtrFactory<ReadingContext> m_weakPtrFactory; |
| 256 size_t m_pendingOffset; | 254 size_t m_pendingOffset; |
| 257 bool m_isReading; | 255 bool m_isReading; |
| 258 bool m_isDone; | 256 bool m_isDone; |
| 259 bool m_hasError; | 257 bool m_hasError; |
| 260 bool m_isInRecursion; | 258 bool m_isInRecursion; |
| 261 }; | 259 }; |
| 262 | 260 |
| 263 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState*
scriptState, v8::Local<v8::Value> stream) | 261 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState*
scriptState, ScriptValue stream) |
| 264 : m_readingContext(ReadingContext::create(scriptState, stream)) | 262 : m_readingContext(ReadingContext::create(scriptState, stream)) |
| 265 { | 263 { |
| 266 } | 264 } |
| 267 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; | 265 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; |
| 268 | 266 |
| 269 FetchDataConsumerHandle::Reader* ReadableStreamDataConsumerHandle::obtainReaderI
nternal(Client* client) | 267 FetchDataConsumerHandle::Reader* ReadableStreamDataConsumerHandle::obtainReaderI
nternal(Client* client) |
| 270 { | 268 { |
| 271 return new ReadingContext::ReaderImpl(m_readingContext, client); | 269 return new ReadingContext::ReaderImpl(m_readingContext, client); |
| 272 } | 270 } |
| 273 | 271 |
| 274 } // namespace blink | 272 } // namespace blink |
| 275 | 273 |
| OLD | NEW |