| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/BodyStreamBuffer.h" | 5 #include "modules/fetch/BodyStreamBuffer.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMArrayBuffer.h" | 7 #include "core/dom/DOMArrayBuffer.h" |
| 8 #include "core/dom/DOMTypedArray.h" | 8 #include "core/dom/DOMTypedArray.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "modules/fetch/DataConsumerHandleUtil.h" | 10 #include "modules/fetch/DataConsumerHandleUtil.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 : m_handle(handle) | 77 : m_handle(handle) |
| 78 , m_reader(m_handle->obtainReader(this)) | 78 , m_reader(m_handle->obtainReader(this)) |
| 79 , m_stream(new ReadableByteStream(this, new ReadableByteStream::StrictStrate
gy)) | 79 , m_stream(new ReadableByteStream(this, new ReadableByteStream::StrictStrate
gy)) |
| 80 , m_streamNeedsMore(false) | 80 , m_streamNeedsMore(false) |
| 81 { | 81 { |
| 82 m_stream->didSourceStart(); | 82 m_stream->didSourceStart(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) | 85 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) |
| 86 { | 86 { |
| 87 ASSERT(!stream()->isLocked()); | 87 ASSERT(!isStreamLocked()); |
| 88 m_stream->setIsDisturbed(); | 88 ASSERT(!isStreamDisturbed()); |
| 89 if (ReadableStream::Closed == m_stream->stateInternal() || ReadableStream::E
rrored == m_stream->stateInternal()) | 89 if (isStreamClosed() || isStreamErrored()) |
| 90 return nullptr; | 90 return nullptr; |
| 91 | 91 |
| 92 RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(poli
cy); | 92 RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(poli
cy); |
| 93 if (blobDataHandle) { | 93 if (blobDataHandle) { |
| 94 m_stream->setIsDisturbed(); |
| 94 close(); | 95 close(); |
| 95 return blobDataHandle.release(); | 96 return blobDataHandle.release(); |
| 96 } | 97 } |
| 97 return nullptr; | 98 return nullptr; |
| 98 } | 99 } |
| 99 | 100 |
| 100 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() | 101 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() |
| 101 { | 102 { |
| 102 ASSERT(!stream()->isLocked()); | 103 ASSERT(!isStreamLocked()); |
| 103 m_stream->setIsDisturbed(); | 104 ASSERT(!isStreamDisturbed()); |
| 104 if (ReadableStream::Closed == m_stream->stateInternal() || ReadableStream::E
rrored == m_stream->stateInternal()) | 105 if (isStreamClosed() || isStreamErrored()) |
| 105 return nullptr; | 106 return nullptr; |
| 106 | 107 |
| 107 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); | 108 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); |
| 108 if (formData) { | 109 if (formData) { |
| 110 m_stream->setIsDisturbed(); |
| 109 close(); | 111 close(); |
| 110 return formData.release(); | 112 return formData.release(); |
| 111 } | 113 } |
| 112 return nullptr; | 114 return nullptr; |
| 113 } | 115 } |
| 114 | 116 |
| 115 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle(ExecutionCon
text* executionContext) | 117 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle(ExecutionCon
text* executionContext) |
| 116 { | 118 { |
| 117 ASSERT(!stream()->isLocked()); | 119 ASSERT(!isStreamLocked()); |
| 120 ASSERT(!isStreamDisturbed()); |
| 118 m_reader = nullptr; | 121 m_reader = nullptr; |
| 119 m_stream->setIsDisturbed(); | 122 m_stream->setIsDisturbed(); |
| 120 TrackExceptionState exceptionState; | 123 TrackExceptionState exceptionState; |
| 121 m_stream->getBytesReader(executionContext, exceptionState); | 124 m_stream->getBytesReader(executionContext, exceptionState); |
| 122 | 125 |
| 123 if (ReadableStream::Closed == m_stream->stateInternal()) | 126 if (isStreamClosed()) |
| 124 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); | 127 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); |
| 125 if (ReadableStream::Errored == m_stream->stateInternal()) | 128 if (isStreamErrored()) |
| 126 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); | 129 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); |
| 127 | 130 |
| 128 ASSERT(m_handle); | 131 ASSERT(m_handle); |
| 129 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); | 132 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); |
| 130 close(); | 133 close(); |
| 131 return handle.release(); | 134 return handle.release(); |
| 132 } | 135 } |
| 133 | 136 |
| 134 void BodyStreamBuffer::startLoading(ExecutionContext* executionContext, FetchDat
aLoader* loader, FetchDataLoader::Client* client) | 137 void BodyStreamBuffer::startLoading(ExecutionContext* executionContext, FetchDat
aLoader* loader, FetchDataLoader::Client* client) |
| 135 { | 138 { |
| 136 ASSERT(!m_loader); | 139 ASSERT(!m_loader); |
| 137 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle(executionContext); | 140 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle(executionContext); |
| 138 m_loader = loader; | 141 m_loader = loader; |
| 139 loader->start(handle.get(), new LoaderClient(executionContext, this, client)
); | 142 loader->start(handle.get(), new LoaderClient(executionContext, this, client)
); |
| 140 } | 143 } |
| 141 | 144 |
| 142 bool BodyStreamBuffer::hasPendingActivity() const | 145 bool BodyStreamBuffer::hasPendingActivity() const |
| 143 { | 146 { |
| 144 return m_loader || (m_stream->isLocked() && m_stream->stateInternal() == Rea
dableStream::Readable); | 147 return m_loader || (isStreamLocked() && isStreamReadable()); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void BodyStreamBuffer::stop() | 150 void BodyStreamBuffer::stop() |
| 148 { | 151 { |
| 149 m_reader = nullptr; | 152 m_reader = nullptr; |
| 150 m_handle = nullptr; | 153 m_handle = nullptr; |
| 151 } | 154 } |
| 152 | 155 |
| 153 void BodyStreamBuffer::pullSource() | 156 void BodyStreamBuffer::pullSource() |
| 154 { | 157 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 183 case WebDataConsumerHandle::ResourceExhausted: | 186 case WebDataConsumerHandle::ResourceExhausted: |
| 184 case WebDataConsumerHandle::UnexpectedError: | 187 case WebDataConsumerHandle::UnexpectedError: |
| 185 error(); | 188 error(); |
| 186 return; | 189 return; |
| 187 } | 190 } |
| 188 return; | 191 return; |
| 189 } | 192 } |
| 190 processData(); | 193 processData(); |
| 191 } | 194 } |
| 192 | 195 |
| 196 bool BodyStreamBuffer::isStreamReadable() const |
| 197 { |
| 198 return m_stream->stateInternal() == ReadableStream::Readable; |
| 199 } |
| 200 |
| 201 bool BodyStreamBuffer::isStreamClosed() const |
| 202 { |
| 203 return m_stream->stateInternal() == ReadableStream::Closed; |
| 204 } |
| 205 |
| 206 bool BodyStreamBuffer::isStreamErrored() const |
| 207 { |
| 208 return m_stream->stateInternal() == ReadableStream::Errored; |
| 209 } |
| 210 |
| 211 bool BodyStreamBuffer::isStreamLocked() const |
| 212 { |
| 213 return m_stream->isLocked(); |
| 214 } |
| 215 |
| 216 bool BodyStreamBuffer::isStreamDisturbed() const |
| 217 { |
| 218 return m_stream->isDisturbed(); |
| 219 } |
| 220 |
| 193 void BodyStreamBuffer::close() | 221 void BodyStreamBuffer::close() |
| 194 { | 222 { |
| 195 m_reader = nullptr; | 223 m_reader = nullptr; |
| 196 m_stream->close(); | 224 m_stream->close(); |
| 197 m_handle.clear(); | 225 m_handle.clear(); |
| 198 } | 226 } |
| 199 | 227 |
| 200 void BodyStreamBuffer::error() | 228 void BodyStreamBuffer::error() |
| 201 { | 229 { |
| 202 m_reader = nullptr; | 230 m_reader = nullptr; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 269 |
| 242 void BodyStreamBuffer::stopLoading() | 270 void BodyStreamBuffer::stopLoading() |
| 243 { | 271 { |
| 244 if (!m_loader) | 272 if (!m_loader) |
| 245 return; | 273 return; |
| 246 m_loader->cancel(); | 274 m_loader->cancel(); |
| 247 m_loader = nullptr; | 275 m_loader = nullptr; |
| 248 } | 276 } |
| 249 | 277 |
| 250 } // namespace blink | 278 } // namespace blink |
| OLD | NEW |