| 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 m_stream->setIsDisturbed(); |
| 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 close(); | 94 close(); |
| 95 return blobDataHandle.release(); | 95 return blobDataHandle.release(); |
| 96 } | 96 } |
| 97 return nullptr; | 97 return nullptr; |
| 98 } | 98 } |
| 99 | 99 |
| 100 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() | 100 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() |
| 101 { | 101 { |
| 102 ASSERT(!stream()->isLocked()); | 102 ASSERT(!isStreamLocked()); |
| 103 m_stream->setIsDisturbed(); | 103 m_stream->setIsDisturbed(); |
| 104 if (ReadableStream::Closed == m_stream->stateInternal() || ReadableStream::E
rrored == m_stream->stateInternal()) | 104 if (isStreamClosed() || isStreamErrored()) |
| 105 return nullptr; | 105 return nullptr; |
| 106 | 106 |
| 107 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); | 107 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); |
| 108 if (formData) { | 108 if (formData) { |
| 109 close(); | 109 close(); |
| 110 return formData.release(); | 110 return formData.release(); |
| 111 } | 111 } |
| 112 return nullptr; | 112 return nullptr; |
| 113 } | 113 } |
| 114 | 114 |
| 115 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle(ExecutionCon
text* executionContext) | 115 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle(ExecutionCon
text* executionContext) |
| 116 { | 116 { |
| 117 ASSERT(!stream()->isLocked()); | 117 ASSERT(!isStreamLocked()); |
| 118 m_reader = nullptr; | 118 m_reader = nullptr; |
| 119 m_stream->setIsDisturbed(); | 119 m_stream->setIsDisturbed(); |
| 120 TrackExceptionState exceptionState; | 120 TrackExceptionState exceptionState; |
| 121 m_stream->getBytesReader(executionContext, exceptionState); | 121 m_stream->getBytesReader(executionContext, exceptionState); |
| 122 | 122 |
| 123 if (ReadableStream::Closed == m_stream->stateInternal()) | 123 if (isStreamClosed()) |
| 124 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); | 124 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); |
| 125 if (ReadableStream::Errored == m_stream->stateInternal()) | 125 if (isStreamErrored()) |
| 126 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); | 126 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); |
| 127 | 127 |
| 128 ASSERT(m_handle); | 128 ASSERT(m_handle); |
| 129 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); | 129 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); |
| 130 close(); | 130 close(); |
| 131 return handle.release(); | 131 return handle.release(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void BodyStreamBuffer::startLoading(ExecutionContext* executionContext, FetchDat
aLoader* loader, FetchDataLoader::Client* client) | 134 void BodyStreamBuffer::startLoading(ExecutionContext* executionContext, FetchDat
aLoader* loader, FetchDataLoader::Client* client) |
| 135 { | 135 { |
| 136 ASSERT(!m_loader); | 136 ASSERT(!m_loader); |
| 137 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle(executionContext); | 137 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle(executionContext); |
| 138 m_loader = loader; | 138 m_loader = loader; |
| 139 loader->start(handle.get(), new LoaderClient(executionContext, this, client)
); | 139 loader->start(handle.get(), new LoaderClient(executionContext, this, client)
); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool BodyStreamBuffer::hasPendingActivity() const | 142 bool BodyStreamBuffer::hasPendingActivity() const |
| 143 { | 143 { |
| 144 return m_loader || (m_stream->isLocked() && m_stream->stateInternal() == Rea
dableStream::Readable); | 144 return m_loader || (isStreamLocked() && isStreamReadable()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void BodyStreamBuffer::stop() | 147 void BodyStreamBuffer::stop() |
| 148 { | 148 { |
| 149 m_reader = nullptr; | 149 m_reader = nullptr; |
| 150 m_handle = nullptr; | 150 m_handle = nullptr; |
| 151 } | 151 } |
| 152 | 152 |
| 153 void BodyStreamBuffer::pullSource() | 153 void BodyStreamBuffer::pullSource() |
| 154 { | 154 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 183 case WebDataConsumerHandle::ResourceExhausted: | 183 case WebDataConsumerHandle::ResourceExhausted: |
| 184 case WebDataConsumerHandle::UnexpectedError: | 184 case WebDataConsumerHandle::UnexpectedError: |
| 185 error(); | 185 error(); |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 processData(); | 190 processData(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool BodyStreamBuffer::isStreamReadable() const |
| 194 { |
| 195 return m_stream->stateInternal() == ReadableStream::Readable; |
| 196 } |
| 197 |
| 198 bool BodyStreamBuffer::isStreamClosed() const |
| 199 { |
| 200 return m_stream->stateInternal() == ReadableStream::Closed; |
| 201 } |
| 202 |
| 203 bool BodyStreamBuffer::isStreamErrored() const |
| 204 { |
| 205 return m_stream->stateInternal() == ReadableStream::Errored; |
| 206 } |
| 207 |
| 208 bool BodyStreamBuffer::isStreamLocked() const |
| 209 { |
| 210 return m_stream->isLocked(); |
| 211 } |
| 212 |
| 213 bool BodyStreamBuffer::isStreamDisturbed() const |
| 214 { |
| 215 return m_stream->isDisturbed(); |
| 216 } |
| 217 |
| 193 void BodyStreamBuffer::close() | 218 void BodyStreamBuffer::close() |
| 194 { | 219 { |
| 195 m_reader = nullptr; | 220 m_reader = nullptr; |
| 196 m_stream->close(); | 221 m_stream->close(); |
| 197 m_handle.clear(); | 222 m_handle.clear(); |
| 198 } | 223 } |
| 199 | 224 |
| 200 void BodyStreamBuffer::error() | 225 void BodyStreamBuffer::error() |
| 201 { | 226 { |
| 202 m_reader = nullptr; | 227 m_reader = nullptr; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 266 |
| 242 void BodyStreamBuffer::stopLoading() | 267 void BodyStreamBuffer::stopLoading() |
| 243 { | 268 { |
| 244 if (!m_loader) | 269 if (!m_loader) |
| 245 return; | 270 return; |
| 246 m_loader->cancel(); | 271 m_loader->cancel(); |
| 247 m_loader = nullptr; | 272 m_loader = nullptr; |
| 248 } | 273 } |
| 249 | 274 |
| 250 } // namespace blink | 275 } // namespace blink |
| OLD | NEW |